Storage¶
-
class mundo.api.storage.Storage(
export_directory: Optional[str] = None
)¶ Manages all file I/O needed for configuration and log files. Files are encoded and decoded as JSON by default, but this behaviour can be disabled in both
save()
andload()
by setting encode and decode, respectively, to False.-
__init__(
export_directory: Optional[str] = None
) None ¶ Finds the appropriate export directory for the current operating system. This can be overwritten using the export_directory parameter.
- Parameters
export_directory – The absolute path of directory to save and load files from
- property export_directory: str¶
Gets the currently set export directory for the application.
- Returns
The absolute path to the applications export directory
- property sessions: List[str]¶
List all available session configuration files.
- Returns
A list of filenames for the currently available session configurations
- property platforms: List[str]¶
List all available platform configuration files.
- Returns
A list of filenames for the currently available platform configurations
-
save(
path: str,
contents: Union[dict, str],
encode: bool = True
) bool ¶ Saves contents to an external file at path in the export directory of the application. If encode is True, the contents will be encoded with JSON before being written.
The export directory can be configured via the
Storage
constructor.All saved files can also be imported using the same filename. Saving to a file with the same name as an existing file results in an overwrite.
- Parameters
path – Path (including file name and extension) to save contents to. The path may only be one subdirectory deep, e.g. sessions/<name>.json. A path such as sessions/old/<name>.json is not allowed
contents – The contents of the file to save. Will be JSON encoded
encode – If the contents should be encoded as JSON
- Returns
True if the file was successfully saved. False otherwise
-
load(
filename: str,
decode: bool = True,
base_dir: Optional[str] = None
) Union[dict, str, bool] ¶ Reads the file contents of filename from the export directory of the application. If decode is True, the contents will be decoded as JSON before being returned.
- Parameters
filename – Filename (including file extension) to load contents from
decode – If the file contents should be decoded as JSON
base_dir – Base directory to load filename from
- Returns
Contents of filename or False if the file could not be read
-
delete(
filename: str
) bool ¶ Deletes an exported file from the export directory, if it exists.
- Parameters
filename – The name of the file to delete
- Returns
True if the file was deleted or does not exist. False otherwise
- load_plugins() List[Tuple[str, Dict[Any, Any]]] ¶
Get a list of all currently available plugins, both external and internal. The list will contain tuples of the plugin base path and its decoded JSON metadata.
- Returns
A list of tuples containing the plugin base path and plugin metadata
-
static asset(
path: str
) str ¶ Finds the absolute path to an application GUI asset. The asset directory will be prepended to path. I.e, to load an icon from icons, path should be set to icons/<icon name>.svg.
Trailing slashes will be removed.
- Parameters
path – The path to the asset from within the asset directory
- Raises
AssetNotFoundError – Raised if the asset could not be loaded, or if path contains illegal characters
- Returns
The absolute path to the asset
-
static load_stylesheet(
name: str,
placeholders: Dict[str, Any] = {}
) Optional[str] ¶ Loads a Qt stylesheet and replaces all occurances of each key in placeholders with the the value of the key.
- Parameters
name – The name of the stylesheet to load from assets/qss/
placeholders – Dictionary containing the placeholder strings as keys (without @ prefix), and the string to replace with as value. If the dictionary is empty, no replacements will be made
- Returns
The loaded and parsed stylesheet, or None if the stylesheet could not be loaded
-
__init__(