pymrio.archive

pymrio.archive(source, archive, path_in_arc=None, remove_source=False, compression=8, compresslevel=-1)

Archives a MRIO database as zip file

This function is a wrapper around zipfile.write, to ease the writing of an archive and removing the source data.

Note

In contrast to zipfile.write, this function raises an error if the data (path + filename) are identical in the zip archive. Background: the zip standard allows that files with the same name and path are stored side by side in a zip file. This becomes an issue when unpacking this files as they overwrite each other upon extraction.

Parameters:
  • source (str or pathlib.Path or list of these) – Location of the mrio data (folder). If not all data should be archived, pass a list of all files which should be included in the archive (absolute path)
  • archive (str or pathlib.Path) – Full path with filename for the archive.
  • path_in_arc (string, optional) – Path within the archive zip file where data should be stored. ‘path_in_arc’ must be given without leading dot and slash. Thus to point to the data in the root of the compressed file pass ‘’, for data in e.g. the folder ‘mrio_v1’ pass ‘mrio_v1/’. If None (default) data will be stored in the root of the archive.
  • remove_source (boolean, optional) – If True, deletes the source file from the disk (all files specified in ‘source’ or the specified directory, depending if a list of files or directory was passed). If False, leaves the original files on disk. Also removes all empty directories in source including source.
  • compression (ZIP compression method, optional) – This is passed to zipfile.write. By default it is set to ZIP_DEFLATED. NB: This is different from the zipfile default (ZIP_STORED) which would not give any compression. See https://docs.python.org/3/library/zipfile.html#zipfile-objects for further information. Depending on the value given here additional modules might be necessary (e.g. zlib for ZIP_DEFLATED). Futher information on this can also be found in the zipfile python docs.
  • compresslevel (int, optional) – This is passed to zipfile.write and specifies the compression level. Acceptable values depend on the method specified at the parameter ‘compression’. By default, it is set to -1 which gives a compromise between speed and size for the ZIP_DEFLATED compression (this is internally interpreted as 6 as described here: https://docs.python.org/3/library/zlib.html#zlib.compressobj ) NB: This is only used if python version >= 3.7
Raises:
  • FileExistsError: In case a file to be archived already present in the
  • archive.