Add support for APE format.
This commit is contained in:
parent
66001fde36
commit
1cb49aa296
|
@ -81,7 +81,10 @@ ArchivePrograms = {
|
||||||
'list': ('unalz',),
|
'list': ('unalz',),
|
||||||
},
|
},
|
||||||
'ape': {
|
'ape': {
|
||||||
None: ('mac',),
|
'create': ('mac',),
|
||||||
|
'extract': ('mac',),
|
||||||
|
'list': ('py_echo',),
|
||||||
|
'test': ('mac',),
|
||||||
},
|
},
|
||||||
'ar': {
|
'ar': {
|
||||||
None: ('ar',),
|
None: ('ar',),
|
||||||
|
|
|
@ -14,10 +14,25 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""Archive commands for the MAC.exe program."""
|
"""Archive commands for the MAC.exe program."""
|
||||||
|
from patoolib import util
|
||||||
|
|
||||||
def extract_ape (archive, compression, cmd, **kwargs):
|
def extract_ape (archive, compression, cmd, **kwargs):
|
||||||
"""Extract an APE archive."""
|
"""Decompress an APE archive to a WAV file."""
|
||||||
cmdlist = [cmd]
|
outfile = util.get_single_outfile(kwargs['outdir'], archive,
|
||||||
# XXX todo
|
extension=".wav")
|
||||||
|
cmdlist = [cmd, archive, outfile, '-d']
|
||||||
return cmdlist
|
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
|
||||||
|
|
|
@ -46,7 +46,11 @@ def list_rzip (archive, compression, cmd, **kwargs):
|
||||||
"""List a RZIP archive."""
|
"""List a RZIP archive."""
|
||||||
return stripext(cmd, 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 the name without suffix."""
|
||||||
print util.stripext(archive)
|
print util.stripext(archive)+extension
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -331,21 +331,21 @@ def stripext (filename):
|
||||||
return os.path.splitext(os.path.basename(filename))[0]
|
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."""
|
"""Get output filename if archive is in a single file format like gzip."""
|
||||||
outfile = os.path.join(directory, stripext(archive))
|
outfile = os.path.join(directory, stripext(archive))
|
||||||
if is_same_filename(archive, outfile):
|
if is_same_filename(archive, outfile):
|
||||||
# prevent overwriting the archive itself
|
# prevent overwriting the archive itself
|
||||||
outfile += ".raw"
|
extension = ".raw"
|
||||||
if os.path.exists(outfile):
|
if os.path.exists(outfile+extension):
|
||||||
# prevent overwriting existing files
|
# prevent overwriting existing files
|
||||||
i = 1
|
i = 1
|
||||||
newfile = "%s%d" % (outfile, i)
|
newfile = "%s%d" % (outfile, i)
|
||||||
while os.path.exists(newfile):
|
while os.path.exists(newfile+extension):
|
||||||
newfile = "%s%d" % (outfile, i)
|
newfile = "%s%d" % (outfile, i)
|
||||||
i += 1
|
i += 1
|
||||||
outfile = newfile
|
outfile = newfile
|
||||||
return outfile
|
return outfile + extension
|
||||||
|
|
||||||
|
|
||||||
def log_error (msg, out=sys.stderr):
|
def log_error (msg, out=sys.stderr):
|
||||||
|
|
Binary file not shown.
|
@ -149,6 +149,7 @@ class TestArchives (ArchiveTest):
|
||||||
self.archive_list('t.txt.lz')
|
self.archive_list('t.txt.lz')
|
||||||
self.archive_list('t.txt.lrz')
|
self.archive_list('t.txt.lrz')
|
||||||
self.archive_list('t.txt.rz')
|
self.archive_list('t.txt.rz')
|
||||||
|
self.archive_list('t.ape')
|
||||||
|
|
||||||
@needs_program('unzip')
|
@needs_program('unzip')
|
||||||
def test_unzip (self):
|
def test_unzip (self):
|
||||||
|
@ -442,4 +443,6 @@ class TestArchives (ArchiveTest):
|
||||||
@needs_program('mac')
|
@needs_program('mac')
|
||||||
def test_mac (self):
|
def test_mac (self):
|
||||||
self.program = 'mac'
|
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)
|
||||||
|
|
|
@ -487,7 +487,8 @@ class TestArchives (ArchiveTest):
|
||||||
# self.archive_test('t.dms.foo')
|
# self.archive_test('t.dms.foo')
|
||||||
# self.archive_list('t.dms.foo')
|
# self.archive_list('t.dms.foo')
|
||||||
|
|
||||||
|
@needs_program('file')
|
||||||
@needs_program('mac')
|
@needs_program('mac')
|
||||||
def test_mac (self):
|
def test_mac (self):
|
||||||
self.program = 'mac'
|
self.program = 'mac'
|
||||||
self.archive_extract('t.ape.foo', singlefile=True)
|
self.archive_extract('t.ape.foo')
|
||||||
|
|
Loading…
Reference in New Issue