mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 12:21:35 +00:00
fix Vault download filenames
This commit is contained in:
@@ -5,6 +5,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import googleapiclient
|
import googleapiclient
|
||||||
|
from pathvalidate import sanitize_filepath
|
||||||
|
|
||||||
import gam
|
import gam
|
||||||
from gam.gapi import errors as gapi_errors
|
from gam.gapi import errors as gapi_errors
|
||||||
@@ -152,11 +153,12 @@ def get_cloud_storage_object(s,
|
|||||||
expectedMd5=None):
|
expectedMd5=None):
|
||||||
if not local_file:
|
if not local_file:
|
||||||
local_file = object_
|
local_file = object_
|
||||||
|
local_file = sanitize_filepath(local_file, platform='auto')
|
||||||
if os.path.exists(local_file):
|
if os.path.exists(local_file):
|
||||||
sys.stdout.write(' File already exists. ')
|
sys.stdout.write(f'File {local_file} already exists.')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
if expectedMd5:
|
if expectedMd5:
|
||||||
sys.stdout.write(f'Verifying {expectedMd5} hash...')
|
sys.stdout.write(f' verifying {expectedMd5} hash...')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
if utils.md5_matches_file(local_file, expectedMd5, False):
|
if utils.md5_matches_file(local_file, expectedMd5, False):
|
||||||
print('VERIFIED')
|
print('VERIFIED')
|
||||||
@@ -164,7 +166,7 @@ def get_cloud_storage_object(s,
|
|||||||
print('not verified. Downloading again and over-writing...')
|
print('not verified. Downloading again and over-writing...')
|
||||||
else:
|
else:
|
||||||
return # nothing to verify, just assume we're good.
|
return # nothing to verify, just assume we're good.
|
||||||
print(f'saving to {local_file}')
|
print(f'Saving to {local_file}')
|
||||||
request = s.objects().get_media(bucket=bucket, object=object_)
|
request = s.objects().get_media(bucket=bucket, object=object_)
|
||||||
file_path = os.path.dirname(local_file)
|
file_path = os.path.dirname(local_file)
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
|
|||||||
@@ -867,24 +867,17 @@ def downloadExport():
|
|||||||
for s_file in export['cloudStorageSink']['files']:
|
for s_file in export['cloudStorageSink']['files']:
|
||||||
bucket = s_file['bucketName']
|
bucket = s_file['bucketName']
|
||||||
s_object = s_file['objectName']
|
s_object = s_file['objectName']
|
||||||
filename = os.path.join(targetFolder, s_object.replace('/', '-'))
|
|
||||||
print(f'saving to {filename}')
|
|
||||||
request = s.objects().get_media(bucket=bucket, object=s_object)
|
|
||||||
f = fileutils.open_file(filename, 'wb')
|
|
||||||
downloader = googleapiclient.http.MediaIoBaseDownload(f, request)
|
|
||||||
done = False
|
|
||||||
while not done:
|
|
||||||
status, done = downloader.next_chunk()
|
|
||||||
sys.stdout.write(f' Downloaded: {status.progress():>7.2%}\r')
|
|
||||||
sys.stdout.flush()
|
|
||||||
sys.stdout.write('\n Download complete. Flushing to disk...\n')
|
|
||||||
fileutils.close_file(f, True)
|
|
||||||
if verifyFiles:
|
if verifyFiles:
|
||||||
expected_hash = s_file['md5Hash']
|
expected_hash = s_file['md5Hash']
|
||||||
sys.stdout.write(f' Verifying file hash is {expected_hash}...')
|
else:
|
||||||
sys.stdout.flush()
|
expected_hash = None
|
||||||
utils.md5_matches_file(filename, expected_hash, True)
|
local_file = s_object.replace('/', '-').replace(':', '-')
|
||||||
print('VERIFIED')
|
filename = os.path.join(targetFolder, local_file)
|
||||||
|
gapi_storage.get_cloud_storage_object(s,
|
||||||
|
bucket,
|
||||||
|
s_object,
|
||||||
|
local_file=filename,
|
||||||
|
expectedMd5=expected_hash)
|
||||||
if extractFiles and re.search(r'\.zip$', filename):
|
if extractFiles and re.search(r'\.zip$', filename):
|
||||||
gam.extract_nested_zip(filename, targetFolder)
|
gam.extract_nested_zip(filename, targetFolder)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user