octoprint.filemanager
- class octoprint.filemanager.ContentTypeDetector(extensions, detector)
- detector
Alias for field number 1
- extensions
Alias for field number 0
- class octoprint.filemanager.ContentTypeMapping(extensions, content_type)
- content_type
Alias for field number 1
- extensions
Alias for field number 0
- exception octoprint.filemanager.NoSuchStorage
octoprint.filemanager.analysis
- class octoprint.filemanager.analysis.AbstractAnalysisQueue(finished_callback)
The
AbstractAnalysisQueueis the parent class of all specific analysis queues such as theGcodeAnalysisQueue. It offers methods to enqueue new entries to analyze and pausing and resuming analysis processing.- Parameters:
finished_callback (callable) – Callback that will be called upon finishing analysis of an entry in the queue. The callback will be called with the analyzed entry as the first argument and the analysis result as returned from the queue implementation as the second parameter.
- _do_analysis(high_priority=False)
Performs the actual analysis of the current entry which can be accessed via
self._current. Needs to be overridden by sub classes.
- _do_abort(reenqueue=True)
Aborts analysis of the current entry. Needs to be overridden by sub classes.
- enqueue(entry, high_priority=False)
Enqueues an
entryfor analysis by the queue.If
high_priorityis True (defaults to False), the entry will be prioritized and hence processed before other entries in the queue with normal priority.- Parameters:
entry (QueueEntry) – The
QueueEntryto analyze.high_priority (boolean) – Whether to process the provided entry with high priority (True) or not (False, default)
- pause()
Pauses processing of the queue, e.g. when a print is active.
- resume()
Resumes processing of the queue, e.g. when a print has finished.
- exception octoprint.filemanager.analysis.AnalysisAborted(reenqueue=True, *args, **kwargs)
- class octoprint.filemanager.analysis.AnalysisQueue(queue_factories)
OctoPrint’s
AnalysisQueuecan manage variousAbstractAnalysisQueueimplementations, mapped by their machine code type.By invoking
register_finish_callback()it is possible to register oneself as a callback to be invoked each time the analysis of a queue entry finishes. The call parameters will be the finished queue entry as the first and the analysis result as the second parameter. It is also possible to remove the registration again by invokingunregister_finish_callback().enqueue()allows enqueuingQueueEntryinstances to analyze. If theQueueEntry.typeis unknown (no specific child class ofAbstractAnalysisQueueis registered for it), nothing will happen. Otherwise the entry will be enqueued with the type specific analysis queue.
- class octoprint.filemanager.analysis.GcodeAnalysisQueue(finished_callback)
A queue to analyze GCODE files. Analysis results are
dictinstances structured as follows:Key
Description
estimatedPrintTimeEstimated time the file take to print, in seconds
filamentSubstructure describing estimated filament usage. Keys are
tool0for the first extruder,tool1for the second and so on. For each tool extruded length and volume (based on diameter) are provided.filament.toolX.lengthThe extruded length in mm
filament.toolX.volumeThe extruded volume in cm³
printingAreaBounding box of the printed object in the print volume (minimum and maximum coordinates)
printingArea.minXMinimum X coordinate of the printed object
printingArea.maxXMaximum X coordinate of the printed object
printingArea.minYMinimum Y coordinate of the printed object
printingArea.maxYMaximum Y coordinate of the printed object
printingArea.minZMinimum Z coordinate of the printed object
printingArea.maxZMaximum Z coordinate of the printed object
dimensionsDimensions of the printed object in X, Y, Z
dimensions.widthWidth of the printed model along the X axis, in mm
dimensions.depthDepth of the printed model along the Y axis, in mm
dimensions.heightHeight of the printed model along the Z axis, in mm
travelAreaBounding box of all machine movements (minimum and maximum coordinates)
travelArea.minXMinimum X coordinate of the machine movement
travelArea.maxXMaximum X coordinate of the machine movement
travelArea.minYMinimum Y coordinate of the machine movement
travelArea.maxYMaximum Y coordinate of the machine movement
travelArea.minZMinimum Z coordinate of the machine movement
travelArea.maxZMaximum Z coordinate of the machine movement
travelDimensionsDimensions of the travel area in X, Y, Z
travelDimensions.widthWidth of the travel area along the X axis, in mm
travelDimensions.depthDepth of the travel area along the Y axis, in mm
travelDimensions.heightHeight of the travel area along the Z axis, in mm
- class octoprint.filemanager.analysis.QueueEntry(name, path, type, location, absolute_path, printer_profile, analysis)
A
QueueEntryfor processing through theAnalysisQueue. Wraps the entry’s properties necessary for processing.- Parameters:
name (str) – Name of the file to analyze.
path (str) – Storage location specific path to the file to analyze.
type (str) – Type of file to analyze, necessary to map to the correct
AbstractAnalysisQueuesub class. At the moment, onlygcodeis supported here.location (str) – Location the file is located on.
absolute_path (str) – Absolute path on disk through which to access the file.
printer_profile (PrinterProfile) –
PrinterProfilewhich to use for analysis.analysis (dict) –
GcodeAnalysisQueueresults from prior analysis, orNoneif there is none.
octoprint.filemanager.destinations
octoprint.filemanager.storage
- class octoprint.filemanager.storage.LocalFileStorage(basefolder, create=False, really_universal=False)
The
LocalFileStorageis a storage implementation which holds all files, folders and metadata on disk.Metadata is managed inside
.metadata.jsonfiles in the respective folders, indexed by the sanitized filenames stored within the folder. Metadata access is managed through an LRU cache to minimize access overhead.This storage type implements
path_on_disk().- add_file(path, file_object, printer_profile=None, links=None, allow_overwrite=False, display=None, user=None)
Adds the file
file_objectaspath- Parameters:
path (string) – the file’s new path, will be sanitized
file_object (object) – a file object that provides a
savemethod which will be called with the destination path where the object should then store its contentsprinter_profile (object) – the printer profile associated with this file (if any)
links (list) – any links to add with the file
allow_overwrite (bool) – if set to True no error will be raised if the file already exists and the existing file and its metadata will just be silently overwritten
display (str) – display name of the file
user (str) – user who added the file, if known
- Returns:
the sanitized name of the file to be used for future references to it
- add_folder(path, ignore_existing=True, display=None, user=None)
Adds a folder as
pathThe
pathwill be sanitized.- Parameters:
- Returns:
the sanitized name of the new folder to be used for future references to the folder
- add_link(path, rel, data)
Adds a link of relation
relto filepathwith the givendata.The following relation types are currently supported:
model: adds a link to a model from which the file was created/sliced, expected additional data is thenameand optionally thehashof the file to link to. If the link can be resolved against another file on the currentpath, not only will it be added to the links ofnamebut a reverse link of typemachinecodereferring tonameand its hash will also be added to the linkedmodelfilemachinecode: adds a link to a file containing machine code created from the current file (model), expected additional data is thenameand optionally thehashof the file to link to. If the link can be resolved against another file on the currentpath, not only will it be added to the links ofnamebut a reverse link of typemodelreferring tonameand its hash will also be added to the linkedmodelfile.web: adds a location on the web associated with this file (e.g. a website where to download a model), expected additional data is ahrefattribute holding the website’s URL and optionally aretrievedattribute describing when the content was retrieved
Note that adding
modellinks to files identifying as models ormachinecodelinks to files identifying as machine code will be refused.- Parameters:
path – path of the file for which to add a link
rel – type of relation of the link to add (currently
model,machinecodeandwebare supported)data – additional data of the link to add
- property analysis_backlog
Get an iterator over all items stored in the storage that need to be analysed by the
AnalysisQueue.The yielded elements are expected as storage specific absolute paths to the respective files. Don’t forget to recurse into folders if your storage adapter supports those.
- Returns:
an iterator yielding all un-analysed files in the storage
- canonicalize(path)
Canonicalizes the given
path. Thepathmay consist of both folder and file name, the underlying implementation must separate those if necessary.By default, this calls
sanitize(), which also takes care of stripping any invalid characters.- Parameters:
path – the path to canonicalize
- Returns:
a 2-tuple containing the canonicalized path and file name
- copy_file(source, destination)
Copies the file
sourcetodestination- Parameters:
source (string) – path to the source file
destination (string) – path to destination
- Returns:
the path in the storage to the copy of the file
- copy_folder(source, destination)
Copies the folder
sourcetodestination- Parameters:
source (string) – path to the source folder
destination (string) – path to destination
- Returns:
the path in the storage to the copy of the folder
- file_exists(path)
Returns whether the file indicated by
pathexists or not. :param string path: the path to check for existence :return:Trueif the file exists,Falseotherwise
- file_in_path(path, filepath)
Returns whether the file indicated by
fileis insidepathor not. :param string path: the path to check :param string filepath: path to the file :return:Trueif the file is inside the path,Falseotherwise
- folder_exists(path)
Returns whether the folder indicated by
pathexists or not. :param string path: the path to check for existence :return:Trueif the folder exists,Falseotherwise
- get_additional_metadata(path, key)
Fetches additional metadata at
keyfrom the metadata ofpath.- Parameters:
path – the virtual path to the file for which to fetch additional metadata
key – key of metadata to fetch
- get_lastmodified(path: str | None = None, recursive: bool = False) int
Get the modification date of the specified
pathorpath’s subtree.
- get_metadata(path)
Retrieves the metadata for the file
path.- Parameters:
path – virtual path to the file for which to retrieve the metadata
- Returns:
the metadata associated with the file
- get_size(path=None, recursive=False)
Get the size of the specified
pathorpath’s subtree.
- has_analysis(path)
Returns whether the file at path has been analysed yet
- Parameters:
path – virtual path to the file for which to retrieve the metadata
- join_path(*path)
Join path elements together :param path: path elements to join :return: joined representation of the path to be usable as fully qualified path for further operations
- last_modified(path=None, recursive=False)
Get the last modification date of the specified
pathorpath’s subtree.- Parameters:
Returns: (float) The last modification date of the indicated subtree
- list_files(path=None, filter=None, recursive=True, level=0, force_refresh=False)
List all files in storage starting at
path. Ifrecursiveis set to True (the default), also dives into subfolders.An optional filter function can be supplied which will be called with a file name and file data and which has to return True if the file is to be included in the result or False if not.
The data structure of the returned result will be a dictionary mapping from file names to entry data. File nodes will contain their metadata here, folder nodes will contain their contained files and folders. Example:
{ "some_folder": { "name": "some_folder", "path": "some_folder", "type": "folder", "children": { "some_sub_folder": { "name": "some_sub_folder", "path": "some_folder/some_sub_folder", "type": "folder", "typePath": ["folder"], "children": { ... } }, "some_file.gcode": { "name": "some_file.gcode", "path": "some_folder/some_file.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "<sha1 hash>", "links": [ ... ], ... }, ... } "test.gcode": { "name": "test.gcode", "path": "test.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "<sha1 hash>", "links": [...], ... }, "test.stl": { "name": "test.stl", "path": "test.stl", "type": "model", "typePath": ["model", "stl"], "hash": "<sha1 hash>", "links": [...], ... }, ... }
- Parameters:
path (string) – base path from which to recursively list all files, optional, if not supplied listing will start from root of base folder
filter (function) – a filter that matches the files that are to be returned, may be left out in which case no filtering will take place
recursive (bool) – will also step into sub folders for building the complete list if set to True, otherwise will only do one step down into sub folders to be able to populate the
children.
- Returns:
a dictionary mapping entry names to entry data that represents the whole file list
- move_file(source, destination, allow_overwrite=False)
Moves the file
sourcetodestination- Parameters:
source (string) – path to the source file
destination (string) – path to destination
- Returns:
the new path in the storage to the file
- move_folder(source, destination)
Moves the folder
sourcetodestination- Parameters:
source (string) – path to the source folder
destination (string) – path to destination
- Returns:
the new path in the storage to the folder
- path_in_storage(path)
Retrieves the equivalent in the storage adapter for
path.Opposite of
path_on_disk().- Parameters:
path (string) – the path for which to retrieve the storage path
- Returns:
the path in storage to
path
- path_on_disk(path)
Retrieves the path on disk for
path.Note: if the storage is not on disk and there exists no path on disk to refer to it, this method should raise an
io.UnsupportedOperationOpposite of
path_in_storage().- Parameters:
path (string) – the virtual path for which to retrieve the path on disk
- Returns:
the path on disk to
path
- remove_additional_metadata(path, key)
Removes additional metadata under
keyfornameonpath- Parameters:
path – the virtual path to the file for which to remove the metadata under
keykey – the key to remove
- remove_file(path)
Removes the file at
pathWill also take care of deleting the corresponding entries in the metadata and deleting all links pointing to the file.
- Parameters:
path (string) – path of the file to remove
- remove_folder(path, recursive=True)
Removes the folder at
path- Parameters:
path (string) – the path of the folder to remove
recursive (bool) – if set to True, contained folders and files will also be removed, otherwise an error will be raised if the folder is not empty (apart from any metadata files) when it’s to be removed
- remove_link(path, rel, data)
Removes the link consisting of
relanddatafrom filenameonpath.- Parameters:
path – path of the file from which to remove the link
rel – type of relation of the link to remove (currently
model,machinecodeandwebare supported)data – additional data of the link to remove, must match existing link
- sanitize(path)
Returns a
(path, name)tuple derived from the providedpath.pathmay be:a storage path
an absolute file system path
a tuple or list containing all individual path elements
a string representation of the path
with or without a file name
Note that for a
pathwithout a trailing slash the last part will be considered a file name and hence be returned at second position. If you only need to convert a folder path, be sure to include a trailing slash for a stringpathor an empty last element for a listpath.
- sanitize_name(name)
Raises a
ValueErrorfor anamecontaining/or\. Otherwise sanitizes the givennameusingoctoprint.files.sanitize_filename. Also strips any leading..
- sanitize_path(path)
Ensures that the on disk representation of
pathis located under the configured basefolder. Resolves all relative path elements (e.g...) and sanitizes folder names usingsanitize_name(). Final path is the absolute path including leadingbasefolderpath.
- set_additional_metadata(path, key, data, overwrite=False, merge=False)
Adds additional metadata to the metadata of
path. Metadata indatawill be saved underkey.If
overwriteis set andkeyalready exists inname’s metadata, the current value will be overwritten.If
mergeis set andkeyalready exists and bothdataand the existing data underkeyare dictionaries, the two dictionaries will be merged recursively.- Parameters:
path – the virtual path to the file for which to add additional metadata
key – key of metadata to add
data – metadata to add
overwrite – if True and
keyalready exists, it will be overwrittenmerge – if True and
keyalready exists and bothdataand the existing data are dictionaries, they will be merged
- split_path(path)
Split
pathinto base directory and file name. :param path: the path to split :return: a tuple (base directory, file name)
- class octoprint.filemanager.storage.StorageInterface
Interface of storage adapters for OctoPrint.
- add_file(path, file_object, printer_profile=None, links=None, allow_overwrite=False, display=None, user=None)
Adds the file
file_objectaspath- Parameters:
path (string) – the file’s new path, will be sanitized
file_object (object) – a file object that provides a
savemethod which will be called with the destination path where the object should then store its contentsprinter_profile (object) – the printer profile associated with this file (if any)
links (list) – any links to add with the file
allow_overwrite (bool) – if set to True no error will be raised if the file already exists and the existing file and its metadata will just be silently overwritten
display (str) – display name of the file
user (str) – user who added the file, if known
- Returns:
the sanitized name of the file to be used for future references to it
- add_folder(path, ignore_existing=True, display=None, user=None)
Adds a folder as
pathThe
pathwill be sanitized.- Parameters:
- Returns:
the sanitized name of the new folder to be used for future references to the folder
- add_link(path, rel, data)
Adds a link of relation
relto filepathwith the givendata.The following relation types are currently supported:
model: adds a link to a model from which the file was created/sliced, expected additional data is thenameand optionally thehashof the file to link to. If the link can be resolved against another file on the currentpath, not only will it be added to the links ofnamebut a reverse link of typemachinecodereferring tonameand its hash will also be added to the linkedmodelfilemachinecode: adds a link to a file containing machine code created from the current file (model), expected additional data is thenameand optionally thehashof the file to link to. If the link can be resolved against another file on the currentpath, not only will it be added to the links ofnamebut a reverse link of typemodelreferring tonameand its hash will also be added to the linkedmodelfile.web: adds a location on the web associated with this file (e.g. a website where to download a model), expected additional data is ahrefattribute holding the website’s URL and optionally aretrievedattribute describing when the content was retrieved
Note that adding
modellinks to files identifying as models ormachinecodelinks to files identifying as machine code will be refused.- Parameters:
path – path of the file for which to add a link
rel – type of relation of the link to add (currently
model,machinecodeandwebare supported)data – additional data of the link to add
- property analysis_backlog
Get an iterator over all items stored in the storage that need to be analysed by the
AnalysisQueue.The yielded elements are expected as storage specific absolute paths to the respective files. Don’t forget to recurse into folders if your storage adapter supports those.
- Returns:
an iterator yielding all un-analysed files in the storage
- canonicalize(path)
Canonicalizes the given
path. Thepathmay consist of both folder and file name, the underlying implementation must separate those if necessary.By default, this calls
sanitize(), which also takes care of stripping any invalid characters.- Parameters:
path – the path to canonicalize
- Returns:
a 2-tuple containing the canonicalized path and file name
- copy_file(source, destination)
Copies the file
sourcetodestination- Parameters:
source (string) – path to the source file
destination (string) – path to destination
- Returns:
the path in the storage to the copy of the file
- copy_folder(source, destination)
Copies the folder
sourcetodestination- Parameters:
source (string) – path to the source folder
destination (string) – path to destination
- Returns:
the path in the storage to the copy of the folder
- file_exists(path)
Returns whether the file indicated by
pathexists or not. :param string path: the path to check for existence :return:Trueif the file exists,Falseotherwise
- file_in_path(path, filepath)
Returns whether the file indicated by
fileis insidepathor not. :param string path: the path to check :param string filepath: path to the file :return:Trueif the file is inside the path,Falseotherwise
- folder_exists(path)
Returns whether the folder indicated by
pathexists or not. :param string path: the path to check for existence :return:Trueif the folder exists,Falseotherwise
- get_additional_metadata(path, key)
Fetches additional metadata at
keyfrom the metadata ofpath.- Parameters:
path – the virtual path to the file for which to fetch additional metadata
key – key of metadata to fetch
- get_lastmodified(path: str | None = None, recursive: bool = False) int
Get the modification date of the specified
pathorpath’s subtree.
- get_metadata(path)
Retrieves the metadata for the file
path.- Parameters:
path – virtual path to the file for which to retrieve the metadata
- Returns:
the metadata associated with the file
- has_analysis(path)
Returns whether the file at path has been analysed yet
- Parameters:
path – virtual path to the file for which to retrieve the metadata
- join_path(*path)
Join path elements together :param path: path elements to join :return: joined representation of the path to be usable as fully qualified path for further operations
- last_modified(path=None, recursive=False)
Get the last modification date of the specified
pathorpath’s subtree.- Parameters:
Returns: (float) The last modification date of the indicated subtree
- list_files(path=None, filter=None, recursive=True, level=0, force_refresh=False)
List all files in storage starting at
path. Ifrecursiveis set to True (the default), also dives into subfolders.An optional filter function can be supplied which will be called with a file name and file data and which has to return True if the file is to be included in the result or False if not.
The data structure of the returned result will be a dictionary mapping from file names to entry data. File nodes will contain their metadata here, folder nodes will contain their contained files and folders. Example:
{ "some_folder": { "name": "some_folder", "path": "some_folder", "type": "folder", "children": { "some_sub_folder": { "name": "some_sub_folder", "path": "some_folder/some_sub_folder", "type": "folder", "typePath": ["folder"], "children": { ... } }, "some_file.gcode": { "name": "some_file.gcode", "path": "some_folder/some_file.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "<sha1 hash>", "links": [ ... ], ... }, ... } "test.gcode": { "name": "test.gcode", "path": "test.gcode", "type": "machinecode", "typePath": ["machinecode", "gcode"], "hash": "<sha1 hash>", "links": [...], ... }, "test.stl": { "name": "test.stl", "path": "test.stl", "type": "model", "typePath": ["model", "stl"], "hash": "<sha1 hash>", "links": [...], ... }, ... }
- Parameters:
path (string) – base path from which to recursively list all files, optional, if not supplied listing will start from root of base folder
filter (function) – a filter that matches the files that are to be returned, may be left out in which case no filtering will take place
recursive (bool) – will also step into sub folders for building the complete list if set to True, otherwise will only do one step down into sub folders to be able to populate the
children.
- Returns:
a dictionary mapping entry names to entry data that represents the whole file list
- move_file(source, destination)
Moves the file
sourcetodestination- Parameters:
source (string) – path to the source file
destination (string) – path to destination
- Returns:
the new path in the storage to the file
- move_folder(source, destination)
Moves the folder
sourcetodestination- Parameters:
source (string) – path to the source folder
destination (string) – path to destination
- Returns:
the new path in the storage to the folder
- path_in_storage(path)
Retrieves the equivalent in the storage adapter for
path.Opposite of
path_on_disk().- Parameters:
path (string) – the path for which to retrieve the storage path
- Returns:
the path in storage to
path
- path_on_disk(path)
Retrieves the path on disk for
path.Note: if the storage is not on disk and there exists no path on disk to refer to it, this method should raise an
io.UnsupportedOperationOpposite of
path_in_storage().- Parameters:
path (string) – the virtual path for which to retrieve the path on disk
- Returns:
the path on disk to
path
- remove_additional_metadata(path, key)
Removes additional metadata under
keyfornameonpath- Parameters:
path – the virtual path to the file for which to remove the metadata under
keykey – the key to remove
- remove_file(path)
Removes the file at
pathWill also take care of deleting the corresponding entries in the metadata and deleting all links pointing to the file.
- Parameters:
path (string) – path of the file to remove
- remove_folder(path, recursive=True)
Removes the folder at
path- Parameters:
path (string) – the path of the folder to remove
recursive (bool) – if set to True, contained folders and files will also be removed, otherwise an error will be raised if the folder is not empty (apart from any metadata files) when it’s to be removed
- remove_link(path, rel, data)
Removes the link consisting of
relanddatafrom filenameonpath.- Parameters:
path – path of the file from which to remove the link
rel – type of relation of the link to remove (currently
model,machinecodeandwebare supported)data – additional data of the link to remove, must match existing link
- sanitize(path)
Sanitizes the given
path, stripping it of all invalid characters. Thepathmay consist of both folder and file name, the underlying implementation must separate those if necessary and sanitize individually.- Parameters:
path (string) – the path to sanitize
- Returns:
a 2-tuple containing the sanitized path and file name
- sanitize_name(name)
Sanitizes the given file
name, stripping it of all invalid characters. :param string name: the file name to sanitize :return: the sanitized name
- sanitize_path(path)
Sanitizes the given folder-only
path, stripping it of all invalid characters. :param string path: the path to sanitize :return: the sanitized path
- set_additional_metadata(path, key, data, overwrite=False, merge=False)
Adds additional metadata to the metadata of
path. Metadata indatawill be saved underkey.If
overwriteis set andkeyalready exists inname’s metadata, the current value will be overwritten.If
mergeis set andkeyalready exists and bothdataand the existing data underkeyare dictionaries, the two dictionaries will be merged recursively.- Parameters:
path – the virtual path to the file for which to add additional metadata
key – key of metadata to add
data – metadata to add
overwrite – if True and
keyalready exists, it will be overwrittenmerge – if True and
keyalready exists and bothdataand the existing data are dictionaries, they will be merged
- split_path(path)
Split
pathinto base directory and file name. :param path: the path to split :return: a tuple (base directory, file name)
octoprint.filemanager.util
- class 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.
- class octoprint.filemanager.util.DiskFileWrapper(filename, path, move=True)
An implementation of
AbstractFileWrapperthat 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:
- save(path, permissions=None)
Saves the file’s content to the given absolute path.
- class octoprint.filemanager.util.LineProcessorStream(input_stream)
While reading from this stream the provided input_stream is read line by line, calling the (overridable) method
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_linewill 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.
- close()
Flush and close the IO object.
This method has no effect if the file is already closed.
- process_line(line)
Called from the read Method of this stream with each line read from self.input_stream.
By returning
Nonethe line will not be returned from the read stream, effectively being stripped from the wrapper input_stream.
- readable(*args, **kwargs)
Return whether object was opened for reading.
If False, read() will raise OSError.
- seekable(*args, **kwargs)
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().
- writable(*args, **kwargs)
Return whether object was opened for writing.
If False, write() will raise OSError.
- class octoprint.filemanager.util.MultiStream(*streams)
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
io.IOBasestreams to concatenate.
- close()
Flush and close the IO object.
This method has no effect if the file is already closed.
- readable(*args, **kwargs)
Return whether object was opened for reading.
If False, read() will raise OSError.
- seekable(*args, **kwargs)
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().
- writable(*args, **kwargs)
Return whether object was opened for writing.
If False, write() will raise OSError.
- class octoprint.filemanager.util.StreamWrapper(filename, *streams)
A wrapper allowing processing of one or more consecutive streams.
- Parameters:
*streams – One or more
io.IOBasestreams 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
MultiStreamwrapping all provided streams in the order they were provided, else the first and only stream is returned directly.