mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-13 10:22:55 +01: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 gzip
|
||||
import tarfile
|
||||
|
||||
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)
|
||||
tar.add(path, path_in_tar)
|
||||
compression = TARGZ_DEFAULT_COMPRESSION_LEVEL
|
||||
tar = tarfile.TarFile.gzopen(tarball_path, 'w', compresslevel=compression)
|
||||
try:
|
||||
with closing(tarfile.TarFile.open(tarball_path, 'w:gz',
|
||||
compresslevel=compression)) as tar:
|
||||
for source in sources:
|
||||
source_path = source
|
||||
if os.path.isdir(source):
|
||||
@ -38,16 +38,9 @@ def make_tarball(tarball_path, sources, base_dir, prefix_dir=''):
|
||||
else:
|
||||
path_in_tar = archive_name(source_path)
|
||||
tar.add(source_path, path_in_tar) # filename, arcname
|
||||
finally:
|
||||
tar.close()
|
||||
|
||||
def decompress(tarball_path, base_dir):
|
||||
"""Decompress the gzipped tarball into directory base_dir.
|
||||
"""
|
||||
# !!! This class method is not documented in the online doc
|
||||
# nor is bz2open!
|
||||
tar = tarfile.TarFile.gzopen(tarball_path, mode='r')
|
||||
try:
|
||||
with closing(tarfile.TarFile.open(tarball_path)) as tar:
|
||||
tar.extractall(base_dir)
|
||||
finally:
|
||||
tar.close()
|
||||
|
Loading…
Reference in New Issue
Block a user