Rename encoding to compression in the context of archive handling. Makes more sense.

This commit is contained in:
Bastian Kleineidam 2012-05-12 09:31:27 +02:00
parent 3fd52ed508
commit 79a376ce4e
39 changed files with 152 additions and 152 deletions

View File

@ -26,9 +26,9 @@ ArchiveFormats = ('7z', 'ace', 'alzip', 'ar', 'arc', 'arj', 'bzip2',
'cab', 'compress', 'cpio', 'deb', 'dms', 'gzip', 'lrzip', 'lzh', 'lzip', 'lzma',
'lzop', 'rar', 'rpm', 'rzip', 'tar', 'xz', 'zip', 'zoo')
# Supported encodings (used with tar for example)
# Note that all encodings must also be archive formats
ArchiveEncodings = ('bzip2', 'compress', 'gzip', 'lzip', 'lzma', 'xz')
# Supported compressions (used with tar for example)
# Note that all compressions must also be archive formats
ArchiveCompressions = ('bzip2', 'compress', 'gzip', 'lzip', 'lzma', 'xz')
# Map MIME types to archive format
ArchiveMimetypes = {
@ -65,9 +65,9 @@ ArchiveMimetypes = {
'application/x-dms': 'dms',
}
# List of programs supporting the given encoding
# List of programs supporting the given compression
EncodingPrograms = {
CompressionPrograms = {
'gzip': ('pigz', 'gzip'),
'bzip2': ('pbzip2', 'lbzip2', 'bzip2'),
'compress': ('compress',),
@ -215,26 +215,26 @@ ProgramModules = {
def get_archive_format (filename):
"""Detect filename archive format and optional encoding."""
mime, encoding = util.guess_mime(filename)
if not (mime or encoding):
"""Detect filename archive format and optional compression."""
mime, compression = util.guess_mime(filename)
if not (mime or compression):
raise util.PatoolError("unknown archive format for file `%s'" % filename)
if mime in ArchiveMimetypes:
format = ArchiveMimetypes[mime]
else:
raise util.PatoolError("unknown archive format for file `%s' (mime-type is `%s')" % (filename, mime))
if format == encoding:
# file cannot be in same format encoded
encoding = None
return format, encoding
if format == compression:
# file cannot be in same format compressed
compression = None
return format, compression
def check_archive_format (format, encoding):
"""Make sure format and encoding is known."""
def check_archive_format (format, compression):
"""Make sure format and compression is known."""
if format not in ArchiveFormats:
raise util.PatoolError("unknown archive format `%s'" % format)
if encoding is not None and encoding not in ArchiveEncodings:
raise util.PatoolError("unkonwn archive encoding `%s'" % encoding)
if compression is not None and compression not in ArchiveCompressions:
raise util.PatoolError("unkonwn archive compression `%s'" % compression)
def check_archive_command (command):
@ -264,16 +264,16 @@ def find_archive_program (format, command):
raise util.PatoolError("could not find an executable program to %s format %s; candidates are (%s)," % (command, format, ",".join(programs)))
def find_encoding_program (program, encoding):
"""Find suitable encoding program and return it. Returns None if
no encoding program could be found"""
def find_compression_program (program, compression):
"""Find suitable compression program and return it. Returns None if
no compression program could be found"""
if program in ('tar', 'star'):
for enc_program in EncodingPrograms[encoding]:
for enc_program in CompressionPrograms[compression]:
found = util.find_program(enc_program)
if found:
return found
elif program == 'pytarfile':
return encoding in ('gzip', 'bzip2')
return compression in ('gzip', 'bzip2')
return None
@ -290,9 +290,9 @@ def list_formats ():
program = find_archive_program(format, command)
print " %8s: %s" % (command, program),
if format == 'tar':
encs = [x for x in ArchiveEncodings if util.find_program(x)]
encs = [x for x in ArchiveCompressions if util.find_program(x)]
if encs:
print "(supported encodings: %s)" % ", ".join(encs),
print "(supported compressions: %s)" % ", ".join(encs),
elif format == '7z':
if util.p7zip_supports_rar():
print "(rar archives supported)",
@ -317,10 +317,10 @@ def clean_config_keys (kwargs):
return config_kwargs
def parse_config (archive, format, encoding, command, **kwargs):
def parse_config (archive, format, compression, command, **kwargs):
"""The configuration determines which program to use for which
archive format for the given command.
@raises: PatoolError if command for given format and encoding
@raises: PatoolError if command for given format and compression
is not supported.
"""
config = {
@ -335,9 +335,9 @@ def parse_config (archive, format, encoding, command, **kwargs):
value = program
config[key] = value
program = os.path.basename(config['program'])
if encoding and not find_encoding_program(program, encoding):
msg = "cannot %s archive `%s': encoding `%s' not supported by %s" % \
(command, archive, encoding, program)
if compression and not find_compression_program(program, compression):
msg = "cannot %s archive `%s': compression `%s' not supported by %s" % \
(command, archive, compression, program)
raise util.PatoolError(msg)
return config
@ -427,13 +427,13 @@ def check_archive_arguments (archive, command, *args):
def _handle_archive (archive, command, *args, **kwargs):
"""Handle archive command; raising PatoolError on errors."""
check_archive_arguments(archive, command, *args)
format, encoding = kwargs.get("format"), kwargs.get("encoding")
format, compression = kwargs.get("format"), kwargs.get("compression")
if format is None:
format, encoding = get_archive_format(archive)
check_archive_format(format, encoding)
format, compression = get_archive_format(archive)
check_archive_format(format, compression)
check_archive_command(command)
config_kwargs = clean_config_keys(kwargs)
config = parse_config(archive, format, encoding, command, **config_kwargs)
config = parse_config(archive, format, compression, command, **config_kwargs)
# check if archive already exists
if command == 'create' and os.path.exists(archive):
raise util.PatoolError("archive `%s' already exists" % archive)
@ -455,7 +455,7 @@ def _handle_archive (archive, command, *args, **kwargs):
origarchive = archive
archive = util.tmpfile(dir=os.path.dirname(archive), suffix=".arc")
try:
cmdlist = get_archive_cmdlist(archive, encoding, program, *args, **cmd_kwargs)
cmdlist = get_archive_cmdlist(archive, compression, program, *args, **cmd_kwargs)
if cmdlist:
# an empty command list means the get_archive_cmdlist() function
# already handled the command (eg. when it's a builting Python

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from patoolib import util
def extract_singlefile_standard (archive, encoding, cmd, **kwargs):
def extract_singlefile_standard (archive, compression, cmd, **kwargs):
"""Standard routine to extract a singlefile archive (like gzip)."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
@ -26,7 +26,7 @@ def extract_singlefile_standard (archive, encoding, cmd, **kwargs):
return (cmdlist, {'shell': True})
def test_singlefile_standard (archive, encoding, cmd, **kwargs):
def test_singlefile_standard (archive, compression, cmd, **kwargs):
"""Standard routine to test a singlefile archive (like gzip)."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -35,7 +35,7 @@ def test_singlefile_standard (archive, encoding, cmd, **kwargs):
return cmdlist
def create_singlefile_standard (archive, encoding, cmd, *args, **kwargs):
def create_singlefile_standard (archive, compression, cmd, *args, **kwargs):
"""Standard routine to create a singlefile archive (like gzip)."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:

View File

@ -15,14 +15,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the ar program."""
def extract_ar (archive, encoding, cmd, **kwargs):
def extract_ar (archive, compression, cmd, **kwargs):
"""Extract a AR archive."""
opts = 'x'
if kwargs['verbose']:
opts += 'v'
return [cmd, opts, archive, kwargs['outdir']]
def list_ar (archive, encoding, cmd, **kwargs):
def list_ar (archive, compression, cmd, **kwargs):
"""List a AR archive."""
opts = 't'
if kwargs['verbose']:
@ -31,7 +31,7 @@ def list_ar (archive, encoding, cmd, **kwargs):
test_ar = list_ar
def create_ar (archive, encoding, cmd, *args, **kwargs):
def create_ar (archive, compression, cmd, *args, **kwargs):
"""Create a AR archive."""
opts = 'rc'
if kwargs['verbose']:

View File

@ -16,14 +16,14 @@
"""Archive commands for the arc program."""
import os
def extract_arc (archive, encoding, cmd, **kwargs):
def extract_arc (archive, compression, cmd, **kwargs):
"""Extract a ARC archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
cmdlist = [cmd, 'x', os.path.abspath(archive)]
return (cmdlist, {'cwd': kwargs['outdir']})
def list_arc (archive, encoding, cmd, **kwargs):
def list_arc (archive, compression, cmd, **kwargs):
"""List a ARC archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -33,11 +33,11 @@ def list_arc (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def test_arc (archive, encoding, cmd, **kwargs):
def test_arc (archive, compression, cmd, **kwargs):
"""Test a ARC archive."""
return [cmd, 't', archive]
def create_arc (archive, encoding, cmd, *args, **kwargs):
def create_arc (archive, compression, cmd, *args, **kwargs):
"""Create a ARC archive."""
cmdlist = [cmd, 'a', archive]
cmdlist.extend(args)

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the arj program."""
def extract_arj (archive, encoding, cmd, **kwargs):
def extract_arj (archive, compression, cmd, **kwargs):
"""Extract a ARJ archive."""
cmdlist = [cmd, 'x', '-r', '-y']
if not kwargs['verbose']:
@ -24,7 +24,7 @@ def extract_arj (archive, encoding, cmd, **kwargs):
return cmdlist
def list_arj (archive, encoding, cmd, **kwargs):
def list_arj (archive, compression, cmd, **kwargs):
"""List a ARJ archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -36,7 +36,7 @@ def list_arj (archive, encoding, cmd, **kwargs):
return cmdlist
def test_arj (archive, encoding, cmd, **kwargs):
def test_arj (archive, compression, cmd, **kwargs):
"""Test a ARJ archive."""
cmdlist = [cmd, 't']
if not kwargs['verbose']:
@ -45,7 +45,7 @@ def test_arj (archive, encoding, cmd, **kwargs):
return cmdlist
def create_arj (archive, encoding, cmd, *args, **kwargs):
def create_arj (archive, compression, cmd, *args, **kwargs):
"""Create a ARJ archive."""
cmdlist = [cmd, 'a', '-r', '-y']
if not kwargs['verbose']:

View File

@ -21,7 +21,7 @@ from patoolib.programs import extract_singlefile_standard, \
extract_bzip2 = extract_singlefile_standard
test_bzip2 = test_singlefile_standard
def create_bzip2 (archive, encoding, cmd, *args, **kwargs):
def create_bzip2 (archive, compression, cmd, *args, **kwargs):
"""Create a BZIP2 archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the cabextract program."""
def extract_cab (archive, encoding, cmd, **kwargs):
def extract_cab (archive, compression, cmd, **kwargs):
"""Extract a CAB archive."""
cmdlist = [cmd, '-d', kwargs['outdir']]
if kwargs['verbose']:
@ -23,7 +23,7 @@ def extract_cab (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def list_cab (archive, encoding, cmd, **kwargs):
def list_cab (archive, compression, cmd, **kwargs):
"""List a CAB archive."""
cmdlist = [cmd, '-l']
if kwargs['verbose']:
@ -31,6 +31,6 @@ def list_cab (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def test_cab (archive, encoding, cmd, **kwargs):
def test_cab (archive, compression, cmd, **kwargs):
"""Test a CAB archive."""
return [cmd, '-t', archive]

View File

@ -17,7 +17,7 @@
from patoolib import util
def create_compress (archive, encoding, cmd, *args, **kwargs):
def create_compress (archive, compression, cmd, *args, **kwargs):
"""Create a compressed archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:

View File

@ -17,7 +17,7 @@
import os
from patoolib import util
def extract_cpio (archive, encoding, cmd, **kwargs):
def extract_cpio (archive, compression, cmd, **kwargs):
"""Extract a CPIO archive."""
cmdlist = [util.shell_quote(cmd), '--extract', '--make-directories',
'--preserve-modification-time', '--no-absolute-filenames',
@ -28,7 +28,7 @@ def extract_cpio (archive, encoding, cmd, **kwargs):
return (cmdlist, {'cwd': kwargs['outdir'], 'shell': True})
def list_cpio (archive, encoding, cmd, **kwargs):
def list_cpio (archive, compression, cmd, **kwargs):
"""List a CPIO archive."""
cmdlist = [cmd, '-t']
if kwargs['verbose']:
@ -38,7 +38,7 @@ def list_cpio (archive, encoding, cmd, **kwargs):
test_cpio = list_cpio
def create_cpio(archive, encoding, cmd, *args, **kwargs):
def create_cpio(archive, compression, cmd, *args, **kwargs):
"""Create a CPIO archive."""
cmdlist = [util.shell_quote(cmd), '--create']
if kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the dpkg-deb program."""
def extract_deb (archive, encoding, cmd, **kwargs):
def extract_deb (archive, compression, cmd, **kwargs):
"""Extract a DEB archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -25,7 +25,7 @@ def extract_deb (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive, kwargs['outdir']])
return cmdlist
def list_deb (archive, encoding, cmd, **kwargs):
def list_deb (archive, compression, cmd, **kwargs):
"""List a DEB archive."""
return [cmd, '--contents', '--', archive]

View File

@ -18,31 +18,31 @@ statement."""
from patoolib import util
def list_bzip2 (archive, encoding, cmd, **kwargs):
def list_bzip2 (archive, compression, cmd, **kwargs):
"""List a BZIP2 archive."""
return stripext(cmd, archive)
def list_compress (archive, encoding, cmd, **kwargs):
def list_compress (archive, compression, cmd, **kwargs):
"""List a compress archive."""
return stripext(cmd, archive)
def list_lzma (archive, encoding, cmd, **kwargs):
def list_lzma (archive, compression, cmd, **kwargs):
"""List a LZMA archive."""
return stripext(cmd, archive)
def list_xz (archive, encoding, cmd, **kwargs):
def list_xz (archive, compression, cmd, **kwargs):
"""List a XZ archive."""
return stripext(cmd, archive)
def list_lzip (archive, encoding, cmd, **kwargs):
def list_lzip (archive, compression, cmd, **kwargs):
"""List a LZIP archive."""
return stripext(cmd, archive)
def list_lrzip (archive, encoding, cmd, **kwargs):
def list_lrzip (archive, compression, cmd, **kwargs):
"""List a LRZIP archive."""
return stripext(cmd, archive)
def list_rzip (archive, encoding, cmd, **kwargs):
def list_rzip (archive, compression, cmd, **kwargs):
"""List a RZIP archive."""
return stripext(cmd, archive)

View File

@ -21,7 +21,7 @@ extract_gzip = extract_compress = extract_singlefile_standard
test_gzip = test_compress = test_singlefile_standard
create_gzip = create_singlefile_standard
def list_gzip (archive, encoding, cmd, **kwargs):
def list_gzip (archive, compression, cmd, **kwargs):
"""List a GZIP archive."""
cmdlist = [cmd]
if kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the lha program."""
def extract_lzh (archive, encoding, cmd, **kwargs):
def extract_lzh (archive, compression, cmd, **kwargs):
"""Extract a LZH archive."""
opts = 'x'
if kwargs['verbose']:
@ -23,7 +23,7 @@ def extract_lzh (archive, encoding, cmd, **kwargs):
opts += "w=%s" % kwargs['outdir']
return [cmd, opts, archive]
def list_lzh (archive, encoding, cmd, **kwargs):
def list_lzh (archive, compression, cmd, **kwargs):
"""List a LZH archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -33,14 +33,14 @@ def list_lzh (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def test_lzh (archive, encoding, cmd, **kwargs):
def test_lzh (archive, compression, cmd, **kwargs):
"""Test a LZH archive."""
opts = 't'
if kwargs['verbose']:
opts += 'v'
return [cmd, opts, archive]
def create_lzh (archive, encoding, cmd, *args, **kwargs):
def create_lzh (archive, compression, cmd, *args, **kwargs):
"""Create a LZH archive."""
opts = 'a'
if kwargs['verbose']:

View File

@ -17,7 +17,7 @@
import os
from patoolib import util
def extract_lrzip (archive, encoding, cmd, **kwargs):
def extract_lrzip (archive, compression, cmd, **kwargs):
"""Extract a LRZIP archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
@ -28,7 +28,7 @@ def extract_lrzip (archive, encoding, cmd, **kwargs):
cmdlist.extend(["-o", outfile, os.path.abspath(archive)])
return (cmdlist, {'cwd': kwargs['outdir']})
def test_lrzip (archive, encoding, cmd, **kwargs):
def test_lrzip (archive, compression, cmd, **kwargs):
"""Test a LRZIP archive."""
cmdlist = [cmd, '-t']
if kwargs['verbose']:
@ -36,7 +36,7 @@ def test_lrzip (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def create_lrzip (archive, encoding, cmd, *args, **kwargs):
def create_lrzip (archive, compression, cmd, *args, **kwargs):
"""Create a LRZIP archive."""
cmdlist = [cmd, '-o', archive]
if kwargs['verbose']:

View File

@ -20,7 +20,7 @@ from patoolib.programs import extract_singlefile_standard
extract_lzop = extract_singlefile_standard
def list_lzop (archive, encoding, cmd, **kwargs):
def list_lzop (archive, compression, cmd, **kwargs):
"""List a LZOP archive."""
cmdlist = [cmd, '--list']
if kwargs['verbose']:
@ -28,7 +28,7 @@ def list_lzop (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive])
return cmdlist
def test_lzop (archive, encoding, cmd, **kwargs):
def test_lzop (archive, compression, cmd, **kwargs):
"""Test a LZOP archive."""
cmdlist = [cmd, '--test']
if kwargs['verbose']:
@ -36,7 +36,7 @@ def test_lzop (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive])
return cmdlist
def create_lzop (archive, encoding, cmd, *args, **kwargs):
def create_lzop (archive, compression, cmd, *args, **kwargs):
"""Create a LZOP archive."""
cmdlist = [cmd]
if kwargs['verbose']:

View File

@ -16,14 +16,14 @@
"""Archive commands for the nomarch program."""
import os
def extract_arc (archive, encoding, cmd, **kwargs):
def extract_arc (archive, compression, cmd, **kwargs):
"""Extract a ARC archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
cmdlist = [cmd, os.path.abspath(archive)]
return (cmdlist, {'cwd': kwargs['outdir']})
def list_arc (archive, encoding, cmd, **kwargs):
def list_arc (archive, compression, cmd, **kwargs):
"""List a ARC archive."""
cmdlist = [cmd, '-l']
if kwargs['verbose']:
@ -31,6 +31,6 @@ def list_arc (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def test_arc (archive, encoding, cmd, **kwargs):
def test_arc (archive, compression, cmd, **kwargs):
"""Test a ARC archive."""
return [cmd, '-t', archive]

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the orange program."""
def extract_cab (archive, encoding, cmd, **kwargs):
def extract_cab (archive, compression, cmd, **kwargs):
"""Extract a CAB archive."""
cmdlist = [cmd, '-d', kwargs['outdir']]
if kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the 7z program."""
def extract_7z (archive, encoding, cmd, **kwargs):
def extract_7z (archive, compression, cmd, **kwargs):
"""Extract a 7z archive."""
cmdlist = [cmd, 'x']
if not kwargs['verbose']:
@ -35,7 +35,7 @@ extract_bzip2 = \
extract_deb = \
extract_7z
def list_7z (archive, encoding, cmd, **kwargs):
def list_7z (archive, compression, cmd, **kwargs):
"""List a 7z archive."""
cmdlist = [cmd, 'l']
if not kwargs['verbose']:
@ -57,7 +57,7 @@ list_bzip2 = \
list_7z
def test_7z (archive, encoding, cmd, **kwargs):
def test_7z (archive, compression, cmd, **kwargs):
"""Test a 7z archive."""
cmdlist = [cmd, 't']
if not kwargs['verbose']:
@ -79,7 +79,7 @@ test_bzip2 = \
test_7z
def create_7z (archive, encoding, cmd, *args, **kwargs):
def create_7z (archive, compression, cmd, *args, **kwargs):
"""Create a 7z archive."""
cmdlist = [cmd, 'a']
if not kwargs['verbose']:

View File

@ -23,7 +23,7 @@ except ImportError:
READ_SIZE_BYTES = 1024*1024
def extract_bzip2 (archive, encoding, cmd, **kwargs):
def extract_bzip2 (archive, compression, cmd, **kwargs):
"""Extract a BZIP2 archive with the bz2 Python module."""
verbose = kwargs['verbose']
outdir = kwargs['outdir']
@ -48,7 +48,7 @@ def extract_bzip2 (archive, encoding, cmd, **kwargs):
return None
def create_bzip2 (archive, encoding, cmd, *args, **kwargs):
def create_bzip2 (archive, compression, cmd, *args, **kwargs):
"""Create a BZIP2 archive with the bz2 Python module."""
verbose = kwargs['verbose']
if verbose:

View File

@ -21,7 +21,7 @@ from patoolib import util
READ_SIZE_BYTES = 1024*1024
def extract_gzip (archive, encoding, cmd, **kwargs):
def extract_gzip (archive, compression, cmd, **kwargs):
"""Extract a GZIP archive with the gzip Python module."""
verbose = kwargs['verbose']
outdir = kwargs['outdir']
@ -46,7 +46,7 @@ def extract_gzip (archive, encoding, cmd, **kwargs):
return None
def create_gzip (archive, encoding, cmd, *args, **kwargs):
def create_gzip (archive, compression, cmd, *args, **kwargs):
"""Create a GZIP archive with the gzip Python module."""
verbose = kwargs['verbose']
if verbose:

View File

@ -20,7 +20,7 @@ import tarfile
READ_SIZE_BYTES = 1024*1024
def list_tar (archive, encoding, cmd, **kwargs):
def list_tar (archive, compression, cmd, **kwargs):
"""List a TAR archive with the tarfile Python module."""
verbose = kwargs['verbose']
if verbose:
@ -34,7 +34,7 @@ def list_tar (archive, encoding, cmd, **kwargs):
test_tar = list_tar
def extract_tar (archive, encoding, cmd, **kwargs):
def extract_tar (archive, compression, cmd, **kwargs):
"""Extract a TAR archive with the tarfile Python module."""
verbose = kwargs['verbose']
outdir = kwargs['outdir']
@ -51,12 +51,12 @@ def extract_tar (archive, encoding, cmd, **kwargs):
return None
def create_tar (archive, encoding, cmd, *args, **kwargs):
def create_tar (archive, compression, cmd, *args, **kwargs):
"""Create a TAR archive with the tarfile Python module."""
verbose = kwargs['verbose']
if verbose:
util.log_info('creating %s...' % archive)
mode = get_tar_mode(encoding)
mode = get_tar_mode(compression)
tfile = tarfile.open(archive, mode)
try:
for filename in args:

View File

@ -20,7 +20,7 @@ import zipfile
READ_SIZE_BYTES = 1024*1024
def list_zip (archive, encoding, cmd, **kwargs):
def list_zip (archive, compression, cmd, **kwargs):
"""List member of a ZIP archive with the zipfile Python module."""
verbose = kwargs['verbose']
if verbose:
@ -35,7 +35,7 @@ def list_zip (archive, encoding, cmd, **kwargs):
test_zip = list_zip
def extract_zip (archive, encoding, cmd, **kwargs):
def extract_zip (archive, compression, cmd, **kwargs):
"""Extract a ZIP archive with the zipfile Python module."""
verbose = kwargs['verbose']
outdir = kwargs['outdir']
@ -52,7 +52,7 @@ def extract_zip (archive, encoding, cmd, **kwargs):
return None
def create_zip (archive, encoding, cmd, *args, **kwargs):
def create_zip (archive, compression, cmd, *args, **kwargs):
"""Create a ZIP archive with the zipfile Python module."""
verbose = kwargs['verbose']
if verbose:

View File

@ -16,7 +16,7 @@
"""Archive commands for the rar program."""
import os
def extract_rar (archive, encoding, cmd, **kwargs):
def extract_rar (archive, compression, cmd, **kwargs):
"""Extract a RAR archive."""
cmdlist = [cmd, 'x']
if not kwargs['verbose']:
@ -24,7 +24,7 @@ def extract_rar (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', os.path.abspath(archive)])
return (cmdlist, {'cwd': kwargs['outdir']})
def list_rar (archive, encoding, cmd, **kwargs):
def list_rar (archive, compression, cmd, **kwargs):
"""List a RAR archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -35,7 +35,7 @@ def list_rar (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive])
return cmdlist
def test_rar (archive, encoding, cmd, **kwargs):
def test_rar (archive, compression, cmd, **kwargs):
"""Test a RAR archive."""
cmdlist = [cmd, 't']
if not kwargs['verbose']:
@ -43,7 +43,7 @@ def test_rar (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive])
return cmdlist
def create_rar (archive, encoding, cmd, *args, **kwargs):
def create_rar (archive, compression, cmd, *args, **kwargs):
"""Create a RAR archive."""
cmdlist = [cmd, 'a']
if not kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the rpm program."""
def list_rpm (archive, encoding, cmd, **kwargs):
def list_rpm (archive, compression, cmd, **kwargs):
"""List a RPM archive."""
cmdlist = [cmd, '-q', '-l']
if kwargs['verbose']:
@ -23,7 +23,7 @@ def list_rpm (archive, encoding, cmd, **kwargs):
cmdlist.extend(['-p', '--', archive])
return cmdlist
def test_rpm (archive, encoding, cmd, **kwargs):
def test_rpm (archive, compression, cmd, **kwargs):
"""Test a RPM archive."""
cmdlist = [cmd, 'V']
if kwargs['verbose']:

View File

@ -17,7 +17,7 @@
import os
from patoolib import util
def extract_rpm (archive, encoding, cmd, **kwargs):
def extract_rpm (archive, compression, cmd, **kwargs):
"""Extract a RPM archive."""
# also check cpio
cpio = util.find_program("cpio")

View File

@ -17,7 +17,7 @@
import os
from patoolib import util
def extract_rzip (archive, encoding, cmd, **kwargs):
def extract_rzip (archive, compression, cmd, **kwargs):
"""Extract a RZIP archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
@ -28,7 +28,7 @@ def extract_rzip (archive, encoding, cmd, **kwargs):
cmdlist.extend(["-o", outfile, os.path.abspath(archive)])
return (cmdlist, {'cwd': kwargs['outdir']})
def create_rzip (archive, encoding, cmd, *args, **kwargs):
def create_rzip (archive, compression, cmd, *args, **kwargs):
"""Create a RZIP archive."""
cmdlist = [cmd, '-k', '-o', archive]
if kwargs['verbose']:

View File

@ -15,42 +15,42 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the star program."""
def extract_tar (archive, encoding, cmd, **kwargs):
def extract_tar (archive, compression, cmd, **kwargs):
"""Extract a TAR archive."""
cmdlist = [cmd, '-x']
add_star_opts(cmdlist, encoding, kwargs['verbose'])
add_star_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.extend(['-C', kwargs['outdir'], 'file=%s' % archive])
return cmdlist
def list_tar (archive, encoding, cmd, **kwargs):
def list_tar (archive, compression, cmd, **kwargs):
"""List a TAR archive."""
cmdlist = [cmd, '-n']
add_star_opts(cmdlist, encoding, kwargs['verbose'])
add_star_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.append("file=%s" % archive)
return cmdlist
test_tar = list_tar
def create_tar (archive, encoding, cmd, *args, **kwargs):
def create_tar (archive, compression, cmd, *args, **kwargs):
"""Create a TAR archive."""
cmdlist = [cmd, '-c']
add_star_opts(cmdlist, encoding, kwargs['verbose'])
add_star_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.append("file=%s" % archive)
cmdlist.extend(args)
return cmdlist
def add_star_opts (cmdlist, encoding, verbose):
def add_star_opts (cmdlist, compression, verbose):
"""Add default options for the star program."""
# Note that star autodetects encoding compression, but displays a warning
# Note that star autodetects compression compression, but displays a warning
# which we want to avoid.
if encoding == 'gzip':
if compression == 'gzip':
cmdlist.append('-z')
elif encoding == 'compress':
elif compression == 'compress':
cmdlist.append('-Z')
elif encoding == 'bzip2':
elif compression == 'bzip2':
cmdlist.append('-bz')
elif encoding in ('lzma', 'xz', 'lzip'):
elif compression in ('lzma', 'xz', 'lzip'):
# use compress-program option
cmdlist.append('compress-program=%s' % encoding)
cmdlist.append('compress-program=%s' % compression)
if verbose:
cmdlist.append('-v')

View File

@ -15,35 +15,35 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the GNU tar program."""
def extract_tar (archive, encoding, cmd, **kwargs):
def extract_tar (archive, compression, cmd, **kwargs):
"""Extract a TAR archive."""
cmdlist = [cmd, '--extract']
add_tar_opts(cmdlist, encoding, kwargs['verbose'])
add_tar_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.extend(["--file", archive, '--directory', kwargs['outdir']])
return cmdlist
def list_tar (archive, encoding, cmd, **kwargs):
def list_tar (archive, compression, cmd, **kwargs):
"""List a TAR archive."""
cmdlist = [cmd, '--list']
add_tar_opts(cmdlist, encoding, kwargs['verbose'])
add_tar_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.extend(["--file", archive])
return cmdlist
test_tar = list_tar
def create_tar (archive, encoding, cmd, *args, **kwargs):
def create_tar (archive, compression, cmd, *args, **kwargs):
"""Create a TAR archive."""
cmdlist = [cmd, '--create']
add_tar_opts(cmdlist, encoding, kwargs['verbose'])
add_tar_opts(cmdlist, compression, kwargs['verbose'])
cmdlist.extend(["--file", archive, '--'])
cmdlist.extend(args)
return cmdlist
def add_tar_opts (cmdlist, encoding, verbose):
if encoding == 'lzip':
def add_tar_opts (cmdlist, compression, verbose):
if compression == 'lzip':
# use compress-program option
cmdlist.extend(['--use-compress-program', encoding])
elif encoding:
cmdlist.append('--%s' % encoding)
cmdlist.extend(['--use-compress-program', compression])
elif compression:
cmdlist.append('--%s' % compression)
if verbose:
cmdlist.append('--verbose')

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the unace program."""
def extract_ace (archive, encoding, cmd, **kwargs):
def extract_ace (archive, compression, cmd, **kwargs):
"""Extract a ACE archive."""
cmdlist = [cmd, 'x']
if not kwargs['verbose']:
@ -23,7 +23,7 @@ def extract_ace (archive, encoding, cmd, **kwargs):
cmdlist.extend([archive, kwargs['outdir']])
return cmdlist
def list_ace (archive, encoding, cmd, **kwargs):
def list_ace (archive, compression, cmd, **kwargs):
"""List a ACE archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -34,7 +34,7 @@ def list_ace (archive, encoding, cmd, **kwargs):
cmdlist.append(archive)
return cmdlist
def test_ace (archive, encoding, cmd, **kwargs):
def test_ace (archive, compression, cmd, **kwargs):
"""Test a ACE archive."""
cmdlist = [cmd, 't']
if not kwargs['verbose']:

View File

@ -15,12 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the unalz program."""
def extract_alzip (archive, encoding, cmd, **kwargs):
def extract_alzip (archive, compression, cmd, **kwargs):
"""Extract a ALZIP archive."""
return [cmd, '-d', kwargs['outdir'], archive]
def list_alzip (archive, encoding, cmd, **kwargs):
def list_alzip (archive, compression, cmd, **kwargs):
"""List a ALZIP archive."""
return [cmd, '-l', archive]

View File

@ -17,7 +17,7 @@
from patoolib import util
def extract_compress (archive, encoding, cmd, **kwargs):
def extract_compress (archive, compression, cmd, **kwargs):
"""Extract a compressed archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the unzip program."""
def extract_zip (archive, encoding, cmd, **kwargs):
def extract_zip (archive, compression, cmd, **kwargs):
"""Extract a ZIP archive."""
cmdlist = [cmd]
if kwargs['verbose']:
@ -23,7 +23,7 @@ def extract_zip (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive, '-d', kwargs['outdir']])
return cmdlist
def list_zip (archive, encoding, cmd, **kwargs):
def list_zip (archive, compression, cmd, **kwargs):
"""List a ZIP archive."""
cmdlist = [cmd, '-l']
if kwargs['verbose']:
@ -31,7 +31,7 @@ def list_zip (archive, encoding, cmd, **kwargs):
cmdlist.extend(['--', archive])
return cmdlist
def test_zip (archive, encoding, cmd, **kwargs):
def test_zip (archive, compression, cmd, **kwargs):
"""Test a ZIP archive."""
cmdlist = [cmd, '-t']
if kwargs['verbose']:

View File

@ -17,7 +17,7 @@
from patoolib import util
def extract_dms (archive, encoding, cmd, **kwargs):
def extract_dms (archive, compression, cmd, **kwargs):
"""Extract a DMS archive."""
check_archive_ext(archive)
cmdlist = [cmd, '-d', kwargs['outdir']]
@ -27,13 +27,13 @@ def extract_dms (archive, encoding, cmd, **kwargs):
return cmdlist
def list_dms (archive, encoding, cmd, **kwargs):
def list_dms (archive, compression, cmd, **kwargs):
"""List a DMS archive."""
check_archive_ext(archive)
return [cmd, 'v', archive]
def test_dms (archive, encoding, cmd, **kwargs):
def test_dms (archive, compression, cmd, **kwargs):
"""Test a DMS archive."""
check_archive_ext(archive)
return [cmd, 't', archive]

View File

@ -22,7 +22,7 @@ extract_xz = extract_singlefile_standard
test_xz = test_singlefile_standard
create_xz = create_singlefile_standard
def list_xz (archive, encoding, cmd, **kwargs):
def list_xz (archive, compression, cmd, **kwargs):
"""List a XZ archive."""
cmdlist = [cmd]
cmdlist.append('-l')

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the zip program."""
def create_zip (archive, encoding, cmd, *args, **kwargs):
def create_zip (archive, compression, cmd, *args, **kwargs):
"""Create a ZIP archive."""
cmdlist = [cmd, '-r']
if kwargs['verbose']:

View File

@ -16,7 +16,7 @@
"""Archive commands for the zoo program."""
import os
def extract_zoo (archive, encoding, cmd, **kwargs):
def extract_zoo (archive, compression, cmd, **kwargs):
"""Extract a ZOO archive."""
# Since extracted files will be placed in the current directory,
# the cwd argument has to be the output directory.
@ -24,17 +24,17 @@ def extract_zoo (archive, encoding, cmd, **kwargs):
return (cmdlist, {'cwd': kwargs['outdir']})
def list_zoo (archive, encoding, cmd, **kwargs):
def list_zoo (archive, compression, cmd, **kwargs):
"""List a ZOO archive."""
return [cmd, '-list', archive]
def test_zoo (archive, encoding, cmd, **kwargs):
def test_zoo (archive, compression, cmd, **kwargs):
"""Test a ZOO archive."""
return [cmd, '-test', archive]
def create_zoo (archive, encoding, cmd, *args, **kwargs):
def create_zoo (archive, compression, cmd, *args, **kwargs):
"""Create a ZOO archive."""
cmdlist = [cmd, '-add', archive]
cmdlist.extend(args)

View File

@ -143,8 +143,8 @@ def guess_mime_mimedb (filename):
@return: tuple (mime, encoding)
"""
mime, encoding = mimedb.guess_type(filename, strict=False)
from patoolib import ArchiveMimetypes, ArchiveEncodings
if mime not in ArchiveMimetypes and encoding in ArchiveEncodings:
from patoolib import ArchiveMimetypes, ArchiveCompressions
if mime not in ArchiveMimetypes and encoding in ArchiveCompressions:
# Files like 't.txt.gz' are recognized with encoding as format, and
# an unsupported mime-type like 'text/plain'. Fix this.
mime = Encoding2Mime[encoding]

View File

@ -174,4 +174,4 @@ def has_codec (program, codec):
"""Test if program supports given codec."""
if program == '7z' and codec == 'rar':
return patoolib.util.p7zip_supports_rar()
return patoolib.find_encoding_program(program, codec)
return patoolib.find_compression_program(program, codec)

View File

@ -32,12 +32,12 @@ class TestConfiguration (unittest.TestCase):
if command is not None:
self.assertTrue(command in patoolib.ArchiveCommands)
def test_encoding_programs (self):
self.assertEqual(set(patoolib.ArchiveEncodings),
set(patoolib.EncodingPrograms.keys()))
def test_compression_programs (self):
self.assertEqual(set(patoolib.ArchiveCompressions),
set(patoolib.CompressionPrograms.keys()))
def test_encoding_mimes (self):
self.assertEqual(set(patoolib.ArchiveEncodings),
self.assertEqual(set(patoolib.ArchiveCompressions),
set(patoolib.util.Encoding2Mime.keys()))
for mime in patoolib.util.Encoding2Mime.values():
self.assertTrue(mime in patoolib.ArchiveMimetypes)