From 9a04371f0792c0d6f03fcc3c31b7aadd27a80b41 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 6 Mar 2010 15:47:00 +0100 Subject: [PATCH] Added support for ACE (.ace) archives. --- doc/changelog.txt | 3 ++- doc/patool.1 | 2 +- doc/patool.txt | 10 ++++---- doc/todo.txt | 1 - patoolib/__init__.py | 8 ++++++- patoolib/programs/unace.py | 47 +++++++++++++++++++++++++++++++++++++ patoolib/util.py | 2 ++ tests/data/t.ace | Bin 0 -> 135 bytes tests/data/t.ace.foo | Bin 0 -> 135 bytes tests/test_archives.py | 7 ++++++ tests/test_foo_archives.py | 8 +++++++ tests/test_mime.py | 2 ++ 12 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 patoolib/programs/unace.py create mode 100644 tests/data/t.ace create mode 100644 tests/data/t.ace.foo diff --git a/doc/changelog.txt b/doc/changelog.txt index 87a22f8..6cfc99a 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -3,9 +3,10 @@ * 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. + * Added support for extracting, listing and testing multiple archives. * Fix permissions of extracted files: make them readable by the current user. + * Added support for ACE (.ace) archives. 0.5 "Vanishing Point" (released 4.3.2010) diff --git a/doc/patool.1 b/doc/patool.1 index 1fae8f9..61604b1 100644 --- a/doc/patool.1 +++ b/doc/patool.1 @@ -26,7 +26,7 @@ files without having to remember a myriad of programs and options. The archive format is determined by the file(1) program and as a fallback by the archive file extension. .PP -\fBpatool\fP supports 7z (.7z), ZIP (.zip, .jar), GZIP (.gz), compress (.Z), +\fBpatool\fP supports 7z (.7z), ACE (.ace), ZIP (.zip, .jar), GZIP (.gz), compress (.Z), BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab), CPIO (.cpio), RPM (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA (.lzma), RAR (.rar) and XZ (.xz) formats. diff --git a/doc/patool.txt b/doc/patool.txt index 18d479a..1f8029f 100644 --- a/doc/patool.txt +++ b/doc/patool.txt @@ -18,11 +18,11 @@ DESCRIPTION The archive format is determined by the file(1) program and as a fall‐ back by the archive file extension. - patool supports 7z (.7z), ZIP (.zip, .jar), GZIP (.gz), compress (.Z), - BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab), CPIO (.cpio), RPM - (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA (.lzma), RAR (.rar) - and XZ (.xz) formats. It relies on helper applications to handle those - archive formats (for example bzip2 for BZIP2 archives). + patool supports 7z (.7z), ACE (.ace), ZIP (.zip, .jar), GZIP (.gz), + compress (.Z), BZIP2 (.bz2), TAR (.tar), ARJ (.arj), CAB (.cab), CPIO + (.cpio), RPM (.rpm), DEB (.deb), LZIP (.lz), LZOP (.lzo), LZMA (.lzma), + RAR (.rar) and XZ (.xz) formats. It relies on helper applications to + handle those archive formats (for example bzip2 for BZIP2 archives). EXAMPLES patool extract archive.zip otherarchive.rar diff --git a/doc/todo.txt b/doc/todo.txt index 67b4199..24deb30 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,3 +1,2 @@ -- Support ace (unace) archives. - Support ar archives. - Support lha archives. diff --git a/patoolib/__init__.py b/patoolib/__init__.py index fed1646..79fcd90 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -23,7 +23,7 @@ ArchiveCommands = ('list', 'extract', 'test', 'create') # Supported archive formats ArchiveFormats = ('gzip', 'bzip2', 'tar', 'zip', 'compress', '7z', 'rar', - 'cab', 'arj', 'cpio', 'rpm', 'deb', 'lzop', 'lzma', 'xz', 'lzip') + 'cab', 'arj', 'cpio', 'rpm', 'deb', 'lzop', 'lzma', 'xz', 'lzip', 'ace') # Supported encodings (used with tar for example) # Note that all encodings must also be archive formats @@ -51,6 +51,7 @@ ArchiveMimetypes = { 'application/x-lzma': 'lzma', 'application/x-xz': 'xz', 'application/x-lzip': 'lzip', + 'application/x-ace': 'ace', } # List of programs supporting the given encoding @@ -67,6 +68,11 @@ EncodingPrograms = { # List of programs supporting the given archive format and command. # If command is None, the program supports all commands (list, extract, ...) ArchivePrograms = { + 'ace': { + 'extract': ('unace',), + 'test': ('unace',), + 'list': ('unace',), + }, 'bzip2': { 'extract': ('pbzip2', 'bzip2', '7z'), 'test': ('pbzip2', 'bzip2', '7z'), diff --git a/patoolib/programs/unace.py b/patoolib/programs/unace.py new file mode 100644 index 0000000..2c26a1d --- /dev/null +++ b/patoolib/programs/unace.py @@ -0,0 +1,47 @@ +# -*- 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 unace program.""" + +def extract_ace (archive, encoding, cmd, **kwargs): + """Extract a ACE archive.""" + cmdlist = [cmd] + cmdlist.append('x') + if not kwargs['verbose']: + cmdlist.append('-c-') + cmdlist.extend([archive, kwargs['outdir']]) + return cmdlist + + +def list_ace (archive, encoding, cmd, **kwargs): + """List a ACE archive.""" + cmdlist = [cmd] + if kwargs['verbose']: + cmdlist.append('v') + else: + cmdlist.append('l') + cmdlist.append('-c-') + cmdlist.extend([archive]) + return cmdlist + + +def test_ace (archive, encoding, cmd, **kwargs): + """Test a ACE archive.""" + cmdlist = [cmd] + cmdlist.append('t') + if not kwargs['verbose']: + cmdlist.append('-c-') + cmdlist.extend([archive]) + return cmdlist diff --git a/patoolib/util.py b/patoolib/util.py index 9d7405c..48c52d8 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -39,6 +39,7 @@ mimedb.add_type('application/x-7z-compressed', '.7z', strict=False) mimedb.add_type('application/x-cab', '.cab', strict=False) mimedb.add_type('application/x-rpm', '.rpm', strict=False) mimedb.add_type('application/x-debian-package', '.deb', strict=False) +mimedb.add_type('application/x-ace', '.ace', strict=False) class PatoolError (StandardError): @@ -174,6 +175,7 @@ def get_file_mime_encoding (parts): # Match file(1) output text to mime types FileText2Mime = { "7-zip archive data": "application/x-7z-compressed", + "ACE archive data": "application/x-ace", "ARJ archive data": "application/x-arj", "bzip2 compressed data": "application/x-bzip2", "cpio archive": "application/x-cpio", diff --git a/tests/data/t.ace b/tests/data/t.ace new file mode 100644 index 0000000000000000000000000000000000000000..88b89512f5360f3cdd556b55419cfa6c494835a3 GIT binary patch literal 135 zcmd;XG-P04n4qQQ=_-El`+2Oe@qc$kp95IK(x`)kPu9H7MBA z-%o2EmjVMLBS--lBms2@09pTmfQgxlA;guDq2%9UHK3XX7N9r?Cj-?e0O=hs(=IcB T)vz;^#FXfjRFs$)@p1tGM3NtS literal 0 HcmV?d00001 diff --git a/tests/data/t.ace.foo b/tests/data/t.ace.foo new file mode 100644 index 0000000000000000000000000000000000000000..88b89512f5360f3cdd556b55419cfa6c494835a3 GIT binary patch literal 135 zcmd;XG-P04n4qQQ=_-El`+2Oe@qc$kp95IK(x`)kPu9H7MBA z-%o2EmjVMLBS--lBms2@09pTmfQgxlA;guDq2%9UHK3XX7N9r?Cj-?e0O=hs(=IcB T)vz;^#FXfjRFs$)@p1tGM3NtS literal 0 HcmV?d00001 diff --git a/tests/test_archives.py b/tests/test_archives.py index 18df0c3..c8b8485 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -219,6 +219,13 @@ class TestArchives (ArchiveTest): self.archive_extract('t.cpio') self.archive_create('t.cpio') + @needs_program('unace') + def test_unace (self): + self.program = 'unace' + self.archive_list('t.ace') + self.archive_test('t.ace') + self.archive_extract('t.ace') + @needs_program('rpm') def test_rpm (self): self.program = 'rpm' diff --git a/tests/test_foo_archives.py b/tests/test_foo_archives.py index 958b48d..f8fd946 100644 --- a/tests/test_foo_archives.py +++ b/tests/test_foo_archives.py @@ -251,6 +251,14 @@ class TestArchives (ArchiveTest): self.archive_extract('t.cpio.foo') self.archive_create('t.cpio.foo', format="cpio") + @needs_program('file') + @needs_program('unace') + def test_unace (self): + self.program = 'unace' + self.archive_list('t.ace.foo') + self.archive_test('t.ace.foo') + self.archive_extract('t.ace.foo') + @needs_program('file') @needs_program('rpm') def test_rpm (self): diff --git a/tests/test_mime.py b/tests/test_mime.py index 6ccb541..66e9ad0 100644 --- a/tests/test_mime.py +++ b/tests/test_mime.py @@ -86,3 +86,5 @@ class TestMime (unittest.TestCase): self.mime_test("t.Z.foo", "application/x-compress", None) self.mime_test("t.zip", "application/zip", None) self.mime_test("t.zip.foo", "application/zip", None) + self.mime_test("t.ace", "application/x-ace", None) + self.mime_test("t.ace.foo", "application/x-ace", None)