Python module programs now have a py_ suffix.

This commit is contained in:
Bastian Kleineidam 2012-05-12 13:36:59 +02:00
parent e4f1a06c82
commit ef8c0e595c
9 changed files with 51 additions and 45 deletions

View File

@ -78,6 +78,7 @@ CompressionPrograms = {
# List of programs supporting the given archive format and command. # List of programs supporting the given archive format and command.
# If command is None, the program supports all commands (list, extract, ...) # If command is None, the program supports all commands (list, extract, ...)
# Programs starting with "py_" are Python modules.
ArchivePrograms = { ArchivePrograms = {
'ace': { 'ace': {
'extract': ('unace',), 'extract': ('unace',),
@ -100,16 +101,16 @@ ArchivePrograms = {
}, },
'bzip2': { 'bzip2': {
None: ('7z', '7za'), None: ('7z', '7za'),
'extract': ('pbzip2', 'lbzip2', 'bzip2', 'pybz2'), 'extract': ('pbzip2', 'lbzip2', 'bzip2', 'py_bz2'),
'test': ('pbzip2', 'lbzip2', 'bzip2'), 'test': ('pbzip2', 'lbzip2', 'bzip2'),
'create': ('pbzip2', 'lbzip2', 'bzip2', 'pybz2'), 'create': ('pbzip2', 'lbzip2', 'bzip2', 'py_bz2'),
'list': ('echo',), 'list': ('py_echo',),
}, },
'tar': { 'tar': {
None: ('tar', 'star', 'pytarfile'), None: ('tar', 'star', 'py_tarfile'),
}, },
'zip': { 'zip': {
None: ('7z', '7za', 'pyzipfile'), None: ('7z', '7za', 'py_zipfile'),
'extract': ('unzip',), 'extract': ('unzip',),
'list': ('unzip',), 'list': ('unzip',),
'test': ('unzip',), 'test': ('unzip',),
@ -117,27 +118,27 @@ ArchivePrograms = {
}, },
'gzip': { 'gzip': {
None: ('pigz', 'gzip', '7z', '7za'), None: ('pigz', 'gzip', '7z', '7za'),
'extract': ('pygzip',), 'extract': ('py_gzip',),
'create': ('pygzip',), 'create': ('py_gzip',),
}, },
'lzh': { 'lzh': {
None: ('lha',), None: ('lha',),
}, },
'lzip': { 'lzip': {
'extract': ('plzip', 'lzip', 'clzip', 'pdlzip'), 'extract': ('plzip', 'lzip', 'clzip', 'pdlzip'),
'list': ('echo',), 'list': ('py_echo',),
'test': ('plzip', 'lzip', 'clzip', 'pdlzip'), 'test': ('plzip', 'lzip', 'clzip', 'pdlzip'),
'create': ('plzip', 'lzip', 'clzip', 'pdlzip'), 'create': ('plzip', 'lzip', 'clzip', 'pdlzip'),
}, },
'lrzip': { 'lrzip': {
'extract': ('lrzip',), 'extract': ('lrzip',),
'list': ('echo',), 'list': ('py_echo',),
'test': ('lrzip',), 'test': ('lrzip',),
'create': ('lrzip',), 'create': ('lrzip',),
}, },
'compress': { 'compress': {
'extract': ('gzip', '7z', '7za', 'uncompress.real'), 'extract': ('gzip', '7z', '7za', 'uncompress.real'),
'list': ('7z', '7za', 'echo',), 'list': ('7z', '7za', 'py_echo',),
'test': ('gzip', '7z', '7za'), 'test': ('gzip', '7z', '7za'),
'create': ('compress',), 'create': ('compress',),
}, },
@ -182,13 +183,13 @@ ArchivePrograms = {
}, },
'lzma': { 'lzma': {
'extract': ('lzma',), 'extract': ('lzma',),
'list': ('echo',), 'list': ('py_echo',),
'test': ('lzma',), 'test': ('lzma',),
'create': ('lzma',), 'create': ('lzma',),
}, },
'rzip': { 'rzip': {
'extract': ('rzip',), 'extract': ('rzip',),
'list': ('echo',), 'list': ('py_echo',),
'create': ('rzip',), 'create': ('rzip',),
}, },
'xz': { 'xz': {
@ -255,6 +256,9 @@ def find_archive_program (format, command):
raise util.PatoolError("%s archive format `%s' is not supported" % (command, format)) raise util.PatoolError("%s archive format `%s' is not supported" % (command, format))
# return the first existing program # return the first existing program
for program in programs: for program in programs:
if program.startswith('py_'):
# it's a Python module and therefore always supported
return program
exe = util.find_program(program) exe = util.find_program(program)
if exe: if exe:
if program == '7z' and format == 'rar' and not util.p7zip_supports_rar(): if program == '7z' and format == 'rar' and not util.p7zip_supports_rar():
@ -272,7 +276,7 @@ def find_compression_program (program, compression):
found = util.find_program(enc_program) found = util.find_program(enc_program)
if found: if found:
return found return found
elif program == 'pytarfile': elif program == 'py_tarfile':
return compression in ('gzip', 'bzip2') return compression in ('gzip', 'bzip2')
return None return None

View File

@ -13,7 +13,7 @@
# #
# 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 echo program, simulated by the Python print """Archive commands echoing data, implemented by the Python print
statement.""" statement."""
from patoolib import util from patoolib import util

View File

@ -102,14 +102,14 @@ class ArchiveTest (unittest.TestCase):
command = 'test' command = 'test'
program = self.program program = self.program
# special case for programs that cannot test what they create # special case for programs that cannot test what they create
if self.program in ('compress', 'pygzip'): if self.program in ('compress', 'py_gzip'):
program = 'gzip' program = 'gzip'
elif self.program == 'pybz2': elif self.program == 'py_bz2':
program = 'bzip2' program = 'bzip2'
elif self.program == 'zip': elif self.program == 'zip':
program = 'unzip' program = 'unzip'
elif self.program == 'rzip': elif self.program == 'rzip':
program = 'echo' program = 'py_echo'
command = 'list' command = 'list'
patoolib._handle_archive(archive, command, program=program) patoolib._handle_archive(archive, command, program=program)
finally: finally:

View File

@ -96,17 +96,17 @@ class TestArchives (ArchiveTest):
self.program = 'star' self.program = 'star'
self.archive_commands('t.tar.xz') self.archive_commands('t.tar.xz')
def test_pytarfile (self): def test_py_tarfile (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar') self.archive_commands('t.tar')
def test_pytarfile_gz (self): def test_py_tarfile_gz (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar.gz') self.archive_commands('t.tar.gz')
self.archive_commands('t.tgz') self.archive_commands('t.tgz')
def test_pytarfile_bz2 (self): def test_py_tarfile_bz2 (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar.bz2') self.archive_commands('t.tar.bz2')
self.archive_commands('t.tbz2') self.archive_commands('t.tbz2')
@ -118,8 +118,8 @@ class TestArchives (ArchiveTest):
self.archive_create('t .bz2', singlefile=True) self.archive_create('t .bz2', singlefile=True)
@needs_program('bzip2') @needs_program('bzip2')
def test_pybz2 (self): def test_py_bz2 (self):
self.program = 'pybz2' self.program = 'py_bz2'
self.archive_extract('t .bz2') self.archive_extract('t .bz2')
# bzip2 is used to test the created archive # bzip2 is used to test the created archive
self.archive_create('t .bz2', singlefile=True) self.archive_create('t .bz2', singlefile=True)
@ -138,8 +138,8 @@ class TestArchives (ArchiveTest):
self.archive_test('t .bz2') self.archive_test('t .bz2')
self.archive_create('t .bz2', singlefile=True) self.archive_create('t .bz2', singlefile=True)
def test_echo (self): def test_py_echo (self):
self.program = 'echo' self.program = 'py_echo'
self.archive_list('t .bz2') self.archive_list('t .bz2')
self.archive_list('t.Z') self.archive_list('t.Z')
self.archive_list('t.lzma') self.archive_list('t.lzma')
@ -162,8 +162,8 @@ class TestArchives (ArchiveTest):
self.program = 'zip' self.program = 'zip'
self.archive_create('t.zip') self.archive_create('t.zip')
def test_pyzipfile (self): def test_py_zipfile (self):
self.program = 'pyzipfile' self.program = 'py_zipfile'
self.archive_commands('t.zip') self.archive_commands('t.zip')
@needs_program('gzip') @needs_program('gzip')
@ -174,8 +174,8 @@ class TestArchives (ArchiveTest):
self.archive_extract('t.Z') self.archive_extract('t.Z')
@needs_program('gzip') @needs_program('gzip')
def test_pygzip (self): def test_py_gzip (self):
self.program = 'pygzip' self.program = 'py_gzip'
self.archive_extract('t.gz') self.archive_extract('t.gz')
self.archive_extract('t.txt.gz') self.archive_extract('t.txt.gz')
# gzip is used to test the created archive # gzip is used to test the created archive

View File

@ -113,19 +113,19 @@ class TestArchives (ArchiveTest):
self.archive_commands('t.tar.xz.foo', format="tar", encoding="xz") self.archive_commands('t.tar.xz.foo', format="tar", encoding="xz")
@needs_program('file') @needs_program('file')
def test_pytarfile_file (self): def test_py_tarfile_file (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar.foo', format="tar") self.archive_commands('t.tar.foo', format="tar")
@needs_program('file') @needs_program('file')
def test_pytarfile_gz_file (self): def test_py_tarfile_gz_file (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar.gz.foo', format="tar", encoding="gzip") self.archive_commands('t.tar.gz.foo', format="tar", encoding="gzip")
self.archive_commands('t.tgz.foo', format="tar", encoding="gzip") self.archive_commands('t.tgz.foo', format="tar", encoding="gzip")
@needs_program('file') @needs_program('file')
def test_pytarfile_bz2 (self): def test_py_tarfile_bz2 (self):
self.program = 'pytarfile' self.program = 'py_tarfile'
self.archive_commands('t.tar.bz2.foo', format="tar", encoding="bzip2") self.archive_commands('t.tar.bz2.foo', format="tar", encoding="bzip2")
self.archive_commands('t.tbz2.foo', format="tar", encoding="bzip2") self.archive_commands('t.tbz2.foo', format="tar", encoding="bzip2")
@ -138,8 +138,8 @@ class TestArchives (ArchiveTest):
self.archive_create('t.bz2.foo', format="bzip2", singlefile=True) self.archive_create('t.bz2.foo', format="bzip2", singlefile=True)
@needs_program('file') @needs_program('file')
def test_pybz2 (self): def test_py_bz2 (self):
self.program = 'pybz2' self.program = 'py_bz2'
self.archive_extract('t.bz2.foo') self.archive_extract('t.bz2.foo')
self.archive_create('t.bz2.foo', format="bzip2", singlefile=True) self.archive_create('t.bz2.foo', format="bzip2", singlefile=True)
@ -160,8 +160,8 @@ class TestArchives (ArchiveTest):
self.archive_create('t.bz2.foo', format="bzip2", singlefile=True) self.archive_create('t.bz2.foo', format="bzip2", singlefile=True)
@needs_program('file') @needs_program('file')
def test_echo (self): def test_py_echo (self):
self.program = 'echo' self.program = 'py_echo'
self.archive_list('t.bz2.foo') self.archive_list('t.bz2.foo')
self.archive_list('t.Z.foo') self.archive_list('t.Z.foo')
# file(1) does not recognize .lzma files # file(1) does not recognize .lzma files
@ -186,8 +186,8 @@ class TestArchives (ArchiveTest):
self.archive_create('t.zip.foo', format="zip") self.archive_create('t.zip.foo', format="zip")
@needs_program('file') @needs_program('file')
def test_pyzipfile (self): def test_py_zipfile (self):
self.program = 'pyzipfile' self.program = 'py_zipfile'
self.archive_commands('t.zip.foo', format="zip") self.archive_commands('t.zip.foo', format="zip")
@needs_program('file') @needs_program('file')
@ -199,10 +199,12 @@ class TestArchives (ArchiveTest):
self.archive_extract('t.Z.foo') self.archive_extract('t.Z.foo')
@needs_program('file') @needs_program('file')
def test_pygzip (self): @needs_program('gzip')
self.program = 'pygzip' def test_py_gzip (self):
self.program = 'py_gzip'
self.archive_extract('t.gz.foo') self.archive_extract('t.gz.foo')
self.archive_extract('t.txt.gz.foo') self.archive_extract('t.txt.gz.foo')
# gzip is used to test the created archive
self.archive_create('t.gz.foo', format="gzip", singlefile=True) self.archive_create('t.gz.foo', format="gzip", singlefile=True)
self.archive_create('t.txt.gz.foo', format="gzip", singlefile=True) self.archive_create('t.txt.gz.foo', format="gzip", singlefile=True)