qiBuild documentation

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=u'zip', output=None, flat=False, quiet=False, verbose=False, display_progress=False)

Compress directory in an archive :param directory: directory to add to the archive :param output: path to the compressed archive :param algo: compression method (default: zip) :param quiet: silent mode (default: False) :param verbose: verbose mode, print all the archive content

(default: False)
Parameters: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 :param archive: path of the archive :param directory: extract location :param algo: uncompression method (default: guessed from the archive name) :param quiet: silent mode (default: False) :param verbose: verbose mode, print all the archive content (default: False) :return: 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 :param archive: path of the archive :return: the compression algorithm name