qibuild.archive – Manage .tar.gz and .zip files

This module contains function to manipulate archives.

We will always manipulate .tar.gz archives on UNIX, and .zip on windows. (keeping it close to the more common used format of the given platform)

All archives should have a unique top dir.

exception qibuild.archive.InvalidArchive(message)

Just a custom exception

qibuild.archive.archive_name(directory)

Return the name an archive made from the directory would have. (platform-dependant)

On windows:

>>> archive_name('foo')
foo.zip

Elsewhere:

>>> archive_name('foo')
foo.tar.gz
qibuild.archive.extract(archive_path, directory, topdir=None, quiet=False)

Extract an archive, calling extract_zip or extract_tar when necessary

The top directory of the archive will be replaced by topdir if it is given

Returns:path to the extracted archive
qibuild.archive.extract_tar(archive_path, dest_dir, quiet=False)

Extract a .tar.gz archive

Returns:path to the extracted archive (dest_dir/topdir)
qibuild.archive.extract_zip(archive_path, dest_dir, quiet=False)

Extract a zip archive :return: path to the extracted archive (dest_dir/topdir)

qibuild.archive.extracted_name(archive_name)

Return the extracted name from the archive name.

Warning: this assumes the archive is well-formed (ie the root dir of foo.tar.gz is foo)

>>> extracted_name("foo.zip")
'foo'
>>> extracted_name("foo.tar.gz")
'foo'
qibuild.archive.zip(directory)

Zip a directory, using .zip on Windows or .tar.gz otherwise.

qibuild.archive.zip_unix(directory)

Call tar cvfz on a directory

qibuild.archive.zip_win(directory)

Compress the directory in a .zip file