Added support for extracting, listing and testing multiple archives.

This commit is contained in:
Bastian Kleineidam 2010-03-06 14:17:01 +01:00
parent aff6657980
commit 0ad54e0f0f
5 changed files with 37 additions and 25 deletions

View File

@ -3,6 +3,7 @@
* Remove the --force option. Local files are now never overwritten.
* Added option alias -v for --verbose.
* Added --verbose option to create command.
* Added support for Extract, list and test multiple archives.
0.5 "Vanishing Point" (released 4.3.2010)

View File

@ -33,7 +33,7 @@ and XZ (.xz) formats.
It relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives).
.SH EXAMPLES
\fBpatool extract archive.zip\fP
\fBpatool extract archive.zip otherarchive.rar\fP
\fBpatool test --verbose dist.tar.gz\fP
\fBpatool list package.deb\fP
\fPpatool create --verbose myfiles.zip file1.txt dir/\fP

View File

@ -25,7 +25,7 @@ DESCRIPTION
archive formats (for example bzip2 for BZIP2 archives).
EXAMPLES
patool extract archive.zip
patool extract archive.zip otherarchive.rar
patool test --verbose dist.tar.gz
patool list package.deb
patool create --verbose myfiles.zip file1.txt dir/

View File

@ -1,2 +1 @@
- Add ability to extract multiple archives.
- fix permissions (unreadable files) in extracted files (honor umask)

56
patool
View File

@ -22,37 +22,49 @@ if not hasattr(sys, "version_info") or sys.version_info < (2, 4, 0, "final", 0):
raise SystemExit("This program requires Python 2.4 or later.")
from patoolib import handle_archive, list_formats, baker
@baker.command(default=True, shortopts={"verbose": "v"}, params={
"verbose": "Be verbose when extracting (if the helper application supports it)."
})
def extract (archive, verbose=False):
"""Extract files from archives."""
return handle_archive(archive, 'extract')
# parameter help and short options
params = {
"verbose": "Verbose operation (if the helper application supports it).",
}
shortopts = {"verbose": "v"}
@baker.command(shortopts={"verbose": "v"}, params={
"verbose": "Verbose archive listing (if the helper application supports it).",
})
def list (archive, verbose=False):
"""List files in an archive."""
return handle_archive(archive, 'list')
def handle_multi_archive(archives, cmd, **kwargs):
"""Handle a multi-archive command."""
res = 0
for archive in archives:
newres = handle_archive(archive, cmd, **kwargs)
# return error if one of the archives could not be extracted
if newres:
res = newres
return res
@baker.command(shortopts={"verbose": "v"}, params={
"verbose": "Verbose archive listing (if the helper application supports it).",
})
def create (archive, file1, *files, **kwargs):
"""Create an archive from given files."""
allfiles = (file1,)+files
return handle_archive(archive, 'create', *allfiles, **kwargs)
@baker.command(default=True, shortopts=shortopts, params=params)
def extract (archive, *archives, **kwargs):
"""Extract files from archive(s)."""
return handle_multi_archive((archive,)+archives, 'extract', **kwargs)
@baker.command(shortopts=shortopts, params=params)
def list (archive, *archives, **kwargs):
"""List files in archive(s)."""
return handle_multi_archive((archive,)+archives, 'list', **kwargs)
@baker.command(shortopts=shortopts, params=params)
def test (archive, *archives, **kwargs):
"""Test files in archive(s)."""
return handle_multi_archive((archive,)+archives, 'test', **kwargs)
@baker.command(shortopts={"verbose": "v"}, params={
"verbose": "Verbose operation (if the helper application supports it).",
})
def test (archive, verbose=False):
"""Test files in an archive."""
return handle_archive(archive, 'test', verbose=verbose)
def create (archive, file1, *files, **kwargs):
"""Create an archive from given files."""
allfiles = (file1,)+files
return handle_archive(archive, 'create', *allfiles, **kwargs)
@baker.command