mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-13 10:31:23 +02:00
update TarFile usage
This commit is contained in:
parent
494950a63d
commit
9cc0bb80b2
@ -1,5 +1,5 @@
|
|||||||
|
from contextlib import closing
|
||||||
import os.path
|
import os.path
|
||||||
import gzip
|
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
TARGZ_DEFAULT_COMPRESSION_LEVEL = 9
|
TARGZ_DEFAULT_COMPRESSION_LEVEL = 9
|
||||||
@ -29,8 +29,8 @@ def make_tarball(tarball_path, sources, base_dir, prefix_dir=''):
|
|||||||
path_in_tar = archive_name(path)
|
path_in_tar = archive_name(path)
|
||||||
tar.add(path, path_in_tar)
|
tar.add(path, path_in_tar)
|
||||||
compression = TARGZ_DEFAULT_COMPRESSION_LEVEL
|
compression = TARGZ_DEFAULT_COMPRESSION_LEVEL
|
||||||
tar = tarfile.TarFile.gzopen(tarball_path, 'w', compresslevel=compression)
|
with closing(tarfile.TarFile.open(tarball_path, 'w:gz',
|
||||||
try:
|
compresslevel=compression)) as tar:
|
||||||
for source in sources:
|
for source in sources:
|
||||||
source_path = source
|
source_path = source
|
||||||
if os.path.isdir(source):
|
if os.path.isdir(source):
|
||||||
@ -38,16 +38,9 @@ def make_tarball(tarball_path, sources, base_dir, prefix_dir=''):
|
|||||||
else:
|
else:
|
||||||
path_in_tar = archive_name(source_path)
|
path_in_tar = archive_name(source_path)
|
||||||
tar.add(source_path, path_in_tar) # filename, arcname
|
tar.add(source_path, path_in_tar) # filename, arcname
|
||||||
finally:
|
|
||||||
tar.close()
|
|
||||||
|
|
||||||
def decompress(tarball_path, base_dir):
|
def decompress(tarball_path, base_dir):
|
||||||
"""Decompress the gzipped tarball into directory base_dir.
|
"""Decompress the gzipped tarball into directory base_dir.
|
||||||
"""
|
"""
|
||||||
# !!! This class method is not documented in the online doc
|
with closing(tarfile.TarFile.open(tarball_path)) as tar:
|
||||||
# nor is bz2open!
|
|
||||||
tar = tarfile.TarFile.gzopen(tarball_path, mode='r')
|
|
||||||
try:
|
|
||||||
tar.extractall(base_dir)
|
tar.extractall(base_dir)
|
||||||
finally:
|
|
||||||
tar.close()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user