Beispiel #1
0
def start(args):
    download = json.loads(base64.urlsafe_b64decode(args.download))
    for download_arg in download:
        from_path = download_arg["from"]
        to_path = download_arg["to"]
        item_name = download_arg.get("item_name", "")
        bucket_name, prefix = S3.deconstruct_s3_path(from_path)
        s3_client = S3(bucket_name, client_config={})

        if item_name != "":
            cx_logger().info("downloading {} from {}".format(item_name, from_path))
        s3_client.download(prefix, to_path)

        if download_arg.get("unzip", False):
            if item_name != "":
                cx_logger().info("unzipping {}".format(item_name))
            util.extract_zip(
                os.path.join(to_path, os.path.basename(from_path)), delete_zip_file=True
            )

        if download_arg.get("tf_model_version_rename", "") != "":
            dest = util.trim_suffix(download_arg["tf_model_version_rename"], "/")
            dir_path = os.path.dirname(dest)
            entries = os.listdir(dir_path)
            if len(entries) == 1:
                src = os.path.join(dir_path, entries[0])
                os.rename(src, dest)
Beispiel #2
0
 def download_dir(self, prefix: str, local_dir: str):
     """
     Download directory inside the specified local directory.
     """
     dir_name = util.trim_suffix(prefix, "/").split("/")[-1]
     self.download_dir_contents(prefix, os.path.join(local_dir, dir_name))
Beispiel #3
0
 def download_dir(self, prefix, local_dir):
     dir_name = util.trim_suffix(prefix, "/").split("/")[-1]
     return self.download_dir_contents(prefix,
                                       os.path.join(local_dir, dir_name))