From e5a73fe8ff5e9ac641ec641b1ba3f8beb1ffa48a Mon Sep 17 00:00:00 2001 From: AMZN-Phil Date: Mon, 18 Oct 2021 16:32:42 -0700 Subject: [PATCH 1/3] Add helper function for UI to return paths to all cached gem jsons for a given repo Signed-off-by: AMZN-Phil --- scripts/o3de/o3de/repo.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/o3de/o3de/repo.py b/scripts/o3de/o3de/repo.py index 191fdbd3e1..6b6dffe8b3 100644 --- a/scripts/o3de/o3de/repo.py +++ b/scripts/o3de/o3de/repo.py @@ -92,6 +92,42 @@ def process_add_o3de_repo(file_name: str or pathlib.Path, return 0 +def get_gem_json_paths_from_cached_repo(repo_uri : str) -> list: + url = f'{repo_uri}/repo.json' + repo_sha256 = hashlib.sha256(url.encode()) + cache_folder = manifest.get_o3de_cache_folder() + cache_filename = cache_folder / str(repo_sha256.hexdigest() + '.json') + + gem_list = [] + + file_name = pathlib.Path(cache_filename).resolve() + if not file_name.is_file(): + return gem_list + + with file_name.open('r') as f: + try: + repo_data = json.load(f) + except json.JSONDecodeError as e: + logger.error(f'{file_name} failed to load: {str(e)}') + return gem_list + + # Get list of gems, then add all json paths to the list if they exist in the cache + repo_gems = [] + try: + repo_gems.append((repo_data['gems'], 'gem.json')) + except KeyError: + pass + + for o3de_object_uris, manifest_json in repo_gems: + for o3de_object_uri in o3de_object_uris: + manifest_json_uri = f'{o3de_object_uri}/{manifest_json}' + manifest_json_sha256 = hashlib.sha256(manifest_json_uri.encode()) + cache_file = cache_folder / str(manifest_json_sha256.hexdigest() + '.json') + if cache_file.is_file(): + gem_list.append(cache_file) + + return gem_list + def refresh_repos() -> int: json_data = manifest.load_o3de_manifest() From c48d95748557d17c246285c8a8b84c4248a17cd6 Mon Sep 17 00:00:00 2001 From: AMZN-Phil Date: Mon, 18 Oct 2021 16:34:07 -0700 Subject: [PATCH 2/3] Slightly better variable naming Signed-off-by: AMZN-Phil --- scripts/o3de/o3de/repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/o3de/o3de/repo.py b/scripts/o3de/o3de/repo.py index 6b6dffe8b3..ae8af43338 100644 --- a/scripts/o3de/o3de/repo.py +++ b/scripts/o3de/o3de/repo.py @@ -122,9 +122,9 @@ def get_gem_json_paths_from_cached_repo(repo_uri : str) -> list: for o3de_object_uri in o3de_object_uris: manifest_json_uri = f'{o3de_object_uri}/{manifest_json}' manifest_json_sha256 = hashlib.sha256(manifest_json_uri.encode()) - cache_file = cache_folder / str(manifest_json_sha256.hexdigest() + '.json') - if cache_file.is_file(): - gem_list.append(cache_file) + cache_gem_json_filepath = cache_folder / str(manifest_json_sha256.hexdigest() + '.json') + if cache_gem_json_filepath.is_file(): + gem_list.append(cache_gem_json_filepath) return gem_list From 7ce376b5b2a6901a55718e3e9f953da6a1c2594b Mon Sep 17 00:00:00 2001 From: AMZN-Phil Date: Tue, 19 Oct 2021 08:40:36 -0700 Subject: [PATCH 3/3] Add some log output if the cached files cannot be found Signed-off-by: AMZN-Phil --- scripts/o3de/o3de/repo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/o3de/o3de/repo.py b/scripts/o3de/o3de/repo.py index ae8af43338..5c47c2bee8 100644 --- a/scripts/o3de/o3de/repo.py +++ b/scripts/o3de/o3de/repo.py @@ -92,7 +92,7 @@ def process_add_o3de_repo(file_name: str or pathlib.Path, return 0 -def get_gem_json_paths_from_cached_repo(repo_uri : str) -> list: +def get_gem_json_paths_from_cached_repo(repo_uri: str) -> list: url = f'{repo_uri}/repo.json' repo_sha256 = hashlib.sha256(url.encode()) cache_folder = manifest.get_o3de_cache_folder() @@ -102,6 +102,7 @@ def get_gem_json_paths_from_cached_repo(repo_uri : str) -> list: file_name = pathlib.Path(cache_filename).resolve() if not file_name.is_file(): + logger.error(f'Could not find cached repo json file for {repo_uri}') return gem_list with file_name.open('r') as f: @@ -124,6 +125,7 @@ def get_gem_json_paths_from_cached_repo(repo_uri : str) -> list: manifest_json_sha256 = hashlib.sha256(manifest_json_uri.encode()) cache_gem_json_filepath = cache_folder / str(manifest_json_sha256.hexdigest() + '.json') if cache_gem_json_filepath.is_file(): + logger.warn(f'Could not find cached gem json file for {o3de_object_uri} in repo {repo_uri}') gem_list.append(cache_gem_json_filepath) return gem_list