diff --git a/doc/changelog.txt b/doc/changelog.txt index 19f6c68..dcc09c4 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,3 +1,11 @@ +0.14 "" (released xx.xx.2011) + + * Handle CRX (.crx) files as ZIP archives. They have garbage at + the beginning of the file, but some unzip programs can cope with + that. + * The xz program supports listing of XZ archives. Adjust the + configuration accordingly. + 0.13 "Megamind" (released 25.1.2011) * Fix command argument order when extracting cpio archives. diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 4cd4377..2ca9565 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -188,10 +188,7 @@ ArchivePrograms = { 'create': ('rzip',), }, 'xz': { - 'extract': ('xz',), - 'list': ('echo',), - 'test': ('xz',), - 'create': ('xz',), + None: ('xz',), }, 'zoo': { None: ('zoo',), @@ -415,12 +412,7 @@ def _handle_archive (archive, command, *args, **kwargs): if command == 'create' and os.path.exists(archive): raise util.PatoolError("archive `%s' already exists" % archive) program = config['program'] - # get python module for given archive program - key = util.stripext(os.path.basename(program).lower()) - module = ProgramModules.get(key, key) - # import archive handler (eg. patoolib.programs.star.extract_tar()) - exec "from patoolib.programs.%s import %s_%s as func" % (module, command, format) - get_archive_cmdlist = locals()['func'] + get_archive_cmdlist = get_archive_cmdlist_func(program, command, format) # prepare keyword arguments for command list cmd_kwargs = dict(verbose=config['verbose']) origarchive = None @@ -456,6 +448,20 @@ def _handle_archive (archive, command, *args, **kwargs): pass +def get_archive_cmdlist_func (program, command, format): + # get python module for given archive program + key = util.stripext(os.path.basename(program).lower()) + module = ProgramModules.get(key, key) + # import archive handler function (eg. patoolib.programs.star.extract_tar) + args = (module, command, format) + import_cmd = "from patoolib.programs.%s import %s_%s as func" % args + try: + exec import_cmd + except ImportError: + raise util.PatoolError('ImportError executing %r' % import_cmd) + return locals()['func'] + + def handle_archive (archive, command, *args, **kwargs): """Handle archive file command; with nice error reporting.""" try: diff --git a/tests/test_archives.py b/tests/test_archives.py index 9b0c71e..aecfe8a 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -339,9 +339,7 @@ class TestArchives (ArchiveTest): @needs_program('xz') def test_xz (self): self.program = 'xz' - self.archive_test('t .xz') - self.archive_extract('t .xz') - self.archive_create('t .xz', singlefile=True) + self.archive_commands('t .xz', singlefile=True) @needs_program('lha') def test_lha (self): diff --git a/tests/test_archives2.py b/tests/test_archives2.py new file mode 100644 index 0000000..6693670 --- /dev/null +++ b/tests/test_archives2.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010-2011 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 . +from tests import ArchiveTest, needs_os, needs_program, needs_codec + +class TestArchives (ArchiveTest): + + @needs_codec('tar', 'lzma') + def test_tar_lzma (self): + self.program = 'tar' + archive = 't.tar.lzma' + self.archive_commands(archive) +