Command handlers#
Command handlers are the interfaces between managers and final usages like Django commands or views.
They include the options validators, the glue with project settings that can be used as default option values and a shortand method to perform job process with option management.
- class diskette.core.handlers.DumpCommandHandler[source]#
Abstraction layer between Dumper and the management command, it holds getters to get and validate values for manager options and provide a shortand to dump or load contents with options.
This relies on
logger
attribute that is not provided here. The logger object should be one of compatible classes fromdiskette.utils.loggers
.- get_archive_destination(path=None)[source]#
Either get the archive destination path from given argument if given else from
settings.DISKETTE_DUMP_PATH
.- Parameters:
path (Path) – Path object to a directory.
- Returns:
Discovered path.
- Return type:
Path
- get_archive_filename(filename=None)[source]#
Either get the archive destination filename from given argument if given else from
settings.DISKETTE_DUMP_FILENAME
.- Keyword Arguments:
filename (string) – Filename.
- Returns:
Discovered filename.
- Return type:
Path
- get_application_configurations(appconfs=None, no_data=False)[source]#
Either get the application configurations from
appconfs
value if not empty, else fromsettings.DISKETTE_APPS
.- Keyword Arguments:
appconfs (string or list or Path) –
Either:
A list which includes application configurations;
A string which holds valid JSON;
A Path object to a JSON file to open to get application configurations;
If None or any empty value, the setting will be used.
no_data (boolean) – Value of argument to explicitely disable data dump.
- Returns:
- A boolean value that is True if dump is enabled and a list of
application configuration has been discovered.
- Return type:
tuple
- get_storage_paths(paths=None, no_storages=False)[source]#
Returns given storage paths from args if any else use
settings.DISKETTE_STORAGES
.- Keyword Arguments:
paths (list) – List of Path object for storage paths to use instead of the ones from settings. If empty, the paths defined in settings are used.
no_storages (boolean) – Value of argument to explicitely disable storage dump.
- Returns:
- A boolean value that is True if dump is enabled and a list of
storage Path objects.
- Return type:
tuple
- get_storage_excludes(patterns=None, no_patterns=False)[source]#
Get exclude patterns either from args if given, else use the default ones from
settings.DISKETTE_STORAGES_EXCLUDES
.- Parameters:
patterns (list) – List of patterns to use instead of the ones from settings. If empty, the paths defined in settings are used.
no_patterns (boolean) – Value of argument to explicitely disable storage excluding patterns usage.
- Returns:
- A boolean value that is True if pattern usage is enabled and a list
of patterns to use if any.
- Return type:
tuple
- script(archive_destination=None, application_configurations=None, storages=None, storages_basepath=None, storages_excludes=None, no_data=False, no_storages=False, no_storages_excludes=False, indent=None)[source]#
Create shellscript command lines to dump data and storages.
Note
This does not involve argument validation methods like
get_archive_destination
and others here.- Keyword Arguments:
archive_destination (Path) – Path where the archive will be written. If not given the value from setting
DISKETTE_DUMP_PATH
will be used instead.filename (string) – Custom archive filename to use instead of the default one. Your custom filename must end with
.tar.gz
. Default filename isdiskette[_data][_storages].tar.gz
(parts depend from options).application_configurations (string or list or Path) –
Either:
A list which includes application configurations;
A string which holds valid JSON;
A Path object to a JSON file to open to get application configurations;
If None or any empty value, the setting will be used.
storages (list) – A list of storage Path objects.
storages_basepath (Path) – Basepath for reference in some path resolution. Currently used by storage dump to make relative path for storage files. On default this is based on current working directory. If given, the storage paths must be in the same leaf else this will be an error.
storages_excludes (list) – A list of patterns to exclude storage files from dump.
no_data (boolean) – Disable dump of application datas.
no_storages (boolean) – Disable dump of media storages.
no_storages_excludes (boolean) – Disable usage of excluding patterns when collecting storages files.
indent (integer) – Indentation level in data dumps. If not given, dumps won’t be indented.
- Returns:
- All commands to dump data, each command on its line with a previous
comment line with the dump name.
- Return type:
string
- dump(archive_destination=None, archive_filename=None, application_configurations=None, storages=None, storages_basepath=None, storages_excludes=None, no_data=False, no_checksum=False, no_storages=False, no_storages_excludes=False, indent=None, check=False)[source]#
Run configuration validation and proceed to archiving operations for datas and storages.
- Keyword Arguments:
archive_destination (Path) – Path where the archive will be written. If not given the value from setting
DISKETTE_DUMP_PATH
will be used instead.archive_filename (string) – Custom archive filename to use instead of the default one. Your custom filename must end with
.tar.gz
. Default filename isdiskette[_data][_storages].tar.gz
(parts depend from options).application_configurations (string or list or Path) –
Either:
A list which includes application configurations;
A string which holds valid JSON;
A Path object to a JSON file to open to get application configurations;
If None or any empty value, the setting will be used.
storages (list) – A list of storage Path objects.
storages_basepath (Path) – Basepath for reference in some path resolution. Currently used by storage dump to make relative path for storage files. On default this is based on current working directory. If given, the storage paths must be in the same leaf else this will be an error.
storages_excludes (list) – A list of patterns to exclude storage files from dump.
no_data (boolean) – Disable dump of application datas.
no_checksum (boolean) – Disable archive checksum.
no_storages (boolean) – Disable dump of media storages.
no_storages_excludes (boolean) – Disable usage of excluding patterns when collecting storages files.
indent (integer) – Indentation level in data dumps. If not given, dumps won’t be indented.
check (boolean) – Only run validations and some additional configurations checking instead of performing real dump operations and archiving. Nothing should be queried or created in this mode.
- Returns:
Path to the written archive file. With ‘check’ mode enable the returned path won’t exists since nothing is created.
- Return type:
Path
- class diskette.core.handlers.LoadCommandHandler[source]#
Abstraction layer between Loader and the management command, it holds getters to get and validate values for manager options and provide a shortand to dump or load contents with options.
This relies on
logger
attribute that is not provided here. The logger object should be one of compatible classes fromdiskette.utils.loggers
.- get_archive_path(path)[source]#
Shortand to convert string path to a Path object for local archive file.
- Parameters:
path (string or Path) – The path to convert if elligible.
- Returns:
- If given path is not an URL this returns a Path object else
it returns given path unchanged as a string.
- Return type:
string or Path
- get_checksum(checksum)[source]#
Shortand to switch checksum value.
- Parameters:
checksum (object) – A string for a checksum or a boolean.
- Returns:
If checksum is equal to “no” this returns False to disable checksum creation. Any other value is returned without change.
- Return type:
Path
- get_download_destination(path)[source]#
Shortand to convert string path to a Path object for downloaded archive destination.
- Parameters:
path (string or Path) – The string path to convert.
- Returns:
Path object.
- Return type:
Path
- get_storages_basepath(path=None)[source]#
Get the storage basepath to use when deploying storages.
Storage basepath can not be empty, a critical error object is raised from logger if the basepath resolve to an empty value. However the basepath does not need to exists (but it would lead to unexpected errors).
- Keyword Arguments:
path (Path) – Path to use as the storage basepath. If not given, the value from
settings.DISKETTE_LOAD_STORAGES_PATH
is used.- Returns:
Storage basepath.
- Return type:
Path
- load(archive_path, storages_basepath=None, data_exclusions=None, no_data=False, no_storages=False, download_destination=None, keep=False, checksum=None)[source]#
Proceed to load and deploy archive contents.
- Keyword Arguments:
archive_filename (string) – Custom archive filename to use instead of the default one. Your custom filename must end with
.tar.gz
. Default filename isdiskette[_data][_storages].tar.gz
(parts depend from options).storages_basepath (Path) – Basepath for reference in some path resolution. Currently used by storage dump to make relative path for storage files. On default this is based on current working directory. If given, the storage paths must be in the same leaf else this will be an error.
data_exclusions (list) – List of dump filenames to exclude from loading.
no_data (boolean) – Disable loading application datas from archive.
no_storages (boolean) – Disable loading media storages from archive.
download_destination (Path) – A path where to write downloaded archive file. If not given, the archive file will be written as
diskette_downloaded_archive.tar.gz
into the current working directory. This argument is useless with local archive file.keep (boolean) – If enabled, the archive is not automatically removed once loading if finished. On default this is disabled and the archive is removed.
checksum (object) –
Manage if archive is checksumed or not depending value:
If
None
: Checksum is done and just output to logs;If
True
: Checksum is done and just output to logs;If
False
: No checksum are done or compared;Any other value is assumed to be a string for a checksum to compare. Then a checksum is done on archive and compared to the given one, if comparaison fails it results to a critical error.
- Returns:
Statistics of deployed storages and datas.
- Return type:
dict