qisys.archive – Manage .tar.gz and .zip files¶
This module contains functions to manipulate archives.
This module can manipulate:
*.zip
archives on all platforms*.tar.gz
and*.tar.bz2
archives on UNIX*.tar.xz
archive is only supported on Linux
The default archive format is zip, to ensure platform interoperability, and also because this is the qiBuild package format.
All archives should have a unique top directory.
To enforce platform interoperability :
- symlinks are dereferenced:
- if the source symlink point to a file, the pointed file is archived in place
- if the source symlink point to a directory, the directory is dropped from the archive
- read-only directories are stored with write access
-
qisys.archive.
compress
(directory, algo='zip', output=None, flat=False, quiet=False, verbose=False, display_progress=False)¶ Compress directory in an archive
Parameters: - directory – directory to add to the archive
- output – path to the compressed archive
- algo – compression method (default: zip)
- quiet – silent mode (default: False)
- verbose – verbose mode, print all the archive content (default: False)
- flat – if false, put all files in a common top dir (default: False)
Returns: path to the generated archive
-
qisys.archive.
extract
(archive, directory, algo=None, quiet=False, verbose=False, strict_mode=True)¶ Extract a an archive into directory
Parameters: - archive – path of the archive
- directory – extract location
- algo – uncompression method (default: guessed from the archive name)
- quiet – silent mode (default: False)
- verbose – verbose mode, print all the archive content (default: False)
Returns: path to the extracted archive (directory/topdir)
If the content is archiving relatively to ”.” or “/”, then this leading field of the path is replace by the archive name.
If several directories or files are stored at the root of the archive, then they will be extracted in a directory maned using the archive name.
e.g.:
Wrong leading field in paths:
Archive content:
./foo ./foo/bar ./foo/bar/bar.txt ./foo/baz.txt
Extracted location:
directory/archive_name/foo directory/archive_name/foo/bar directory/archive_name/foo/bar/bar.txt directory/archive_name/foo/baz.txt
Several items at the root of the archive:
Archive content:
foo foo/bar foo/bar/bar.txt baz.txt
Extracted location:
directory/archive_name/foo directory/archive_name/foo/bar directory/archive_name/foo/bar/bar.txt directory/archive_name/baz.txt
-
qisys.archive.
guess_algo
(archive)¶ Guess the compression algorithm from the archive filename
Parameters: archive – path of the archive Returns: the compression algorithm name