Updating manifest.py template query functions (#1113)

* Updating manifest.py template query functions
The get_project_templates, get_gem_templates and get_generic_templates
methods have been renamed to indicate that the methods return the
templates that can be used in a create-project, create-gem and
create-from-template command of the engine_template.py

Updated the print_registration.py script to support outputing project
specific gems and templates.
Add a unit test script for the manifest.py script.
Added unit test to validate the new functions:
`get_templates_for_project_creation`
`get_templates_for_gem_creation`
`get_templates_for_generic_creation`

* Implementing the project print registration methods

Added implementations of the project print registration methods and tested them locally
Removed implementations of the download print registration methods, since they have not went through app-sec review.

* Renaming get_restricted_data to get_restricted_json_data

Fixed the get_registered method in manifest.py when looking up projects

* Updated the print_manifest_json_data calls to return the result
main
lumberyard-employee-dm 5 years ago committed by GitHub
parent c2619decc4
commit 816d05ef2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -294,7 +294,8 @@ namespace O3DE::ProjectManager
RegisterThisEngine();
return result == 0 && !PyErr_Occurred();
} catch ([[maybe_unused]] const std::exception& e)
}
catch ([[maybe_unused]] const std::exception& e)
{
AZ_Warning("ProjectManagerWindow", false, "Py_Initialize() failed with %s", e.what());
return false;
@ -383,7 +384,7 @@ namespace O3DE::ProjectManager
engineInfo.m_defaultProjectsFolder = Py_To_String(o3deData["default_projects_folder"]);
engineInfo.m_defaultRestrictedFolder = Py_To_String(o3deData["default_restricted_folder"]);
engineInfo.m_defaultTemplatesFolder = Py_To_String(o3deData["default_templates_folder"]);
engineInfo.m_thirdPartyPath = Py_To_String_Optional(o3deData,"third_party_path","");
engineInfo.m_thirdPartyPath = Py_To_String_Optional(o3deData, "third_party_path", "");
}
auto engineData = m_manifest.attr("get_engine_json_data")(pybind11::none(), enginePath);
@ -391,8 +392,8 @@ namespace O3DE::ProjectManager
{
try
{
engineInfo.m_version = Py_To_String_Optional(engineData,"O3DEVersion","0.0.0.0");
engineInfo.m_name = Py_To_String_Optional(engineData,"engine_name","O3DE");
engineInfo.m_version = Py_To_String_Optional(engineData, "O3DEVersion", "0.0.0.0");
engineInfo.m_name = Py_To_String_Optional(engineData, "engine_name", "O3DE");
}
catch ([[maybe_unused]] const std::exception& e)
{
@ -685,7 +686,7 @@ namespace O3DE::ProjectManager
try
{
projectInfo.m_projectName = Py_To_String(projectData["project_name"]);
projectInfo.m_displayName = Py_To_String_Optional(projectData,"display_name", projectInfo.m_projectName);
projectInfo.m_displayName = Py_To_String_Optional(projectData, "display_name", projectInfo.m_projectName);
}
catch ([[maybe_unused]] const std::exception& e)
{
@ -806,7 +807,7 @@ namespace O3DE::ProjectManager
QVector<ProjectTemplateInfo> templates;
bool result = ExecuteWithLock([&] {
for (auto path : m_manifest.attr("get_project_templates")())
for (auto path : m_manifest.attr("get_templates_for_project_creation")())
{
templates.push_back(ProjectTemplateInfoFromPath(path));
}

@ -302,64 +302,95 @@ def get_project_external_subdirectories(project_path: pathlib.Path) -> list:
project_object['external_subdirectories'])) if 'external_subdirectories' in project_object else []
def get_project_templates(project_path: pathlib.Path) -> list:
project_object = get_project_json_data(project_path=project_path)
return list(map(lambda rel_path: (pathlib.Path(project_path) / rel_path).as_posix(),
project_object['templates']))
def get_project_restricted(project_path: pathlib.Path) -> list:
project_object = get_project_json_data(project_path=project_path)
return list(map(lambda rel_path: (pathlib.Path(project_path) / rel_path).as_posix(),
project_object['restricted'])) if 'restricted' in project_object else []
# Combined manifest queries
def get_all_projects() -> list:
projects_data = set(get_projects())
projects_data.update(get_engine_projects())
return list(projects_data)
projects_data = get_projects()
projects_data.extend(get_engine_projects())
# Remove duplicates from the list
return list(dict.fromkeys(projects_data))
def get_all_gems(project_path: pathlib.Path = None) -> list:
gems_data = set(get_gems())
gems_data.update(get_engine_gems())
gems_data = get_gems()
gems_data.extend(get_engine_gems())
if project_path:
gems_data.update(get_project_gems(project_path))
return list(gems_data)
gems_data.extend(get_project_gems(project_path))
return list(dict.fromkeys(gems_data))
def get_all_external_subdirectories(project_path: pathlib.Path = None) -> list:
external_subdirectories_data = set(get_external_subdirectories())
external_subdirectories_data.update(get_engine_external_subdirectories())
external_subdirectories_data = get_external_subdirectories()
external_subdirectories_data.extend(get_engine_external_subdirectories())
if project_path:
external_subdirectories_data.update(get_project_external_subdirectories(project_path))
return list(templates_data)
external_subdirectories_data.extend(get_project_external_subdirectories(project_path))
return list(dict.fromkeys(external_subdirectories_data))
def get_all_templates() -> list:
templates_data = set(get_templates())
templates_data.update(get_engine_templates())
return list(templates_data)
def get_all_templates(project_path: pathlib.Path = None) -> list:
templates_data = get_templates()
templates_data.extend(get_engine_templates())
if project_path:
templates_data.extend(get_project_templates(project_path))
return list(dict.fromkeys(templates_data))
def get_all_restricted() -> list:
restricted_data = set(get_restricted())
restricted_data.update(get_engine_restricted())
return list(gems_data)
restricted_data = get_restricted()
restricted_data.extend(get_engine_restricted())
if project_path:
restricted_data.extend(get_project_restricted(project_path))
return list(dict.fromkeys(restricted_data))
# Template functions
def get_project_templates(): # temporary until we have a better way to do this... maybe template_type element
def get_templates_for_project_creation():
project_templates = []
for template in get_all_templates():
if 'Project' in template:
project_templates.append(template)
for template_path in get_all_templates():
template_path = pathlib.Path(template_path)
template_json_path = pathlib.Path(template_path) / 'template.json'
if not validation.valid_o3de_template_json(template_json_path):
continue
project_json_path = template_path / 'Template' / 'project.json'
if validation.valid_o3de_project_json(project_json_path):
project_templates.append(template_path)
return project_templates
def get_gem_templates(): # temporary until we have a better way to do this... maybe template_type element
def get_templates_for_gem_creation():
gem_templates = []
for template in get_all_templates():
if 'Gem' in template:
gem_templates.append(template)
for template_path in get_all_templates():
template_path = pathlib.Path(template_path)
template_json_path = pathlib.Path(template_path) / 'template.json'
if not validation.valid_o3de_template_json(template_json_path):
continue
gem_json_path = template_path / 'Template' / 'gem.json'
if validation.valid_o3de_gem_json(gem_json_path):
gem_templates.append(template_path)
return gem_templates
def get_generic_templates(): # temporary until we have a better way to do this... maybe template_type element
generic_templates = []
for template in get_all_templates():
if 'Project' not in template and 'Gem' not in template:
generic_templates.append(template)
return generic_templates
def get_templates_for_generic_creation(): # temporary until we have a better way to do this... maybe template_type element
def filter_project_and_gem_templates_out(template_path,
templates_for_project_creation = get_templates_for_project_creation(),
templates_for_gem_creation = get_templates_for_gem_creation()):
template_path = pathlib.Path(template_path)
return template_path not in templates_for_project_creation and template_path not in templates_for_gem_creation
return list(filter(filter_project_and_gem_templates_out, get_all_templates()))
def get_all_restricted() -> list:
@ -515,7 +546,7 @@ def get_template_json_data(template_name: str = None,
return None
def get_restricted_data(restricted_name: str = None,
def get_restricted_json_data(restricted_name: str = None,
restricted_path: str or pathlib.Path = None) -> dict or None:
if not restricted_name and not restricted_path:
logger.error('Must specify either a Restricted name or Restricted Path.')

@ -13,6 +13,7 @@ import argparse
import json
import hashlib
import logging
import pathlib
import sys
import urllib.parse
@ -21,219 +22,251 @@ from o3de import manifest, validation
logger = logging.getLogger()
logging.basicConfig()
def print_this_engine(verbose: int) -> None:
def get_project_path(project_path: pathlib.Path, project_name: str) -> pathlib.Path:
if not project_name and not project_path:
logger.error(f'Must either specify a Project path or Project Name.')
return None
if not project_path:
project_path = manifest.get_registered(project_name=project_name)
if not project_path:
logger.error(f'Unable to locate project path from the registered manifest json files:'
f' {str(pathlib.Path("~/.o3de/o3de_manifest.json").expanduser())}, engine.json')
return None
if not project_path.is_dir():
logger.error(f'Project path {project_path} is not a folder.')
return None
return project_path
def print_this_engine(verbose: int) -> int:
engine_data = manifest.get_this_engine()
print(json.dumps(engine_data, indent=4))
result = True
if verbose > 0:
print_engines_data(engine_data)
result = print_manifest_json_data(engine_data, 'engine.json', 'This Engine',
manifest.get_engine_json_data, 'engine_path')
return 0 if result else 1
def print_engines(verbose: int) -> None:
engines_data = manifest.get_engines()
print(json.dumps(engines_data, indent=4))
if verbose > 0:
print_engines_data(engines_data)
return print_manifest_json_data(engines_data, 'engine.json', 'Engines',
manifest.get_engine_json_data, 'engine_path')
return 0
def print_projects(verbose: int) -> None:
def print_projects(verbose: int) -> int:
projects_data = manifest.get_projects()
print(json.dumps(projects_data, indent=4))
if verbose > 0:
print_projects_data(projects_data)
return print_manifest_json_data(projects_data, 'project.json', 'Projects',
manifest.get_project_json_data, 'project_path')
return 0
def print_gems(verbose: int) -> None:
def print_gems(verbose: int) -> int:
gems_data = manifest.get_gems()
print(json.dumps(gems_data, indent=4))
if verbose > 0:
print_gems_data(gems_data)
return print_manifest_json_data(gems_data, 'gem.json', 'Gems',
manifest.get_gem_json_data, 'gem_path')
return 0
def print_templates(verbose: int) -> None:
def print_templates(verbose: int) -> int:
templates_data = manifest.get_templates()
print(json.dumps(templates_data, indent=4))
if verbose > 0:
print_templates_data(templates_data)
return print_manifest_json_data(templates_data, 'template.json', 'Templates',
manifest.get_template_json_data, 'template_path')
return 0
def print_restricted(verbose: int) -> None:
def print_restricted(verbose: int) -> int:
restricted_data = manifest.get_restricted()
print(json.dumps(restricted_data, indent=4))
if verbose > 0:
print_restricted_data(restricted_data)
return print_manifest_json_data(restricted_data, 'restricted.json', 'Restricted',
manifest.get_restricted_json_data, 'restricted_path')
return 0
def print_engine_projects(verbose: int) -> None:
# Engine output methods
def print_engine_projects(verbose: int) -> int:
engine_projects_data = manifest.get_engine_projects()
print(json.dumps(engine_projects_data, indent=4))
if verbose > 0:
print_projects_data(engine_projects_data)
return print_manifest_json_data(engine_projects_data, 'project.json', 'Projects',
manifest.get_project_json_data, 'project_path')
return 0
def print_engine_gems(verbose: int) -> None:
def print_engine_gems(verbose: int) -> int:
engine_gems_data = manifest.get_engine_gems()
print(json.dumps(engine_gems_data, indent=4))
if verbose > 0:
print_gems_data(engine_gems_data)
return print_manifest_json_data(engine_gems_data, 'gem.json', 'Gems',
manifest.get_gem_json_data, 'gem_path')
return 0
def print_engine_templates(verbose: int) -> None:
def print_engine_templates(verbose: int) -> int:
engine_templates_data = manifest.get_engine_templates()
print(json.dumps(engine_templates_data, indent=4))
if verbose > 0:
print_templates_data(engine_templates_data)
return print_manifest_json_data(engine_templates_data, 'template.json', 'Templates',
manifest.get_template_json_data, 'template_path')
return 0
def print_engine_restricted(verbose: int) -> None:
def print_engine_restricted(verbose: int) -> int:
engine_restricted_data = manifest.get_engine_restricted()
print(json.dumps(engine_restricted_data, indent=4))
if verbose > 0:
print_restricted_data(engine_restricted_data)
return print_manifest_json_data(engine_restricted_data, 'restricted.json', 'Restricted',
manifest.get_restricted_json_data, 'restricted_path')
return 0
def print_engine_external_subdirectories(verbose: int) -> None:
def print_engine_external_subdirectories() -> int:
external_subdirs_data = manifest.get_engine_external_subdirectories()
print(json.dumps(external_subdirs_data, indent=4))
return 0
def print_all_projects(verbose: int) -> None:
all_projects_data = manifest.get_all_projects()
print(json.dumps(all_projects_data, indent=4))
# Project output methods
def print_project_gems(verbose: int, project_path: pathlib.Path, project_name: str) -> int:
project_path = get_project_path(project_path, project_name)
if not project_path:
return 1
project_gems_data = manifest.get_project_gems(project_path)
print(json.dumps(project_gems_data, indent=4))
if verbose > 0:
print_projects_data(all_projects_data)
return print_manifest_json_data(project_gems_data, 'gem.json', 'Gems',
manifest.get_gem_json_data, 'gem_path')
return 0
def print_all_gems(verbose: int) -> None:
all_gems_data = manifest.get_all_gems()
print(json.dumps(all_gems_data, indent=4))
def print_project_external_subdirectories(project_path: pathlib.Path, project_name: str) -> int:
project_path = get_project_path(project_path, project_name)
if not project_path:
return 1
external_subdirs_data = manifest.get_project_external_subdirectories(project_path)
print(json.dumps(external_subdirs_data, indent=4))
return 0
def print_project_templates(verbose: int, project_path: pathlib.Path, project_name: str) -> int:
project_path = get_project_path(project_path, project_name)
if not project_path:
return 1
project_templates_data = manifest.get_project_templates(project_path)
print(json.dumps(project_templates_data, indent=4))
if verbose > 0:
print_gems_data(all_gems_data)
return print_manifest_json_data(project_templates_data, 'template.json', 'Templates',
manifest.get_template_json_data, 'template_path')
return 0
def print_all_templates(verbose: int) -> None:
all_templates_data = manifest.get_all_templates()
print(json.dumps(all_templates_data, indent=4))
def print_project_restricted(verbose: int, project_path: pathlib.Path, project_name: str) -> int:
project_path = get_project_path(project_path, project_name)
if not project_path:
return 1
project_restricted_data = manifest.get_project_restricted(project_path)
print(json.dumps(project_restricted_data, indent=4))
if verbose > 0:
print_templates_data(all_templates_data)
return print_manifest_json_data(project_restricted_data, 'restricted.json', 'Restricted',
manifest.get_restricted_json_data, 'restricted_path')
return 0
def print_all_restricted(verbose: int) -> None:
all_restricted_data = manifest.get_all_restricted()
print(json.dumps(all_restricted_data, indent=4))
def print_all_projects(verbose: int) -> int:
all_projects_data = manifest.get_all_projects()
print(json.dumps(all_projects_data, indent=4))
if verbose > 0:
print_restricted_data(all_restricted_data)
return print_manifest_json_data(all_projects_data, 'project.json', 'Projects',
manifest.get_project_json_data, 'project_path')
return 0
def print_engines_data(engines_data: dict) -> None:
print('\n')
print("Engines================================================")
for engine_object in engines_data:
# if it's not local it should be in the cache
engine_uri = engine_object['path']
parsed_uri = urllib.parse.urlparse(engine_uri)
if parsed_uri.scheme == 'http' or \
parsed_uri.scheme == 'https' or \
parsed_uri.scheme == 'ftp' or \
parsed_uri.scheme == 'ftps':
repo_sha256 = hashlib.sha256(engine_uri.encode())
cache_folder = manifest.get_o3de_cache_folder()
engine = cache_folder / str(repo_sha256.hexdigest() + '.json')
print(f'{engine_uri}/engine.json cached as:')
else:
engine_json = pathlib.Path(engine_uri).resolve() / 'engine.json'
def print_all_gems(verbose: int) -> int:
all_gems_data = manifest.get_all_gems()
print(json.dumps(all_gems_data, indent=4))
with engine_json.open('r') as f:
try:
engine_json_data = json.load(f)
except json.JSONDecodeError as e:
logger.warn(f'{engine_json} failed to load: {str(e)}')
else:
print(engine_json)
print(json.dumps(engine_json_data, indent=4))
print('\n')
if verbose > 0:
return print_manifest_json_data(all_gems_data, 'gem.json', 'Gems',
manifest.get_gem_json_data, 'gem_path')
return 0
def print_projects_data(projects_data: dict) -> None:
print('\n')
print("Projects================================================")
for project_uri in projects_data:
# if it's not local it should be in the cache
parsed_uri = urllib.parse.urlparse(project_uri)
if parsed_uri.scheme == 'http' or \
parsed_uri.scheme == 'https' or \
parsed_uri.scheme == 'ftp' or \
parsed_uri.scheme == 'ftps':
repo_sha256 = hashlib.sha256(project_uri.encode())
cache_folder = manifest.get_o3de_cache_folder()
project_json = cache_folder / str(repo_sha256.hexdigest() + '.json')
else:
project_json = pathlib.Path(project_uri).resolve() / 'project.json'
def print_all_external_subdirectories() -> int:
all_external_subdirectories_data = manifest.get_all_external_subdirectories()
print(json.dumps(all_external_subdirectories_data, indent=4))
return 0
with project_json.open('r') as f:
try:
project_json_data = json.load(f)
except json.JSONDecodeError as e:
logger.warn(f'{project_json} failed to load: {str(e)}')
else:
print(project_json)
print(json.dumps(project_json_data, indent=4))
print('\n')
def print_all_templates(verbose: int) -> int:
all_templates_data = manifest.get_all_templates()
print(json.dumps(all_templates_data, indent=4))
if verbose > 0:
return print_manifest_json_data(all_templates_data, 'template.json', 'Templates',
manifest.get_template_json_data, 'template_path')
return 0
def print_gems_data(gems_data: dict) -> None:
print('\n')
print("Gems================================================")
for gem_uri in gems_data:
# if it's not local it should be in the cache
parsed_uri = urllib.parse.urlparse(gem_uri)
if parsed_uri.scheme == 'http' or \
parsed_uri.scheme == 'https' or \
parsed_uri.scheme == 'ftp' or \
parsed_uri.scheme == 'ftps':
repo_sha256 = hashlib.sha256(gem_uri.encode())
cache_folder = manifest.get_o3de_cache_folder()
gem_json = cache_folder / str(repo_sha256.hexdigest() + '.json')
else:
gem_json = pathlib.Path(gem_uri).resolve() / 'gem.json'
with gem_json.open('r') as f:
try:
gem_json_data = json.load(f)
except json.JSONDecodeError as e:
logger.warn(f'{gem_json} failed to load: {str(e)}')
else:
print(gem_json)
print(json.dumps(gem_json_data, indent=4))
print('\n')
def print_all_restricted(verbose: int) -> int:
all_restricted_data = manifest.get_all_restricted()
print(json.dumps(all_restricted_data, indent=4))
if verbose > 0:
return print_manifest_json_data(all_restricted_data, 'restricted.json', 'Restricted',
manifest.get_restricted_json_data, 'restricted_path')
return 0
def print_templates_data(templates_data: dict) -> None:
def print_manifest_json_data(uri_json_data: dict, json_filename: str,
print_prefix: str, get_json_func: callable, get_json_data_kw: str) -> int:
print('\n')
print("Templates================================================")
for template_uri in templates_data:
print(f"{print_prefix}================================================")
for manifest_uri in uri_json_data:
# if it's not local it should be in the cache
parsed_uri = urllib.parse.urlparse(template_uri)
if parsed_uri.scheme == 'http' or \
parsed_uri.scheme == 'https' or \
parsed_uri.scheme == 'ftp' or \
parsed_uri.scheme == 'ftps':
repo_sha256 = hashlib.sha256(template_uri.encode())
parsed_uri = urllib.parse.urlparse(manifest_uri)
if parsed_uri.scheme in ['http', 'https', 'ftp', 'ftps']:
repo_sha256 = hashlib.sha256(manifest_uri.encode())
cache_folder = manifest.get_o3de_cache_folder()
template_json = cache_folder / str(repo_sha256.hexdigest() + '.json')
manifest_json_path = cache_folder / str(repo_sha256.hexdigest() + '.json')
else:
template_json = pathlib.Path(template_uri).resolve() / 'template.json'
manifest_json_path = pathlib.Path(manifest_uri).resolve() / json_filename
with template_json.open('r') as f:
try:
template_json_data = json.load(f)
except json.JSONDecodeError as e:
logger.warn(f'{template_json} failed to load: {str(e)}')
else:
print(template_json)
print(json.dumps(template_json_data, indent=4))
print('\n')
json_data = get_json_func(**{get_json_data_kwargs: manifest_json_path})
if json_data:
print(manifest_json_path)
print(json.dumps(json_data, indent=4) + '\n')
return 0
def print_repos_data(repos_data: dict) -> None:
def print_repos_data(repos_data: dict) -> int:
print('\n')
print("Repos================================================")
cache_folder = manifest.get_o3de_cache_folder()
@ -251,29 +284,16 @@ def print_repos_data(repos_data: dict) -> None:
print(cache_file)
print(json.dumps(repo_json_data, indent=4))
print('\n')
def print_restricted_data(restricted_data: dict) -> None:
print('\n')
print("Restricted================================================")
for restricted_path in restricted_data:
restricted_json = pathlib.Path(restricted_path).resolve() / 'restricted.json'
with restricted_json.open('r') as f:
try:
restricted_json_data = json.load(f)
except json.JSONDecodeError as e:
logger.warn(f'{restricted_json} failed to load: {str(e)}')
else:
print(restricted_json)
print(json.dumps(restricted_json_data, indent=4))
print('\n')
return 0
def register_show_repos(verbose: int) -> None:
repos_data = get_repos()
repos_data = manifest.get_repos()
print(json.dumps(repos_data, indent=4))
if verbose > 0:
print_repos_data(repos_data)
return print_repos_data(repos_data) == 0
return 0
def register_show(verbose: int) -> None:
@ -281,13 +301,15 @@ def register_show(verbose: int) -> None:
print(f"{manifest.get_o3de_manifest()}:")
print(json.dumps(json_data, indent=4))
result = True
if verbose > 0:
print_engines_data(manifest.get_engines())
print_projects_data(manifest.get_all_projects())
print_gems_data(manifest.get_gems())
print_templates_data(manifest.get_all_templates())
print_restricted_data(manifest.get_all_restricted())
print_repos_data(manifest.get_repos())
result = print_manifest_json_data(manifest.get_engines()) == 0 and result
result = print_manifest_json_data(manifest.get_all_projects()) == 0 and result
result = print_manifest_json_data(manifest.get_gems()) == 0 and result
result = print_manifest_json_data(manifest.get_all_templates()) == 0 and result
result = print_manifest_json_data(manifest.get_all_restricted()) == 0 and result
result = print_repos_data(manifest.get_repos()) == 0 and result
return 0 if result else 1
def _run_register_show(args: argparse) -> int:
@ -295,75 +317,53 @@ def _run_register_show(args: argparse) -> int:
manifest.override_home_folder = args.override_home_folder
if args.this_engine:
print_this_engine(args.verbose)
return 0
return print_this_engine(args.verbose)
elif args.engines:
print_engines(args.verbose)
return 0
return print_engines(args.verbose)
elif args.projects:
print_projects(args.verbose)
return 0
return print_projects(args.verbose)
elif args.gems:
print_gems(args.verbose)
return 0
return print_gems(args.verbose)
elif args.templates:
print_templates(args.verbose)
return 0
return print_templates(args.verbose)
elif args.repos:
register_show_repos(args.verbose)
return 0
return register_show_repos(args.verbose)
elif args.restricted:
print_restricted(args.verbose)
return 0
return print_restricted(args.verbose)
elif args.engine_projects:
print_engine_projects(args.verbose)
return 0
return print_engine_projects(args.verbose)
elif args.engine_gems:
print_engine_gems(args.verbose)
return 0
return print_engine_gems(args.verbose)
elif args.engine_external_subdirectories:
return print_engine_external_subdirectories()
elif args.engine_templates:
print_engine_templates(args.verbose)
return 0
return print_engine_templates(args.verbose)
elif args.engine_restricted:
print_engine_restricted(args.verbose)
return 0
elif args.engine_external_subdirectories:
print_engine_external_subdirectories(args.verbose)
return 0
return print_engine_restricted(args.verbose)
elif args.project_gems:
return print_project_gems(args.verbose, args.project_path, args.project_name)
elif args.project_external_subdirectories:
return print_project_external_subdirectories(args.project_path, args.project_name)
elif args.project_templates:
return print_project_templates(args.verbose, args.project_path, args.project_name)
elif args.project_restricted:
return print_project_restricted(args.verbose, args.project_path, args.project_name)
elif args.all_projects:
print_all_projects(args.verbose)
return 0
return print_all_projects(args.verbose)
elif args.all_gems:
print_all_gems(args.verbose)
return 0
return print_all_gems(args.verbose)
elif args.all_external_subdirectories:
return print_all_external_subdirectories()
elif args.all_templates:
print_all_templates(args.verbose)
return 0
return print_all_templates(args.verbose)
elif args.all_restricted:
print_all_restricted(args.verbose)
return 0
return print_all_restricted(args.verbose)
elif args.downloadables:
print_downloadables(args.verbose)
return 0
if args.downloadable_engines:
print_downloadable_engines(args.verbose)
return 0
elif args.downloadable_projects:
print_downloadable_projects(args.verbose)
return 0
elif args.downloadable_gems:
print_downloadable_gems(args.verbose)
return 0
elif args.downloadable_templates:
print_downloadable_templates(args.verbose)
return 0
else:
register_show(args.verbose)
return 0
return register_show(args.verbose)
def add_parser_args(parser):
@ -376,76 +376,82 @@ def add_parser_args(parser):
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('-te', '--this-engine', action='store_true', required=False,
default=False,
help='Just the local engines.')
help='Output the current engine path.')
group.add_argument('-e', '--engines', action='store_true', required=False,
default=False,
help='Just the local engines.')
help='Output the engines registered in the global ~/.o3de/o3de_manifest.json.')
group.add_argument('-p', '--projects', action='store_true', required=False,
default=False,
help='Just the local projects.')
help='Output the projects registered in the global ~/.o3de/o3de_manifest.json.')
group.add_argument('-g', '--gems', action='store_true', required=False,
default=False,
help='Just the local gems.')
help='Output the gems registered in the global ~/.o3de/o3de_manifest.json.')
group.add_argument('-t', '--templates', action='store_true', required=False,
default=False,
help='Just the local templates.')
help='Output the templates registered in the global ~/.o3de/o3de_manifest.json.')
group.add_argument('-r', '--repos', action='store_true', required=False,
default=False,
help='Just the local repos. Ignores repos.')
help='Output the repos registered in the global ~/.o3de/o3de_manifest.json. Ignores repos.')
group.add_argument('-rs', '--restricted', action='store_true', required=False,
default=False,
help='The local restricted folders.')
help='Output the restricted directories registered in the global ~/.o3de/o3de_manifest.json.')
group.add_argument('-ep', '--engine-projects', action='store_true', required=False,
default=False,
help='Just the local projects. Ignores repos.')
help='Output the projects registered in the current engine engine.json. Ignores repos.')
group.add_argument('-eg', '--engine-gems', action='store_true', required=False,
default=False,
help='Just the local gems. Ignores repos')
help='Output the gems registered in the current engine engine.json. Ignores repos')
group.add_argument('-et', '--engine-templates', action='store_true', required=False,
default=False,
help='Just the local templates. Ignores repos.')
help='Output the templates registered in the current engine engine.json. Ignores repos.')
group.add_argument('-ers', '--engine-restricted', action='store_true', required=False,
default=False,
help='The restricted folders.')
group.add_argument('-x', '--engine-external-subdirectories', action='store_true', required=False,
help='Output the restricted directories registered in the current engine engine.json.')
group.add_argument('-ees', '--engine-external-subdirectories', action='store_true', required=False,
default=False,
help='The external subdirectories.')
help='Output the external subdirectories registered in the current engine engine.json.')
group.add_argument('-ap', '--all-projects', action='store_true', required=False,
group.add_argument('-pg', '--project-gems', action='store_true',
default=False,
help='Just the local projects. Ignores repos.')
group.add_argument('-ag', '--all-gems', action='store_true', required=False,
help='Returns the gems registered with the project.json.')
group.add_argument('-pt', '--project-templates', action='store_true',
default=False,
help='Just the local gems. Ignores repos')
group.add_argument('-at', '--all-templates', action='store_true', required=False,
help='Returns the templates registered with the project.json.')
group.add_argument('-prs', '--project-restricted', action='store_true',
default=False,
help='Just the local templates. Ignores repos.')
group.add_argument('-ars', '--all-restricted', action='store_true', required=False,
help='Returns the restricted directories registered with the project.json.')
group.add_argument('-pes', '--project-external-subdirectories', action='store_true',
default=False,
help='The restricted folders.')
help='Returns the external subdirectories register with the project.json.')
group.add_argument('-d', '--downloadables', action='store_true', required=False,
group.add_argument('-ap', '--all-projects', action='store_true', required=False,
default=False,
help='Combine all repos into a single list of resources.')
group.add_argument('-de', '--downloadable-engines', action='store_true', required=False,
help='Output all projects registered in the ~/.o3de/o3de_manifest.json and the current engine.json. Ignores repos.')
group.add_argument('-ag', '--all-gems', action='store_true', required=False,
default=False,
help='Combine all repos engines into a single list of resources.')
group.add_argument('-dp', '--downloadable-projects', action='store_true', required=False,
help='Output all gems registered in the ~/.o3de/o3de_manifest.json and the current engine.json. Ignores repos')
group.add_argument('-at', '--all-templates', action='store_true', required=False,
default=False,
help='Combine all repos projects into a single list of resources.')
group.add_argument('-dg', '--downloadable-gems', action='store_true', required=False,
help='Output all templates registered in the ~/.o3de/o3de_manifest.json and the current engine.json. Ignores repos.')
group.add_argument('-ares', '--all-restricted', action='store_true', required=False,
default=False,
help='Combine all repos gems into a single list of resources.')
group.add_argument('-dt', '--downloadable-templates', action='store_true', required=False,
help='Output all restricted directory registered in the ~/.o3de/o3de_manifest.json and the current engine.json.')
group.add_argument('-aes', '--all-external-subdirectories', action='store_true',
default=False,
help='Combine all repos templates into a single list of resources.')
help='Output all external subdirectories registered in the ~/.o3de/o3de_manifest.json and the current engine.json.')
parser.add_argument('-v', '--verbose', action='count', required=False,
default=0,
help='How verbose do you want the output to be.')
project_group = parser.add_mutually_exclusive_group(required=False)
project_group.add_argument('-pp', '--project-path', type=pathlib.Path,
help='The path to a project.')
project_group.add_argument('-pn', '--project-name', type=str,
help='The name of a project.')
parser.add_argument('-ohf', '--override-home-folder', type=str, required=False,
help='By default the home folder is the user folder, override it to this folder.')

