Merged revisions 80282 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80282 | tarek.ziade | 2010-04-20 23:09:06 +0200 (Tue, 20 Apr 2010) | 1 line removed ztar support in shutil.make_archive ........
This commit is contained in:
parent
33798fde76
commit
5e2be8737d
|
@ -237,7 +237,7 @@ Archives operations
|
||||||
|
|
||||||
*base_name* is the name of the file to create, including the path, minus
|
*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
|
any format-specific extension. *format* is the archive format: one of
|
||||||
"zip", "tar", "ztar", "bztar" or "gztar".
|
"zip", "tar", "bztar" or "gztar".
|
||||||
|
|
||||||
*root_dir* is a directory that will be the root directory of the
|
*root_dir* is a directory that will be the root directory of the
|
||||||
archive; i.e. we typically chdir into *root_dir* before creating the
|
archive; i.e. we typically chdir into *root_dir* before creating the
|
||||||
|
@ -264,7 +264,6 @@ Archives operations
|
||||||
|
|
||||||
- *gztar*: gzip'ed tar-file
|
- *gztar*: gzip'ed tar-file
|
||||||
- *bztar*: bzip2'ed tar-file
|
- *bztar*: bzip2'ed tar-file
|
||||||
- *ztar*: compressed tar file
|
|
||||||
- *tar*: uncompressed tar file
|
- *tar*: uncompressed tar file
|
||||||
- *zip*: ZIP file
|
- *zip*: ZIP file
|
||||||
|
|
||||||
|
|
|
@ -355,31 +355,28 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
|
||||||
"""Create a (possibly compressed) tar file from all the files under
|
"""Create a (possibly compressed) tar file from all the files under
|
||||||
'base_dir'.
|
'base_dir'.
|
||||||
|
|
||||||
'compress' must be "gzip" (the default), "compress", "bzip2", or None.
|
'compress' must be "gzip" (the default), "bzip2", or None.
|
||||||
(compress will be deprecated in Python 3.2)
|
|
||||||
|
|
||||||
'owner' and 'group' can be used to define an owner and a group for the
|
'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
|
archive that is being built. If not provided, the current owner and group
|
||||||
will be used.
|
will be used.
|
||||||
|
|
||||||
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
||||||
the appropriate compression extension (".gz", ".bz2" or ".Z").
|
the appropriate compression extension (".gz", or ".bz2").
|
||||||
|
|
||||||
Returns the output filename.
|
Returns the output filename.
|
||||||
"""
|
"""
|
||||||
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: '', 'compress': ''}
|
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: ''}
|
||||||
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'compress': '.Z'}
|
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2'}
|
||||||
|
|
||||||
# flags for compression program, each element of list will be an argument
|
# flags for compression program, each element of list will be an argument
|
||||||
if compress is not None and compress not in compress_ext.keys():
|
if compress is not None and compress not in compress_ext.keys():
|
||||||
raise ValueError("bad value for 'compress': must be None, 'gzip', "
|
raise ValueError("bad value for 'compress': must be None, 'gzip', or "
|
||||||
"'bzip2' or 'compress'")
|
"'bzip2'")
|
||||||
|
|
||||||
archive_name = base_name + '.tar'
|
|
||||||
if compress != 'compress':
|
|
||||||
archive_name += compress_ext.get(compress, '')
|
|
||||||
|
|
||||||
|
archive_name = base_name + '.tar' + compress_ext.get(compress, '')
|
||||||
archive_dir = os.path.dirname(archive_name)
|
archive_dir = os.path.dirname(archive_name)
|
||||||
|
|
||||||
if not os.path.exists(archive_dir):
|
if not os.path.exists(archive_dir):
|
||||||
logger.info("creating %s" % archive_dir)
|
logger.info("creating %s" % archive_dir)
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
|
@ -411,20 +408,6 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
|
||||||
finally:
|
finally:
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
# compression using `compress`
|
|
||||||
# XXX this block will be removed in Python 3.2
|
|
||||||
if compress == 'compress':
|
|
||||||
warn("'compress' will be deprecated.", PendingDeprecationWarning)
|
|
||||||
# the option varies depending on the platform
|
|
||||||
compressed_name = archive_name + compress_ext[compress]
|
|
||||||
if sys.platform == 'win32':
|
|
||||||
cmd = [compress, archive_name, compressed_name]
|
|
||||||
else:
|
|
||||||
cmd = [compress, '-f', archive_name]
|
|
||||||
from distutils.spawn import spawn
|
|
||||||
spawn(cmd, dry_run=dry_run)
|
|
||||||
return compressed_name
|
|
||||||
|
|
||||||
return archive_name
|
return archive_name
|
||||||
|
|
||||||
def _call_external_zip(directory, verbose=False):
|
def _call_external_zip(directory, verbose=False):
|
||||||
|
@ -494,8 +477,6 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
|
||||||
_ARCHIVE_FORMATS = {
|
_ARCHIVE_FORMATS = {
|
||||||
'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
||||||
'bztar': (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
'bztar': (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
||||||
'ztar': (_make_tarball, [('compress', 'compress')],
|
|
||||||
"compressed tar file"),
|
|
||||||
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
|
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
|
||||||
'zip': (_make_zipfile, [],"ZIP file")
|
'zip': (_make_zipfile, [],"ZIP file")
|
||||||
}
|
}
|
||||||
|
@ -539,8 +520,8 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
|
||||||
"""Create an archive file (eg. zip or tar).
|
"""Create an archive file (eg. zip or tar).
|
||||||
|
|
||||||
'base_name' is the name of the file to create, minus any format-specific
|
'base_name' is the name of the file to create, minus any format-specific
|
||||||
extension; 'format' is the archive format: one of "zip", "tar", "ztar",
|
extension; 'format' is the archive format: one of "zip", "tar", "bztar"
|
||||||
"bztar" or "gztar".
|
or "gztar".
|
||||||
|
|
||||||
'root_dir' is a directory that will be the root directory of the
|
'root_dir' is a directory that will be the root directory of the
|
||||||
archive; ie. we typically chdir into 'root_dir' before creating the
|
archive; ie. we typically chdir into 'root_dir' before creating the
|
||||||
|
|
|
@ -487,36 +487,6 @@ class TestShutil(unittest.TestCase):
|
||||||
tarball = base_name + '.tar'
|
tarball = base_name + '.tar'
|
||||||
self.assertTrue(os.path.exists(tarball))
|
self.assertTrue(os.path.exists(tarball))
|
||||||
|
|
||||||
@unittest.skipUnless(find_executable('compress'),
|
|
||||||
'The compress program is required')
|
|
||||||
def test_compress_deprecated(self):
|
|
||||||
tmpdir, tmpdir2, base_name = self._create_files()
|
|
||||||
|
|
||||||
# using compress and testing the PendingDeprecationWarning
|
|
||||||
old_dir = os.getcwd()
|
|
||||||
os.chdir(tmpdir)
|
|
||||||
try:
|
|
||||||
with captured_stdout() as s, check_warnings(quiet=False) as w:
|
|
||||||
_make_tarball(base_name, 'dist', compress='compress')
|
|
||||||
finally:
|
|
||||||
os.chdir(old_dir)
|
|
||||||
tarball = base_name + '.tar.Z'
|
|
||||||
self.assertTrue(os.path.exists(tarball))
|
|
||||||
self.assertEqual(len(w.warnings), 1)
|
|
||||||
|
|
||||||
# same test with dry_run
|
|
||||||
os.remove(tarball)
|
|
||||||
old_dir = os.getcwd()
|
|
||||||
os.chdir(tmpdir)
|
|
||||||
try:
|
|
||||||
with captured_stdout() as s, check_warnings(quiet=False) as w:
|
|
||||||
_make_tarball(base_name, 'dist', compress='compress',
|
|
||||||
dry_run=True)
|
|
||||||
finally:
|
|
||||||
os.chdir(old_dir)
|
|
||||||
self.assertFalse(os.path.exists(tarball))
|
|
||||||
self.assertEqual(len(w.warnings), 1)
|
|
||||||
|
|
||||||
@unittest.skipUnless(zlib, "Requires zlib")
|
@unittest.skipUnless(zlib, "Requires zlib")
|
||||||
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
|
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
|
||||||
def test_make_zipfile(self):
|
def test_make_zipfile(self):
|
||||||
|
|
Loading…
Reference in New Issue