-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JA): Code refactor and moving functions around for code sharing …
…with upcoming JA CLI. (#451) Signed-off-by: David Leong <[email protected]>
- Loading branch information
Showing
9 changed files
with
165 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
from deadline.client import api | ||
from deadline.client.config import config_file | ||
from deadline.job_attachments.models import AssetRootGroup, AssetRootManifest | ||
from deadline.job_attachments.upload import S3AssetManager, SummaryStatistics | ||
|
||
|
||
import textwrap | ||
from configparser import ConfigParser | ||
from typing import Callable, Dict, List, Optional, Tuple | ||
|
||
|
||
def _hash_attachments( | ||
asset_manager: S3AssetManager, | ||
asset_groups: List[AssetRootGroup], | ||
total_input_files: int, | ||
total_input_bytes: int, | ||
print_function_callback: Callable = lambda msg: None, | ||
hashing_progress_callback: Optional[Callable] = None, | ||
config: Optional[ConfigParser] = None, | ||
) -> Tuple[SummaryStatistics, List[AssetRootManifest]]: | ||
""" | ||
Starts the job attachments hashing and handles the progress reporting | ||
callback. Returns a list of the asset manifests of the hashed files. | ||
""" | ||
|
||
def _default_update_hash_progress(hashing_metadata: Dict[str, str]) -> bool: | ||
return True | ||
|
||
if not hashing_progress_callback: | ||
hashing_progress_callback = _default_update_hash_progress | ||
|
||
hashing_summary, manifests = asset_manager.hash_assets_and_create_manifest( | ||
asset_groups=asset_groups, | ||
total_input_files=total_input_files, | ||
total_input_bytes=total_input_bytes, | ||
hash_cache_dir=config_file.get_cache_directory(), | ||
on_preparing_to_submit=hashing_progress_callback, | ||
) | ||
api.get_deadline_cloud_library_telemetry_client(config=config).record_hashing_summary( | ||
hashing_summary | ||
) | ||
print_function_callback("Hashing Summary:") | ||
print_function_callback(textwrap.indent(str(hashing_summary), " ")) | ||
|
||
return hashing_summary, manifests |
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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import click | ||
import json | ||
import typing as t | ||
|
||
|
||
class ClickLogger: | ||
""" | ||
Wrapper around click that is JSON aware. Users can instantiate this as a | ||
replacement for using `click.echo`. A helper JSON function is also provided | ||
to output JSON. | ||
""" | ||
|
||
def __init__(self, is_json: bool): | ||
self._is_json = is_json | ||
|
||
def echo( | ||
self, | ||
message: t.Optional[t.Any] = None, | ||
file: t.Optional[t.IO[t.Any]] = None, | ||
nl: bool = True, | ||
err: bool = False, | ||
color: t.Optional[bool] = None, | ||
): | ||
if not self._is_json: | ||
click.echo(message, file, nl, err, color) | ||
|
||
def json( | ||
self, | ||
message: t.Optional[dict] = None, | ||
file: t.Optional[t.IO[t.Any]] = None, | ||
nl: bool = True, | ||
err: bool = False, | ||
color: t.Optional[bool] = None, | ||
indent=None, | ||
): | ||
if self._is_json: | ||
click.echo(json.dumps(obj=message, indent=indent), file, nl, err, color) |
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
Oops, something went wrong.