From 82708b74fa50e79e257b3d8540494f465ab14e6b Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 20 Mar 2010 11:34:40 +0100 Subject: [PATCH] Added support for RZIP (.rz) archives. --- doc/changelog.txt | 1 + doc/patool.1 | 3 ++- patoolib/__init__.py | 8 +++++++- patoolib/programs/echo.py | 4 ++++ patoolib/programs/rzip.py | 37 +++++++++++++++++++++++++++++++++++++ patoolib/util.py | 2 ++ setup.py | 6 +++--- tests/__init__.py | 12 ++++++++---- tests/data/t.txt.rz | Bin 0 -> 89 bytes tests/data/t.txt.rz.foo | Bin 0 -> 89 bytes tests/test_archives.py | 7 +++++++ tests/test_foo_archives.py | 8 +++++++- 12 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 patoolib/programs/rzip.py create mode 100644 tests/data/t.txt.rz create mode 100644 tests/data/t.txt.rz.foo diff --git a/doc/changelog.txt b/doc/changelog.txt index 958a979..1bcda6e 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -2,6 +2,7 @@ * Do not use the diff -B option when comparing archives. * Improved documentation: explain commands in more detail. + * Added support for RZIP (.rz) archives. 0.8 "Storage" (released 11.3.2010) diff --git a/doc/patool.1 b/doc/patool.1 index 95838f3..46909ec 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -32,7 +32,8 @@ by the archive file extension. ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio), DEB (.deb), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP (.lzo), -RPM (.rpm), RAR (.rar), TAR (.tar), XZ (.xz) and ZIP (.zip, .jar) formats. +RPM (.rpm), RAR (.rar), RZIP (.rz), TAR (.tar), XZ (.xz) and ZIP (.zip, .jar) +formats. It relies on helper applications to handle those archive formats (for example bzip2 for BZIP2 archives). .SH EXAMPLES diff --git a/patoolib/__init__.py b/patoolib/__init__.py index e169786..042a87f 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -24,7 +24,7 @@ ArchiveCommands = ('list', 'extract', 'test', 'create') # Supported archive formats ArchiveFormats = ('7z', 'ace', 'alzip', 'ar', 'arc', 'arj', 'bzip2', 'cab', 'compress', 'cpio', 'deb', 'gzip', 'lrzip', 'lzh', 'lzip', 'lzma', - 'lzop', 'rar', 'rpm', 'tar', 'xz', 'zip') + 'lzop', 'rar', 'rpm', 'rzip', 'tar', 'xz', 'zip') # Supported encodings (used with tar for example) # Note that all encodings must also be archive formats @@ -59,6 +59,7 @@ ArchiveMimetypes = { 'application/x-alzip': 'alzip', 'application/x-arc': 'arc', 'application/x-lrzip': 'lrzip', + 'application/x-rzip': 'rzip', } # List of programs supporting the given encoding @@ -178,6 +179,11 @@ ArchivePrograms = { 'test': ('lzma',), 'create': ('lzma',), }, + 'rzip': { + 'extract': ('rzip',), + 'list': ('echo',), + 'create': ('rzip',), + }, 'xz': { 'extract': ('xz',), 'list': ('echo',), diff --git a/patoolib/programs/echo.py b/patoolib/programs/echo.py index 997d4ca..56a3cbb 100644 --- a/patoolib/programs/echo.py +++ b/patoolib/programs/echo.py @@ -41,6 +41,10 @@ def list_lrzip (archive, encoding, cmd, **kwargs): """List a LRZIP archive.""" return stripext(cmd, archive) +def list_rzip (archive, encoding, cmd, **kwargs): + """List a RZIP archive.""" + return stripext(cmd, archive) + def stripext (cmd, archive): """Echo the name without suffix.""" return [cmd, util.stripext(archive)] diff --git a/patoolib/programs/rzip.py b/patoolib/programs/rzip.py new file mode 100644 index 0000000..f5f5035 --- /dev/null +++ b/patoolib/programs/rzip.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Bastian Kleineidam +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +"""Archive commands for the lrzip program.""" +import os +from patoolib import util + +def extract_rzip (archive, encoding, cmd, **kwargs): + """Extract a RZIP archive.""" + # Since extracted files will be placed in the current directory, + # the cwd argument has to be the output directory. + cmdlist = [cmd, '-d', '-k'] + if kwargs['verbose']: + cmdlist.append('-v') + outfile = util.get_single_outfile(kwargs['outdir'], archive) + cmdlist.extend(["-o", outfile, os.path.abspath(archive)]) + return (cmdlist, {'cwd': kwargs['outdir']}) + +def create_rzip (archive, encoding, cmd, *args, **kwargs): + """Create a RZIP archive.""" + cmdlist = [cmd, '-k', '-o', archive] + if kwargs['verbose']: + cmdlist.append('-v') + cmdlist.extend(args) + return cmdlist diff --git a/patoolib/util.py b/patoolib/util.py index 83e3602..51c8745 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -47,6 +47,7 @@ mimedb.add_type('application/x-arc', '.arc', strict=False) mimedb.add_type('application/x-lrzip', '.lrz', strict=False) mimedb.add_type('application/x-lha', '.lha', strict=False) mimedb.add_type('application/x-lzh', '.lzh', strict=False) +mimedb.add_type('application/x-rzip', '.rz', strict=False) class PatoolError (StandardError): @@ -205,6 +206,7 @@ FileText2Mime = { "Zip archive data": "application/zip", "compress'd data": "application/x-compress", "lzip compressed data": "application/x-lzip", + "rzip compressed data": "application/x-rzip", "current ar archive": "application/x-archive", "LHa ": "application/x-lha", "ARC archive data": "application/x-arc", diff --git a/setup.py b/setup.py index 19dc31f..4b74964 100644 --- a/setup.py +++ b/setup.py @@ -49,9 +49,9 @@ fallback by the archive file extension. patool supports 7z (.7z), ACE (.ace), ALZIP (.alz), AR (.a), ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio), DEB (.deb), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), -LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), TAR (.tar), XZ (.xz) -and ZIP (.zip, .jar) formats. It relies on helper applications to handle -those archive formats (for example bzip2 for BZIP2 archives).""", +LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), TAR (.tar), +XZ (.xz) and ZIP (.zip, .jar) formats. It relies on helper applications +to handle those archive formats (for example bzip2 for BZIP2 archives).""", author = MyName, author_email = MyEmail, maintainer = MyName, diff --git a/tests/__init__.py b/tests/__init__.py index d40ef09..8acaf3f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -94,14 +94,18 @@ class ArchiveTest (unittest.TestCase): try: patoolib._handle_archive(archive, 'create', topack, **kwargs) self.assertTrue(os.path.isfile(archive)) - # not all programs can test what they create + # test the created archive + command = 'test' + program = self.program + # special case for programs that cannot test what they create if self.program == 'compress': program = 'gzip' elif self.program == 'zip': program = 'unzip' - else: - program = self.program - patoolib._handle_archive(archive, 'test', program=program) + elif self.program == 'rzip': + program = 'echo' + command = 'list' + patoolib._handle_archive(archive, command, program=program) finally: os.chdir(basedir) shutil.rmtree(tmpdir) diff --git a/tests/data/t.txt.rz b/tests/data/t.txt.rz new file mode 100644 index 0000000000000000000000000000000000000000..e070832918082d44231f330afc9a575fec969014 GIT binary patch literal 89 wcmWHF@(f^NWME)m24W-t=Sl$u;T%H{hYLu6Fc^TPls_ETV+OHc3Qdf-0IOmIH~;_u literal 0 HcmV?d00001 diff --git a/tests/data/t.txt.rz.foo b/tests/data/t.txt.rz.foo new file mode 100644 index 0000000000000000000000000000000000000000..e070832918082d44231f330afc9a575fec969014 GIT binary patch literal 89 wcmWHF@(f^NWME)m24W-t=Sl$u;T%H{hYLu6Fc^TPls_ETV+OHc3Qdf-0IOmIH~;_u literal 0 HcmV?d00001 diff --git a/tests/test_archives.py b/tests/test_archives.py index dfe0ea4..ca6c189 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -115,6 +115,7 @@ class TestArchives (ArchiveTest): self.archive_list('t.lzma') self.archive_list('t.txt.lz') self.archive_list('t.txt.lrz') + self.archive_list('t.txt.rz') @needs_program('unzip') def test_unzip (self): @@ -311,3 +312,9 @@ class TestArchives (ArchiveTest): self.archive_test('t.txt.lrz') self.archive_extract('t.txt.lrz') self.archive_create('t.txt.lrz', singlefile=True) + + @needs_program('rzip') + def test_rzip (self): + self.program = 'rzip' + self.archive_extract('t.txt.rz') + self.archive_create('t.txt.rz', singlefile=True) diff --git a/tests/test_foo_archives.py b/tests/test_foo_archives.py index 9dbd5af..1fbe234 100644 --- a/tests/test_foo_archives.py +++ b/tests/test_foo_archives.py @@ -349,10 +349,16 @@ class TestArchives (ArchiveTest): self.archive_list('t.arc.foo') self.archive_extract('t.arc.foo') - # file(1) does not recognize .alz files + # file(1) does not recognize .lrz files #@needs_program('lrzip') #def test_lrzip (self): # self.program = 'lrzip' # self.archive_test('t.txt.lrz.foo') # self.archive_extract('t.txt.lrz.foo') # self.archive_create('t.txt.lrz.foo', format="lrzip", singlefile=True) + + @needs_program('rzip') + def test_rzip (self): + self.program = 'rzip' + self.archive_extract('t.txt.rz.foo') + self.archive_create('t.txt.rz.foo', format="rzip", singlefile=True)