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
exception qisys.archive.InvalidArchive(message)

Just a custom exception

qisys.archive.compress(directory, archive=None, algo='zip', quiet=False, verbose=False)

Compress directory in an archive

Parameters:
  • directory – directory to add to the archive
  • archive – output archive basepath
  • algo – compression method (default: zip)
  • quiet – silent mode (default: False)
  • verbose – verbose mode, print all the archive content (default: False)
Returns:

path to the generated archive (archive_basepath.tar.*)

qisys.archive.extract(archive, directory, algo=None, quiet=False, verbose=False)

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)

qisys.archive.guess_algo(archive)

Guess the compression algorithm from the archive filename

Parameters:archive – path of the archive
Returns:the compression algorithm name
qisys.archive.compress(directory, archive=None, algo='zip', quiet=False, verbose=False)

Compress directory in an archive

Parameters:
  • directory – directory to add to the archive
  • archive – output archive basepath
  • algo – compression method (default: zip)
  • quiet – silent mode (default: False)
  • verbose – verbose mode, print all the archive content (default: False)
Returns:

path to the generated archive (archive_basepath.tar.*)

qisys.archive.extract(archive, directory, algo=None, quiet=False, verbose=False)

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 pathes:

    • Archive content:

      ./foo
      ./foo/bar
      ./foo/bar/bar.txt
      ./foo/baz.txt
    • Extacted 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
      
    • Extacted 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