diff --git a/patoolib/__init__.py b/patoolib/__init__.py index e7792af..4cc8f20 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -22,7 +22,7 @@ from patoolib import util ArchiveCommands = ('list', 'extract', 'test', 'create') # Supported archive formats -ArchiveFormats = ('7z', 'ace', 'alzip', 'ar', 'arc', 'arj', 'bzip2', +ArchiveFormats = ('7z', 'ace', 'alzip', 'ape', 'ar', 'arc', 'arj', 'bzip2', 'cab', 'compress', 'cpio', 'deb', 'dms', 'gzip', 'lrzip', 'lzh', 'lzip', 'lzma', 'lzop', 'rar', 'rpm', 'rzip', 'tar', 'xz', 'zip', 'zoo') @@ -63,6 +63,7 @@ ArchiveMimetypes = { 'application/x-rzip': 'rzip', 'application/x-zoo': 'zoo', 'application/x-dms': 'dms', + 'audio/x-ape': 'ape', } # List of programs supporting the given archive format and command. @@ -79,6 +80,9 @@ ArchivePrograms = { 'test': ('unalz',), 'list': ('unalz',), }, + 'ape': { + None: ('mac',), + }, 'ar': { None: ('ar',), }, diff --git a/patoolib/programs/mac.py b/patoolib/programs/mac.py new file mode 100644 index 0000000..9730ddf --- /dev/null +++ b/patoolib/programs/mac.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2012 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 MAC.exe program.""" + +def extract_ape (archive, compression, cmd, **kwargs): + """Extract an APE archive.""" + cmdlist = [cmd] + # XXX todo + return cmdlist + diff --git a/patoolib/util.py b/patoolib/util.py index 395f30c..21a44a6 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -51,6 +51,7 @@ mimedb.add_type('application/x-rzip', '.rz', strict=False) mimedb.add_type('application/x-zoo', '.zoo', strict=False) mimedb.add_type('application/x-dms', '.dms', strict=False) mimedb.add_type('application/x-zip-compressed', '.crx', strict=False) +mimedb.add_type('audio/x-ape', '.ape', strict=False) class PatoolError (StandardError): @@ -243,6 +244,7 @@ FileText2Mime = { "ARC archive data": "application/x-arc", "Zoo archive data": "application/x-zoo", "DMS archive data": "application/x-dms", + "Monkey's Audio": "audio/x-ape", } def guess_mime_file_text (file_prog, filename): @@ -378,6 +380,7 @@ def find_program (program): path = os.environ['PATH'] if os.name == 'nt': path = append_to_path(path, get_nt_7z_dir()) + path = append_to_path(path, get_nt_mac_dir()) return find_executable(program, path=path) @@ -404,6 +407,17 @@ def get_nt_7z_dir (): return "" +def get_nt_program_dir (): + """Return the Windows program files directory.""" + progvar = "%ProgramFiles%" + return os.path.expandvars(progvar) + + +def get_nt_mac_dir (): + """Return Monkey Audio Compressor (MAC) directory, or an empty string.""" + return os.path.join(get_nt_program_dir(), "Monkey's Audio") + + def strlist_with_or (alist): """Return comma separated string, and last entry appended with ' or '.""" if len(alist) > 1: diff --git a/tests/data/t.ape b/tests/data/t.ape new file mode 100644 index 0000000..6867407 Binary files /dev/null and b/tests/data/t.ape differ diff --git a/tests/data/t.ape.foo b/tests/data/t.ape.foo new file mode 100644 index 0000000..6867407 Binary files /dev/null and b/tests/data/t.ape.foo differ diff --git a/tests/test_archives.py b/tests/test_archives.py index 66c5d95..47c2487 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -438,3 +438,8 @@ class TestArchives (ArchiveTest): self.archive_test('t.dms') self.archive_extract('t.dms') self.archive_list('t.dms') + + @needs_program('mac') + def test_mac (self): + self.program = 'mac' + self.archive_extract('t.ape', singlefile=True) diff --git a/tests/test_foo_archives.py b/tests/test_foo_archives.py index 72a2b31..f3b0d27 100644 --- a/tests/test_foo_archives.py +++ b/tests/test_foo_archives.py @@ -486,3 +486,8 @@ class TestArchives (ArchiveTest): # self.archive_extract('t.dms.foo') # self.archive_test('t.dms.foo') # self.archive_list('t.dms.foo') + + @needs_program('mac') + def test_mac (self): + self.program = 'mac' + self.archive_extract('t.ape.foo', singlefile=True) diff --git a/tests/test_mime.py b/tests/test_mime.py index dc67795..2fd03a8 100644 --- a/tests/test_mime.py +++ b/tests/test_mime.py @@ -116,6 +116,8 @@ class TestMime (unittest.TestCase): self.mime_test_file("t.zoo.foo", "application/x-zoo", None) self.mime_test_file("t.dms", "application/x-dms", None) self.mime_test_file("t.dms.foo", "application/x-dms", None) + self.mime_test_file("t.ape", "audio/x-ape", None) + self.mime_test_file("t.ape.foo", "audio/x-ape", None) @needs_program('file') @needs_program('lzip') @@ -183,3 +185,4 @@ class TestMime (unittest.TestCase): self.mime_test_mimedb("t.rz", "application/x-rzip", None) self.mime_test_mimedb("t.zoo", "application/x-zoo", None) self.mime_test_mimedb("t.dms", "application/x-dms", None) + self.mime_test_mimedb("t.ape", "audio/x-ape", None)