2012-05-11 18:07:50 +00:00
|
|
|
Development with the patoolib library
|
|
|
|
======================================
|
|
|
|
|
|
|
|
The patool funtionality can also be used in other Python programs.
|
|
|
|
To do this, install the patool program, import the library and
|
|
|
|
use one or more of the convenience functions.
|
|
|
|
|
|
|
|
import patoolib
|
2013-02-28 20:58:37 +00:00
|
|
|
try:
|
|
|
|
patoolib.extract("myarchive.zip", verbose=True)
|
|
|
|
print("Success.")
|
|
|
|
except patoolib.util.PatoolError as msg:
|
|
|
|
print("Error:", msg)
|
2012-05-11 18:07:50 +00:00
|
|
|
|
|
|
|
General rules for all convenience functions:
|
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* All convenience functions raise PatoolError on errors.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
|
|
|
* Error messages are printed on stderr, informative messages
|
|
|
|
are printed on stdout.
|
|
|
|
|
|
|
|
* All file arguments are filenames. File objects are not accepted
|
|
|
|
as input.
|
|
|
|
|
|
|
|
* Filenames can be relative or absolute.
|
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* If verbosity is increased, additional output of the archive
|
|
|
|
program is shown.
|
|
|
|
|
|
|
|
* Usually the program to be executed is automatically determined
|
|
|
|
but it can be set manually with the program parameter.
|
|
|
|
|
2012-05-11 18:07:50 +00:00
|
|
|
The convenience functions are:
|
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``def extract_archive(archive, verbosity=0, outdir=None, program=None)``
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2012-05-12 10:57:01 +00:00
|
|
|
Extracts the given archive filename to the current working directory
|
|
|
|
or if specified to the given directory name in outdir.
|
|
|
|
Checks that the archive exists and is readable before extracting it.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``def list_archive(archive, verbosity=1, program=None)``
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2012-05-12 10:57:01 +00:00
|
|
|
Lists the contents of the given archive filename on stdout.
|
|
|
|
Checks that the archive exists and is readable before listing it.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``def test_archive(archive, verbosity=0, program=None)``
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2012-05-12 10:57:01 +00:00
|
|
|
Tests the given archive filename.
|
|
|
|
Checks that the archive exists and is readable before testing it.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``def create_archive(archive, filenames, verbosity=0, program=None)``
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2012-05-12 10:57:01 +00:00
|
|
|
Creates a new archive. The type of archive is determined
|
|
|
|
by the archive filename extension.
|
|
|
|
Checks that the archive is not already existing to avoid overwriting it.
|
|
|
|
Also checks that the filename list is not empty and that all files exist
|
|
|
|
and are readable.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``diff_archives(archive1, archive2, verbosity=0)``
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2012-05-11 19:09:32 +00:00
|
|
|
This function lists differences in the content of the two archives.
|
|
|
|
Both archives are extracted and the contents are compared
|
|
|
|
recursively with the diff(1) program.
|
2012-05-12 10:57:01 +00:00
|
|
|
Checks that both archives exist and are readable.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``def search_archive(pattern, archive, verbosity=0)``
|
|
|
|
|
|
|
|
This function searches the given pattern in the archive file contents
|
|
|
|
with grep(1).
|
|
|
|
Checks that archive exists and is readable.
|
2012-05-11 18:07:50 +00:00
|
|
|
|
2013-02-28 20:58:37 +00:00
|
|
|
* ``repack_archive (archive, archive_new, verbosity=0)``
|
|
|
|
|
|
|
|
This function extracts the contents of the archive and packs them
|
|
|
|
into archive_new.
|
|
|
|
Checks that archive exists and is readable. Also checks that
|
|
|
|
archive_new does not exist to avoid overwriting it.
|