@ -34,3 +34,10 @@ ly_add_pytest(
TEST_SUITE smoke
EXCLUDE_TEST_RUN_TARGET_FROM_IDE
)
ly_add_pytest(
NAME o3de_manifest
PATH ${CMAKE_CURRENT_LIST_DIR}/unit_test_manifest.py
TEST_SUITE smoke
EXCLUDE_TEST_RUN_TARGET_FROM_IDE
)

@ -0,0 +1,111 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
import argparse
import json
import logging
import pytest
import pathlib
from unittest.mock import patch
from o3de import manifest
@pytest.mark.parametrize("valid_project_json_paths, valid_gem_json_paths", [
pytest.param([pathlib.Path('D:/o3de/Templates/DefaultProject/Template/project.json')],
[pathlib.Path('D:/o3de/Templates/DefaultGem/Template/gem.json')])
])
class TestGetTemplatesForCreation:
@staticmethod
def get_templates() -> list:
return []
@staticmethod
def get_project_templates() -> list:
return []
@staticmethod
def get_engine_templates() -> list:
return [pathlib.Path('D:/o3de/Templates/DefaultProject'), pathlib.Path('D:/o3de/Templates/DefaultGem')]
@pytest.mark.parametrize("expected_template_paths", [
pytest.param([])
]
)
def test_get_templates_for_generic_creation(self, valid_project_json_paths, valid_gem_json_paths,
expected_template_paths):
def validate_project_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_project_json_paths
def validate_gem_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_gem_json_paths
with patch('o3de.manifest.get_templates', side_effect=self.get_templates) as get_templates_patch, \
patch('o3de.manifest.get_project_templates', side_effect=self.get_project_templates)\
as get_project_templates_patch, \
patch('o3de.manifest.get_engine_templates', side_effect=self.get_engine_templates)\
as get_engine_templates_patch, \
patch('o3de.validation.valid_o3de_template_json', return_value=True) as validate_template_json,\
patch('o3de.validation.valid_o3de_project_json', side_effect=validate_project_json) as validate_project_json,\
patch('o3de.validation.valid_o3de_gem_json', side_effect=validate_gem_json) as validate_gem_json:
templates = manifest.get_templates_for_generic_creation()
assert templates == expected_template_paths
@pytest.mark.parametrize("expected_template_paths", [
pytest.param([pathlib.Path('D:/o3de/Templates/DefaultProject')])
]
)
def test_get_templates_for_gem_creation(self, valid_project_json_paths, valid_gem_json_paths,
expected_template_paths):
def validate_project_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_project_json_paths
def validate_gem_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_gem_json_paths
with patch('o3de.manifest.get_templates', side_effect=self.get_templates) as get_templates_patch, \
patch('o3de.manifest.get_project_templates', side_effect=self.get_project_templates) \
as get_project_templates_patch, \
patch('o3de.manifest.get_engine_templates', side_effect=self.get_engine_templates) \
as get_engine_templates_patch, \
patch('o3de.validation.valid_o3de_template_json', return_value=True) as validate_template_json, \
patch('o3de.validation.valid_o3de_project_json',
side_effect=validate_project_json) as validate_project_json, \
patch('o3de.validation.valid_o3de_gem_json', side_effect=validate_gem_json) as validate_gem_json:
templates = manifest.get_templates_for_project_creation()
assert templates == expected_template_paths
@pytest.mark.parametrize("expected_template_paths", [
pytest.param([pathlib.Path('D:/o3de/Templates/DefaultGem')])
]
)
def test_get_templates_for_project_creation(self, valid_project_json_paths, valid_gem_json_paths,
expected_template_paths):
def validate_project_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_project_json_paths
def validate_gem_json(template_path) -> bool:
return pathlib.Path(template_path) in valid_gem_json_paths
with patch('o3de.manifest.get_templates', side_effect=self.get_templates) as get_templates_patch, \
patch('o3de.manifest.get_project_templates', side_effect=self.get_project_templates) \
as get_project_templates_patch, \
patch('o3de.manifest.get_engine_templates', side_effect=self.get_engine_templates) \
as get_engine_templates_patch, \
patch('o3de.validation.valid_o3de_template_json', return_value=True) as validate_template_json, \
patch('o3de.validation.valid_o3de_project_json',
side_effect=validate_project_json) as validate_project_json, \
patch('o3de.validation.valid_o3de_gem_json', side_effect=validate_gem_json) as validate_gem_json:
templates = manifest.get_templates_for_gem_creation()
assert templates == expected_template_paths

@ -11,7 +11,7 @@
import pytest
from . import utils
from o3de import utils
@pytest.mark.parametrize(
"value, expected_result", [

Loading…
Cancel
Save