merge stabilization/2106 into development
Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
@@ -212,6 +212,28 @@ def save_o3de_manifest(json_data: dict, manifest_path: pathlib.Path = None) -> b
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def get_gems_from_subdirectories(external_subdirs: list) -> list:
|
||||
'''
|
||||
Helper Method for scanning a set of external subdirectories for gem.json files
|
||||
'''
|
||||
def is_gem_subdirectory(subdir_files):
|
||||
for name in files:
|
||||
if name == 'gem.json':
|
||||
return True
|
||||
return False
|
||||
|
||||
gem_directories = []
|
||||
# Locate all subfolders with gem.json files within them
|
||||
if external_subdirs:
|
||||
for subdirectory in external_subdirs:
|
||||
for root, dirs, files in os.walk(pathlib.Path(subdirectory).resolve()):
|
||||
if is_gem_subdirectory(files):
|
||||
gem_directories.append(pathlib.PurePath(root).as_posix())
|
||||
|
||||
return gem_directories
|
||||
|
||||
|
||||
# Data query methods
|
||||
def get_this_engine() -> dict:
|
||||
json_data = load_o3de_manifest()
|
||||
@@ -230,11 +252,7 @@ def get_projects() -> list:
|
||||
|
||||
|
||||
def get_gems() -> list:
|
||||
def is_gem_subdirectory(subdir):
|
||||
return (pathlib.Path(subdir) / 'gem.json').exists()
|
||||
|
||||
external_subdirs = get_external_subdirectories()
|
||||
return list(filter(is_gem_subdirectory, external_subdirs)) if external_subdirs else []
|
||||
return get_gems_from_subdirectories(get_external_subdirectories())
|
||||
|
||||
|
||||
def get_external_subdirectories() -> list:
|
||||
@@ -265,11 +283,7 @@ def get_engine_projects() -> list:
|
||||
|
||||
|
||||
def get_engine_gems() -> list:
|
||||
def is_gem_subdirectory(subdir):
|
||||
return (pathlib.Path(subdir) / 'gem.json').exists()
|
||||
|
||||
external_subdirs = get_engine_external_subdirectories()
|
||||
return list(filter(is_gem_subdirectory, external_subdirs)) if external_subdirs else []
|
||||
return get_gems_from_subdirectories(get_engine_external_subdirectories())
|
||||
|
||||
|
||||
def get_engine_external_subdirectories() -> list:
|
||||
@@ -295,11 +309,7 @@ def get_engine_restricted() -> list:
|
||||
|
||||
# project.json queries
|
||||
def get_project_gems(project_path: pathlib.Path) -> list:
|
||||
def is_gem_subdirectory(subdir):
|
||||
return (pathlib.Path(subdir) / 'gem.json').exists()
|
||||
|
||||
external_subdirs = get_project_external_subdirectories(project_path)
|
||||
return list(filter(is_gem_subdirectory, external_subdirs)) if external_subdirs else []
|
||||
return get_gems_from_subdirectories(get_project_external_subdirectories(project_path))
|
||||
|
||||
|
||||
def get_project_external_subdirectories(project_path: pathlib.Path) -> list:
|
||||
|
||||
@@ -404,26 +404,27 @@ def register_project_path(json_data: dict,
|
||||
if result != 0:
|
||||
return result
|
||||
|
||||
# registering a project has the additional step of setting the project.json 'engine' field
|
||||
this_engine_json = manifest.get_engine_json_data(engine_path=manifest.get_this_engine_path())
|
||||
if not this_engine_json:
|
||||
return 1
|
||||
project_json_data = manifest.get_project_json_data(project_path=project_path)
|
||||
if not project_json_data:
|
||||
return 1
|
||||
|
||||
update_project_json = False
|
||||
try:
|
||||
update_project_json = project_json_data['engine'] != this_engine_json['engine_name']
|
||||
except KeyError as e:
|
||||
update_project_json = True
|
||||
|
||||
if update_project_json:
|
||||
project_json_path = project_path / 'project.json'
|
||||
project_json_data['engine'] = this_engine_json['engine_name']
|
||||
utils.backup_file(project_json_path)
|
||||
if not manifest.save_o3de_manifest(project_json_data, project_json_path):
|
||||
if not remove:
|
||||
# registering a project has the additional step of setting the project.json 'engine' field
|
||||
this_engine_json = manifest.get_engine_json_data(engine_path=manifest.get_this_engine_path())
|
||||
if not this_engine_json:
|
||||
return 1
|
||||
project_json_data = manifest.get_project_json_data(project_path=project_path)
|
||||
if not project_json_data:
|
||||
return 1
|
||||
|
||||
update_project_json = False
|
||||
try:
|
||||
update_project_json = project_json_data['engine'] != this_engine_json['engine_name']
|
||||
except KeyError as e:
|
||||
update_project_json = True
|
||||
|
||||
if update_project_json:
|
||||
project_json_path = project_path / 'project.json'
|
||||
project_json_data['engine'] = this_engine_json['engine_name']
|
||||
utils.backup_file(project_json_path)
|
||||
if not manifest.save_o3de_manifest(project_json_data, project_json_path):
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
@@ -656,6 +657,22 @@ def register(engine_path: pathlib.Path = None,
|
||||
|
||||
return result
|
||||
|
||||
def remove_invalid_o3de_projects(manifest_path: pathlib.Path = None) -> int:
|
||||
if not manifest_path:
|
||||
manifest_path = manifest.get_o3de_manifest()
|
||||
|
||||
json_data = manifest.load_o3de_manifest(manifest_path)
|
||||
|
||||
result = 0
|
||||
|
||||
for project in json_data['projects']:
|
||||
if not validation.valid_o3de_project_json(pathlib.Path(project).resolve() / 'project.json'):
|
||||
logger.warn(f"Project path {project} is invalid.")
|
||||
# Attempt to unregister all invalid projects even if previous projects failed to unregister
|
||||
# but combine the result codes of each command.
|
||||
result = register(project_path=pathlib.Path(project), remove=True) or result
|
||||
|
||||
return result
|
||||
|
||||
def remove_invalid_o3de_objects() -> None:
|
||||
json_data = manifest.load_o3de_manifest()
|
||||
@@ -666,10 +683,7 @@ def remove_invalid_o3de_objects() -> None:
|
||||
logger.warn(f"Engine path {engine_path} is invalid.")
|
||||
register(engine_path=engine_path, remove=True)
|
||||
|
||||
for project in json_data['projects']:
|
||||
if not validation.valid_o3de_project_json(pathlib.Path(project).resolve() / 'project.json'):
|
||||
logger.warn(f"Project path {project} is invalid.")
|
||||
register(project_path=project, remove=True)
|
||||
remove_invalid_o3de_projects()
|
||||
|
||||
for gem in json_data['gems']:
|
||||
if not validation.valid_o3de_gem_json(pathlib.Path(gem).resolve() / 'gem.json'):
|
||||
|
||||
Reference in New Issue
Block a user