cpython: e57db221b6c4 (original) (raw)

Mercurial > cpython

changeset 92025:e57db221b6c4

Issue #5411: Added support for the "xztar" format in the shutil module. [#5411]

Serhiy Storchaka storchaka@gmail.com
date Wed, 06 Aug 2014 18:50:19 +0300
parents 9244ed41057a
children a47996c10579
files Doc/library/shutil.rst Lib/shutil.py Lib/test/test_shutil.py Misc/NEWS
diffstat 4 files changed, 40 insertions(+), 5 deletions(-)[+] [-] Doc/library/shutil.rst 8 Lib/shutil.py 27 Lib/test/test_shutil.py 8 Misc/NEWS 2

line wrap: on

line diff

--- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -469,7 +469,8 @@ provided. They rely on the :mod:`zipfil base_name is the name of the file to create, including the path, minus any format-specific extension. format is the archive format: one of

.. function:: get_archive_formats() @@ -497,6 +501,7 @@ provided. They rely on the :mod:zipfil[](#l1.23) [](#l1.24) - *gztar*: gzip'ed tar-file[](#l1.25) - *bztar*: bzip2'ed tar-file (if the :mod:bz2` module is available.)

@@ -567,6 +572,7 @@ provided. They rely on the :mod:zipfil[](#l1.31) [](#l1.32) - *gztar*: gzip'ed tar-file[](#l1.33) - *bztar*: bzip2'ed tar-file (if the :mod:bz2` module is available.)

--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -21,6 +21,13 @@ except ImportError: _BZ2_SUPPORTED = False try:

+except ImportError:

+ +try: from pwd import getpwnam except ImportError: getpwnam = None @@ -580,14 +587,14 @@ def _make_tarball(base_name, base_dir, c """Create a (possibly compressed) tar file from all the files under 'base_dir'.

'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owner and group will be used. The output tar file will be named 'base_name' + ".tar", possibly plus

Returns the output filename. """ @@ -598,6 +605,10 @@ def _make_tarball(base_name, base_dir, c tar_compression['bzip2'] = 'bz2' compress_ext['bzip2'] = '.bz2'

+ # flags for compression program, each element of list will be an argument if compress is not None and compress not in compress_ext: raise ValueError("bad value for 'compress', or compression format not " @@ -684,6 +695,10 @@ if _BZ2_SUPPORTED: _ARCHIVE_FORMATS['bztar'] = (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file") +if _LZMA_SUPPORTED:

+ def get_archive_formats(): """Returns a list of supported formats for archiving and unarchiving. @@ -872,7 +887,7 @@ def _unpack_zipfile(filename, extract_di zip.close() def _unpack_tarfile(filename, extract_dir):

@@ -891,9 +906,13 @@ def _unpack_tarfile(filename, extract_di } if _BZ2_SUPPORTED:

+if _LZMA_SUPPORTED:

+ def _find_unpack_format(filename): for name, info in _UNPACK_FORMATS.items(): for extension in info[0]:

--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -32,6 +32,12 @@ try: except ImportError: BZ2_SUPPORTED = False +try:

+except ImportError:

+ TESTFN2 = TESTFN + "2" try: @@ -1156,6 +1162,8 @@ class TestShutil(unittest.TestCase): formats = ['tar', 'gztar', 'zip'] if BZ2_SUPPORTED: formats.append('bztar')

for format in formats: tmpdir = self.mkdtemp()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -112,6 +112,8 @@ Core and Builtins Library ------- +- Issue #5411: Added support for the "xztar" format in the shutil module. +