From 0ad54e0f0f2f6faa1c7f2863e2b17150ade141df Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 6 Mar 2010 14:17:01 +0100 Subject: [PATCH] Added support for extracting, listing and testing multiple archives. --- doc/changelog.txt | 1 + doc/patool.1 | 2 +- doc/patool.txt | 2 +- doc/todo.txt | 1 - patool | 56 ++++++++++++++++++++++++++++------------------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index 2ff8401..9e0b3f8 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -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) diff --git a/doc/patool.1 b/doc/patool.1 index 367d0df..3f1d090 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -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 diff --git a/doc/patool.txt b/doc/patool.txt index 63a89d6..b02822f 100644 --- a/doc/patool.txt +++ b/doc/patool.txt @@ -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/ diff --git a/doc/todo.txt b/doc/todo.txt index bee36bc..c3b7680 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,2 +1 @@ -- Add ability to extract multiple archives. - fix permissions (unreadable files) in extracted files (honor umask) diff --git a/patool b/patool index b86c442..cc63a63 100755 --- a/patool +++ b/patool @@ -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