def list_part(resource, bucket_name, object_name, upload_id): try: response = bucket_lib.list_part(resource, bucket_name, object_name, upload_id) for part in response: size = utils.sizeof_fmt(part["Size"]) last_modified = f"{part['LastModified']:%Y-%m-%d %H:%M:%S}" msg = (f'Number of part: {part["PartNumber"]}\n' f"Last Modified: {last_modified}\n" f'ETag: {part["ETag"]}\n' f"Size: {size}") click.secho(msg) except Exception as exc: click.secho(f"{exc}", fg="yellow", bold=True, err=True)
def object_info(resource, bucket_name, object_name): try: info = bucket_lib.object_info(resource, bucket_name, object_name) size = utils.sizeof_fmt(info["Size"]) last_modified = f"{info['LastModified']:%Y-%m-%d %H:%M:%S}" msg = ( f"File Size: {size}\n" f"Last Modified: {last_modified}\n" f"Mime Type: {info['MimeType']}\n" f"Storage: {info['StorageClass']}\n" f"MD5 Sum: {info['MD5']}" ) click.secho(msg) for grant in info["ACL"]: click.secho(f"ACL: {grant[0]} : {grant[1]}") except Exception as exc: click.secho(f"Info fetching failed. \n{exc}", fg="yellow", bold=True, err=True)
def get_objects(resource, uri): try: bucket_name, prefix = utils.get_bucket_key(uri) response = bucket_lib.get_objects(resource, bucket_name, prefix) if not response: click.secho(f'Bucket "{bucket_name}" is empty', fg="green") if response["CommonPrefixes"]: for prefix in response["CommonPrefixes"]: dir_ = "DIR".rjust(12) click.secho(f"{dir_} {bucket_name}/{prefix['Prefix']}") if response["Contents"]: for content in response["Contents"]: key = content["Key"] size = utils.sizeof_fmt(content["Size"]) last_modified = content["LastModified"] click.secho( f"{last_modified:%Y-%m-%d %H:%M:%S}, {size}, {bucket_name}/{key}" ) except Exception as exc: click.secho(f"{exc}", fg="yellow", bold=True, err=True)
def test_size(): # 100*13 is used to get size with unit YiB assert utils.sizeof_fmt(100 ** 13) == "82.7 YiB"