Support tarfile to work with python2.6

Change-Id: If39ac9473742ed67a623b81716e8ece7fe98dc9f
This commit is contained in:
Ekaterina Fedorova
2013-11-07 14:04:57 +04:00
parent ccff0e7fd4
commit b8c433b2c1
2 changed files with 9 additions and 3 deletions

View File

@@ -77,7 +77,7 @@ def upload_file(data_type):
@v1_api.route('/admin/<data_type>/<path:path>')
def _get_locations_in_nested_path_or_get_file(data_type, path):
def get_locations_in_nested_path_or_get_file(data_type, path):
api.check_data_type(data_type)
result_path = api.compose_path(data_type, path)
if os.path.isfile(result_path):

View File

@@ -88,9 +88,12 @@ class Archiver(object):
return None
def _compose_archive(self, arch_name, path, hash=False, cache_dir=None):
with tarfile.open(arch_name, 'w:gz') as tar:
tar = tarfile.open(arch_name, 'w:gz')
try:
for item in os.listdir(path):
tar.add(os.path.join(path, item), item)
finally:
tar.close()
try:
shutil.rmtree(path, ignore_errors=True)
except Exception as e:
@@ -219,8 +222,11 @@ class Archiver(object):
"""
try:
path_to_extract = tempfile.mkdtemp()
with tarfile.open(path_to_archive) as archive:
archive = tarfile.open(path_to_archive)
try:
archive.extractall(path_to_extract)
finally:
archive.close()
# assert manifest file
manifests = glob.glob(os.path.join(path_to_extract,
'*-manifest.yaml'))