Support creation of BZIP2 and GZIP files with Python modules.
This commit is contained in:
parent
8304658d4e
commit
a0669fd438
|
@ -102,7 +102,7 @@ ArchivePrograms = {
|
||||||
None: ('7z', '7za'),
|
None: ('7z', '7za'),
|
||||||
'extract': ('pbzip2', 'lbzip2', 'bzip2', 'pybz2'),
|
'extract': ('pbzip2', 'lbzip2', 'bzip2', 'pybz2'),
|
||||||
'test': ('pbzip2', 'lbzip2', 'bzip2'),
|
'test': ('pbzip2', 'lbzip2', 'bzip2'),
|
||||||
'create': ('pbzip2', 'lbzip2', 'bzip2'),
|
'create': ('pbzip2', 'lbzip2', 'bzip2', 'pybz2'),
|
||||||
'list': ('echo',),
|
'list': ('echo',),
|
||||||
},
|
},
|
||||||
'tar': {
|
'tar': {
|
||||||
|
@ -118,6 +118,7 @@ ArchivePrograms = {
|
||||||
'gzip': {
|
'gzip': {
|
||||||
None: ('pigz', 'gzip', '7z', '7za'),
|
None: ('pigz', 'gzip', '7z', '7za'),
|
||||||
'extract': ('pygzip',),
|
'extract': ('pygzip',),
|
||||||
|
'create': ('pygzip',),
|
||||||
},
|
},
|
||||||
'lzh': {
|
'lzh': {
|
||||||
None: ('lha',),
|
None: ('lha',),
|
||||||
|
|
|
@ -24,7 +24,7 @@ except ImportError:
|
||||||
READ_SIZE_BYTES = 1024*1024
|
READ_SIZE_BYTES = 1024*1024
|
||||||
|
|
||||||
def extract_bzip2 (archive, encoding, cmd, **kwargs):
|
def extract_bzip2 (archive, encoding, cmd, **kwargs):
|
||||||
"""Extract a BZIP2 archive with the bz2 Python module functionality."""
|
"""Extract a BZIP2 archive with the bz2 Python module."""
|
||||||
verbose = kwargs['verbose']
|
verbose = kwargs['verbose']
|
||||||
if verbose:
|
if verbose:
|
||||||
util.log_info('extracting %s...' % archive)
|
util.log_info('extracting %s...' % archive)
|
||||||
|
@ -44,3 +44,28 @@ def extract_bzip2 (archive, encoding, cmd, **kwargs):
|
||||||
if verbose:
|
if verbose:
|
||||||
util.log_info('... extracted to %s' % targetname)
|
util.log_info('... extracted to %s' % targetname)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def create_bzip2 (archive, encoding, cmd, *args, **kwargs):
|
||||||
|
"""Create a BZIP2 archive with the bz2 Python module."""
|
||||||
|
verbose = kwargs['verbose']
|
||||||
|
if verbose:
|
||||||
|
util.log_info('creating %s...' % archive)
|
||||||
|
if len(args) > 1:
|
||||||
|
util.log_error('multi-file compression not supported in Python bz2')
|
||||||
|
bz2file = bz2.BZ2File(archive, 'wb')
|
||||||
|
try:
|
||||||
|
filename = args[0]
|
||||||
|
srcfile = open(filename)
|
||||||
|
try:
|
||||||
|
data = srcfile.read(READ_SIZE_BYTES)
|
||||||
|
while data:
|
||||||
|
bz2file.write(data)
|
||||||
|
data = srcfile.read(READ_SIZE_BYTES)
|
||||||
|
if verbose:
|
||||||
|
util.log_info('... added %s' % filename)
|
||||||
|
finally:
|
||||||
|
srcfile.close()
|
||||||
|
finally:
|
||||||
|
bz2file.close()
|
||||||
|
return None
|
||||||
|
|
|
@ -22,7 +22,7 @@ from patoolib import util
|
||||||
READ_SIZE_BYTES = 1024*1024
|
READ_SIZE_BYTES = 1024*1024
|
||||||
|
|
||||||
def extract_gzip (archive, encoding, cmd, **kwargs):
|
def extract_gzip (archive, encoding, cmd, **kwargs):
|
||||||
"""Extract a GZIP archive with the gzip Python module functionality."""
|
"""Extract a GZIP archive with the gzip Python module."""
|
||||||
verbose = kwargs['verbose']
|
verbose = kwargs['verbose']
|
||||||
if verbose:
|
if verbose:
|
||||||
util.log_info('extracting %s...' % archive)
|
util.log_info('extracting %s...' % archive)
|
||||||
|
@ -42,3 +42,28 @@ def extract_gzip (archive, encoding, cmd, **kwargs):
|
||||||
if verbose:
|
if verbose:
|
||||||
util.log_info('... extracted to %s' % targetname)
|
util.log_info('... extracted to %s' % targetname)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def create_gzip (archive, encoding, cmd, *args, **kwargs):
|
||||||
|
"""Create a GZIP archive with the gzip Python module."""
|
||||||
|
verbose = kwargs['verbose']
|
||||||
|
if verbose:
|
||||||
|
util.log_info('creating %s...' % archive)
|
||||||
|
if len(args) > 1:
|
||||||
|
util.log_error('multi-file compression not supported in Python gzip')
|
||||||
|
gzipfile = gzip.GzipFile(archive, 'wb')
|
||||||
|
try:
|
||||||
|
filename = args[0]
|
||||||
|
srcfile = open(filename)
|
||||||
|
try:
|
||||||
|
data = srcfile.read(READ_SIZE_BYTES)
|
||||||
|
while data:
|
||||||
|
gzipfile.write(data)
|
||||||
|
data = srcfile.read(READ_SIZE_BYTES)
|
||||||
|
if verbose:
|
||||||
|
util.log_info('... added %s' % filename)
|
||||||
|
finally:
|
||||||
|
srcfile.close()
|
||||||
|
finally:
|
||||||
|
gzipfile.close()
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in New Issue