scistag.filestag.shared_archive.SharedArchive¶
- class SharedArchive(source, identifier, cache=False)[source]¶
Bases:
objectDefines a shared zip archive which can be used by multiple users, e.g. classes to provide shared data quickly from a compact archive once initialized.
Usage: SharedArchive.register(“sharedData.zip”, “sharedData”)
Then data can be loaded flexible via FileStag, independent of if it’s located in the web, in a zip archive or as simple local file: FileStag.load_file(“zip://@sharedData/testFile.zip”) FileStag.load_file(“local_file.txt”) FileStag.load_file(“https://www….”)
Note: Registered zip files have to add an @ in front of their identifier.
Initializer
- Parameters
Methods
Verifies if a file exists within a zip file
Closes the archive to unload and not having to wait for the gc
Returns if the file exists
Returns if given file exists
Lists all element from the archive matching given filter
Returns if a given zip file was registered
Loads a file by filename
Loads a file directly from a zip archive
Loads the data from given file to memory
Registers a new archive.
Scans an archive for a given file mask to search for files of a specific type
Unloads a zip file, e.g.
Attributes
__annotations____dict____doc____module____weakref__list of weak references to the object (if defined)
Access lock (for multi-threading)
Dictionary of the loaded archives, identifier: SharedArchive
The archive's unique identifier
The archive's filename (if loaded from a file), otherwise empty
- classmethod _split_identifier_and_filename(identifier)[source]¶
Returns the registered zip archive and the filename within the archive
- Parameters
identifier – The provided identifier
- Returns
identifier or filename of zip file, filename within the archive
- static check_in_zip_direct(zip_filename, filename)[source]¶
Verifies if a file exists within a zip file
- Parameters
zip_filename – The name of the zip file
filename – The filename within the zip file
- Return type
- Returns
Returns if the file exists
- classmethod exists_at_source(identifier, filename=None)[source]¶
Returns if given file exists
- Parameters
identifier (str) – The archive identifier. Alternate: a full identifier in the form
zip://@identifier/filename :type filename: str | None :param filename: The name of the file to load. :rtype: bool :return: True if the file exists
- classmethod is_loaded(filename)[source]¶
Returns if a given zip file was registered
- Parameters
filename – The zip file to be removed
- Return type
- Returns
True if the archive exists
- classmethod load_file(identifier, filename=None)[source]¶
Loads a file by filename
- Parameters
identifier (str) – The archive identifier. Alternate: a full identifier in the form
- zip://@identifier/filename or a path to a zipfile, e.g.
zip://filename.zip/filename
- static load_file_from_zip_direct(zip_filename, filename)[source]¶
Loads a file directly from a zip archive
- Parameters
zip_filename – The name of the zip file
filename – The filename within the zip file
- Return type
bytes | None
- Returns
The file’s data if it could be found. None otherwise.
- classmethod register(source, identifier, cache=False)[source]¶
Registers a new archive.
- Parameters
- Return type
- Returns
The archive
- classmethod scan(identifier, name_filter='*', long_identifier=True)[source]¶
Scans an archive for a given file mask to search for files of a specific type
- Parameters
- Return type
- Returns
All file in given archive matching the mask
- classmethod unload(filename=None, identifier=None)[source]¶
Unloads a zip file, e.g. if it’s uninstalled
- access_lock = <RLock(None, 0)>¶
Access lock (for multi-threading)
- archives: dict[str, 'SharedArchive'] = {'scistagessential': <scistag.filestag.shared_archive.SharedArchive object>}¶
Dictionary of the loaded archives, identifier: SharedArchive
- filename¶
The archive’s filename (if loaded from a file), otherwise empty
- identifier¶
The archive’s unique identifier