in service/app/engine.py [0:0]
def download_bag_file(config):
now = str(int(time.time()))
working_dir = f"/root/{now}"
csv_dir = os.path.join(working_dir, "csvs")
clean_directory(working_dir)
clean_directory(csv_dir)
if config["s3_bag_file_prefix"].endswith(".tar.gz"):
local_tar_file = get_object(
config["s3_bag_file_bucket"], config["s3_bag_file_prefix"], working_dir
)
logging.warning("Untarring")
tar = tarfile.open(local_tar_file, "r:gz")
tar.extractall(working_dir)
print_files_in_path(working_dir)
tar.close()
logging.warning(f"Deleting {local_tar_file}")
os.remove(local_tar_file)
local_bag_files = [
x for x in absolute_file_paths(working_dir) if x.endswith(".bag")
]
assert (
len(local_bag_files) == 1
), f"More than 1 bag file found {local_bag_files}"
local_bag_file = local_bag_files[0]
# logging.warning("testing efs - copy 1")
# shutil.copyfile(local_bag_file, local_bag_file + "_2")
# logging.warning("testing efs - copy 2")
# shutil.copyfile(local_bag_file, local_bag_file + "_3")
# logging.warning("testing efs - copy 3")
# shutil.copyfile(local_bag_file, local_bag_file + "_4")
# logging.warning(psutil.disk_usage('/'))
# logging.warning(psutil.disk_usage(working_dir))
# os.remove(local_bag_file + "_4")
# os.remove(local_bag_file + "_3")
# os.remove(local_bag_file + "_2")
else:
# Download Bag File from S3
local_bag_file = get_object(
config["s3_bag_file_bucket"], config["s3_bag_file_prefix"], working_dir
)
return local_bag_file, working_dir