Add support for APE format.

This commit is contained in:
Bastian Kleineidam 2012-05-17 11:01:06 +02:00
parent 66001fde36
commit 1cb49aa296
7 changed files with 39 additions and 13 deletions

View File

@ -81,7 +81,10 @@ ArchivePrograms = {
'list': ('unalz',),
},
'ape': {
None: ('mac',),
'create': ('mac',),
'extract': ('mac',),
'list': ('py_echo',),
'test': ('mac',),
},
'ar': {
None: ('ar',),

View File

@ -14,10 +14,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the MAC.exe program."""
from patoolib import util
def extract_ape (archive, compression, cmd, **kwargs):
"""Extract an APE archive."""
cmdlist = [cmd]
# XXX todo
"""Decompress an APE archive to a WAV file."""
outfile = util.get_single_outfile(kwargs['outdir'], archive,
extension=".wav")
cmdlist = [cmd, archive, outfile, '-d']
return cmdlist
def create_ape (archive, compression, cmd, *args, **kwargs):
"""Compress a WAV file to an APE archive."""
cmdlist = [cmd]
cmdlist.extend(args)
cmdlist.append(archive)
cmdlist.append('-c2000')
return cmdlist
def test_ape (archive, compression, cmd, **kwargs):
cmdlist = [cmd, archive, '-v']
return cmdlist

View File

@ -46,7 +46,11 @@ def list_rzip (archive, compression, cmd, **kwargs):
"""List a RZIP archive."""
return stripext(cmd, archive)
def stripext (cmd, archive):
def list_ape (archive, compression, cmd, **kwargs):
"""List an APE archive."""
return stripext(cmd, archive, extension=".wav")
def stripext (cmd, archive, extension=""):
"""Print the name without suffix."""
print util.stripext(archive)
print util.stripext(archive)+extension
return None

View File

@ -331,21 +331,21 @@ def stripext (filename):
return os.path.splitext(os.path.basename(filename))[0]
def get_single_outfile (directory, archive):
def get_single_outfile (directory, archive, extension=""):
"""Get output filename if archive is in a single file format like gzip."""
outfile = os.path.join(directory, stripext(archive))
if is_same_filename(archive, outfile):
# prevent overwriting the archive itself
outfile += ".raw"
if os.path.exists(outfile):
extension = ".raw"
if os.path.exists(outfile+extension):
# prevent overwriting existing files
i = 1
newfile = "%s%d" % (outfile, i)
while os.path.exists(newfile):
while os.path.exists(newfile+extension):
newfile = "%s%d" % (outfile, i)
i += 1
outfile = newfile
return outfile
return outfile + extension
def log_error (msg, out=sys.stderr):

BIN
tests/data/pop.wav Normal file

Binary file not shown.

View File

@ -149,6 +149,7 @@ class TestArchives (ArchiveTest):
self.archive_list('t.txt.lz')
self.archive_list('t.txt.lrz')
self.archive_list('t.txt.rz')
self.archive_list('t.ape')
@needs_program('unzip')
def test_unzip (self):
@ -442,4 +443,6 @@ class TestArchives (ArchiveTest):
@needs_program('mac')
def test_mac (self):
self.program = 'mac'
self.archive_extract('t.ape', singlefile=True)
self.archive_extract('t.ape')
self.archive_test('t.ape')
self.archive_create('t.ape', singlefile=True)

View File

@ -487,7 +487,8 @@ class TestArchives (ArchiveTest):
# self.archive_test('t.dms.foo')
# self.archive_list('t.dms.foo')
@needs_program('file')
@needs_program('mac')
def test_mac (self):
self.program = 'mac'
self.archive_extract('t.ape.foo', singlefile=True)
self.archive_extract('t.ape.foo')