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. * Remove the --force option. Local files are now never overwritten.
* Added option alias -v for --verbose. * Added option alias -v for --verbose.
* Added --verbose option to create command. * Added --verbose option to create command.
* Added support for Extract, list and test multiple archives.
0.5 "Vanishing Point" (released 4.3.2010) 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 It relies on helper applications to handle those archive formats
(for example bzip2 for BZIP2 archives). (for example bzip2 for BZIP2 archives).
.SH EXAMPLES .SH EXAMPLES
\fBpatool extract archive.zip\fP \fBpatool extract archive.zip otherarchive.rar\fP
\fBpatool test --verbose dist.tar.gz\fP \fBpatool test --verbose dist.tar.gz\fP
\fBpatool list package.deb\fP \fBpatool list package.deb\fP
\fPpatool create --verbose myfiles.zip file1.txt dir/\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). archive formats (for example bzip2 for BZIP2 archives).
EXAMPLES EXAMPLES
patool extract archive.zip patool extract archive.zip otherarchive.rar
patool test --verbose dist.tar.gz patool test --verbose dist.tar.gz
patool list package.deb patool list package.deb
patool create --verbose myfiles.zip file1.txt dir/ 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) - 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.") raise SystemExit("This program requires Python 2.4 or later.")
from patoolib import handle_archive, list_formats, baker from patoolib import handle_archive, list_formats, baker
@baker.command(default=True, shortopts={"verbose": "v"}, params={ # parameter help and short options
"verbose": "Be verbose when extracting (if the helper application supports it)." params = {
}) "verbose": "Verbose operation (if the helper application supports it).",
def extract (archive, verbose=False): }
"""Extract files from archives.""" shortopts = {"verbose": "v"}
return handle_archive(archive, 'extract')
@baker.command(shortopts={"verbose": "v"}, params={ def handle_multi_archive(archives, cmd, **kwargs):
"verbose": "Verbose archive listing (if the helper application supports it).", """Handle a multi-archive command."""
}) res = 0
def list (archive, verbose=False): for archive in archives:
"""List files in an archive.""" newres = handle_archive(archive, cmd, **kwargs)
return handle_archive(archive, 'list') # return error if one of the archives could not be extracted
if newres:
res = newres
return res
@baker.command(shortopts={"verbose": "v"}, params={ @baker.command(default=True, shortopts=shortopts, params=params)
"verbose": "Verbose archive listing (if the helper application supports it).", def extract (archive, *archives, **kwargs):
}) """Extract files from archive(s)."""
def create (archive, file1, *files, **kwargs): return handle_multi_archive((archive,)+archives, 'extract', **kwargs)
"""Create an archive from given files."""
allfiles = (file1,)+files
return handle_archive(archive, 'create', *allfiles, **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={ @baker.command(shortopts={"verbose": "v"}, params={
"verbose": "Verbose operation (if the helper application supports it).", "verbose": "Verbose operation (if the helper application supports it).",
}) })
def test (archive, verbose=False): def create (archive, file1, *files, **kwargs):
"""Test files in an archive.""" """Create an archive from given files."""
return handle_archive(archive, 'test', verbose=verbose) allfiles = (file1,)+files
return handle_archive(archive, 'create', *allfiles, **kwargs)
@baker.command @baker.command