-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c73786e
commit 62b38b4
Showing
2 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
import os | ||
import logging | ||
from concurrent.futures import ThreadPoolExecutor | ||
from functools import partial | ||
|
||
|
||
from transferrer.common import should_download_file, shoot_number_to_folder_path, get_source_bucket | ||
|
||
logger = logging.getLogger(__name__) | ||
THREADS = 20 | ||
|
||
|
||
def download_s3_folder(bucket, s3_folder: str, local_dir: str): | ||
os.makedirs(local_dir, exist_ok=True) | ||
with ThreadPoolExecutor(max_workers=THREADS) as executor: | ||
for key in executor.map( | ||
partial(download_s3_file, local_dir=local_dir, s3_folder=s3_folder), | ||
(obj for obj in bucket.objects.filter(Prefix=s3_folder) if should_download_file(obj.key)) | ||
): | ||
logger.info(f"downloaded\t{key}") | ||
|
||
downloadables = (obj for obj in bucket.objects.filter(Prefix=s3_folder) if should_download_file(obj.key)) | ||
|
||
for obj in downloadables: | ||
target = os.path.join(local_dir, os.path.relpath(obj.key, s3_folder)) | ||
bucket.download_file(obj.key, target) | ||
def download_s3_file(object_summary, *, local_dir: str, s3_folder: str): | ||
logger.info(f"downloading\t{object_summary.key}") | ||
target = os.path.join(local_dir, os.path.relpath(object_summary.key, s3_folder)) | ||
object_summary.Object().download_file(target) | ||
return object_summary.key | ||
|
||
|
||
def download_shoot_folder(bucket, shoot_number, local_dir): | ||
download_s3_folder(bucket, shoot_number_to_folder_path(shoot_number), local_dir) | ||
|
||
|
||
def download_shoot(shoot_number, local_dir): | ||
download_shoot_folder(get_source_bucket(), shoot_number, local_dir) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
shoot_number = sys.argv[1] | ||
download_folder = os.path.join("download", shoot_number) | ||
os.makedirs(download_folder, exist_ok=True) | ||
download_shoot_folder(get_source_bucket(), sys.argv[1], download_folder) | ||
download_shoot_folder(get_source_bucket(THREADS), sys.argv[1], download_folder) |