Skip to content

octoprint.filemanager.util#

AbstractFileWrapper(filename) #

Wrapper for file representations to save to storages.

Parameters:

  • filename (str) –

    The file's name

save(path, permissions = None) #

Saves the file's content to the given absolute path.

Parameters:

  • path (str) –

    The absolute path to where to save the file

  • permissions (int) –

    The permissions to set on the file

stream() #

Returns a Python stream object (subclass of io.IOBase) representing the file's contents.

Returns:

  • io.IOBase: The file's contents as a stream.

DiskFileWrapper(filename, path, move = True) #

Bases: AbstractFileWrapper

An implementation of :class:.AbstractFileWrapper that wraps an actual file on disk. The save implementations will either copy the file to the new path (preserving file attributes) or -- if move is True (the default) -- move the file.

Parameters:

  • filename (str) –

    The file's name

  • path (str) –

    The file's absolute path

  • move (boolean) –

    Whether to move the file upon saving (True, default) or copying.

LineProcessorStream(input_stream) #

Bases: io.RawIOBase

While reading from this stream the provided input_stream is read line by line, calling the (overridable) method :meth:.process_line for each read line.

Sub classes can thus modify the contents of the input_stream in line, while it is being read. Keep in mind that process_line will receive the line as a byte stream - if underlying code needs to operate on unicode you'll need to do the decoding yourself.

Parameters:

  • input_stream (io.RawIOBase) –

    The stream to process on the fly.

process_line(line) #

Called from the read Method of this stream with each line read from self.input_stream.

By returning None the line will not be returned from the read stream, effectively being stripped from the wrapper input_stream.

Parameters:

  • line (bytes) –

    The line as read from self.input_stream in byte representation

Returns:

  • bytes or None: The processed version of the line (might also be multiple lines), or None if the line is to be stripped from the processed stream.

MultiStream(*streams) #

Bases: io.RawIOBase

A stream implementation which when read reads from multiple streams, one after the other, basically concatenating their contents in the order they are provided to the constructor.

Parameters:

  • *streams

    One or more 🇵🇾class:io.IOBase streams to concatenate.

StreamWrapper(filename, *streams) #

Bases: AbstractFileWrapper

A wrapper allowing processing of one or more consecutive streams.

Parameters:

  • *streams

    One or more 🇵🇾class:io.IOBase streams to process one after another to save to storage.

save(path, permissions = None) #

Will dump the contents of all streams provided during construction into the target file, in the order they were provided.

stream() #

If more than one stream was provided to the constructor, will return a :class:.MultiStream wrapping all provided streams in the order they were provided, else the first and only stream is returned directly.