Merge branch 'development' into Prism/RefreshGemRepos
This commit is contained in:
@@ -407,15 +407,12 @@ def create_template(source_path: pathlib.Path,
|
||||
source_name = os.path.basename(source_path)
|
||||
sanitized_source_name = utils.sanitize_identifier_for_cpp(source_name)
|
||||
|
||||
# if no template path, error
|
||||
# if no template path, use default_templates_folder path
|
||||
if not template_path:
|
||||
logger.info(f'Template path empty. Using source name {source_name}')
|
||||
template_path = pathlib.Path(source_name)
|
||||
if not template_path.is_absolute():
|
||||
default_templates_folder = manifest.get_registered(default_folder='templates')
|
||||
template_path = default_templates_folder / template_path
|
||||
logger.info(f'Template path not a full path. Using default templates folder {template_path}')
|
||||
if not force and template_path.is_dir():
|
||||
template_path = default_templates_folder / source_name
|
||||
logger.info(f'Template path empty. Using default templates folder {template_path}')
|
||||
if not force and template_path.is_dir() and len(list(template_path.iterdir())):
|
||||
logger.error(f'Template path {template_path} already exists.')
|
||||
return 1
|
||||
|
||||
@@ -1105,7 +1102,7 @@ def create_from_template(destination_path: pathlib.Path,
|
||||
logger.error(f'Could not find the template {template_name}=>{template_path}')
|
||||
return 1
|
||||
|
||||
# the template.json should be in the template_path, make sure it's there a nd valid
|
||||
# the template.json should be in the template_path, make sure it is valid
|
||||
template_json = template_path / 'template.json'
|
||||
if not validation.valid_o3de_template_json(template_json):
|
||||
logger.error(f'Template json {template_path} is invalid.')
|
||||
@@ -1254,7 +1251,7 @@ def create_from_template(destination_path: pathlib.Path,
|
||||
# destination restricted path
|
||||
elif destination_restricted_path:
|
||||
if os.path.isabs(destination_restricted_path):
|
||||
restricted_default_path = manifest.get_registered(default='restricted')
|
||||
restricted_default_path = manifest.get_registered(default_folder='restricted')
|
||||
new_destination_restricted_path = restricted_default_path / destination_restricted_path
|
||||
logger.info(f'{destination_restricted_path} is not a full path, making it relative'
|
||||
f' to default restricted path = {new_destination_restricted_path}')
|
||||
@@ -1346,7 +1343,7 @@ def create_project(project_path: pathlib.Path,
|
||||
Template instantiation specialization that makes all default assumptions for a Project template instantiation,
|
||||
reducing the effort needed in instancing a project
|
||||
:param project_path: the project path, can be absolute or relative to default projects path
|
||||
:param project_name: the project name, defaults to project_path basename if not provided
|
||||
:param project_name: the project name, defaults to project_path basename if not provided
|
||||
:param template_path: the path to the template you want to instance, can be absolute or relative to default templates path
|
||||
:param template_name: the name the registered template you want to instance, defaults to DefaultProject, resolves template_path
|
||||
:param project_restricted_path: path to the projects restricted folder, can be absolute or relative to the restricted='projects'
|
||||
@@ -1523,13 +1520,9 @@ def create_project(project_path: pathlib.Path,
|
||||
if not project_path:
|
||||
logger.error('Project path cannot be empty.')
|
||||
return 1
|
||||
if not os.path.isabs(project_path):
|
||||
default_projects_folder = manifest.get_registered(default_folder='projects')
|
||||
new_project_path = default_projects_folder / project_path
|
||||
logger.info(f'Project Path {project_path} is not a full path, we must assume its relative'
|
||||
f' to default projects path = {new_project_path}')
|
||||
project_path = new_project_path
|
||||
if not force and os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
||||
|
||||
project_path = project_path.resolve()
|
||||
if not force and project_path.is_dir() and len(list(project_path.iterdir())):
|
||||
logger.error(f'Project path {project_path} already exists and is not empty.')
|
||||
return 1
|
||||
elif not os.path.isdir(project_path):
|
||||
@@ -1904,14 +1897,10 @@ def create_gem(gem_path: pathlib.Path,
|
||||
if not gem_path:
|
||||
logger.error('Gem path cannot be empty.')
|
||||
return 1
|
||||
if not os.path.isabs(gem_path):
|
||||
default_gems_folder = manifest.get_registered(default_folder='gems')
|
||||
new_gem_path = default_gems_folder / gem_path
|
||||
logger.info(f'Gem Path {gem_path} is not a full path, we must assume its relative'
|
||||
f' to default gems path = {new_gem_path}')
|
||||
gem_path = new_gem_path
|
||||
if not force and os.path.isdir(gem_path):
|
||||
logger.error(f'Gem path {gem_path} already exists.')
|
||||
|
||||
gem_path = gem_path.resolve()
|
||||
if not force and gem_path.is_dir() and len(list(gem_path.iterdir())):
|
||||
logger.error(f'Gem path {gem_path} already exists and is not empty.')
|
||||
return 1
|
||||
else:
|
||||
os.makedirs(gem_path, exist_ok=force)
|
||||
@@ -1936,16 +1925,18 @@ def create_gem(gem_path: pathlib.Path,
|
||||
# gem restricted path
|
||||
elif gem_restricted_path:
|
||||
if not os.path.isabs(gem_restricted_path):
|
||||
default_gems_restricted_folder = manifest.get_registered(restricted_name='gems')
|
||||
new_gem_restricted_path = default_gems_restricted_folder /gem_restricted_path
|
||||
logger.info(f'Gem restricted path {gem_restricted_path} is not a full path, we must assume its'
|
||||
f' relative to default gems restricted path = {new_gem_restricted_path}')
|
||||
gem_restricted_path = new_gem_restricted_path
|
||||
elif template_restricted_path:
|
||||
gem_restricted_default_path = manifest.get_registered(restricted_name='gems')
|
||||
if gem_restricted_default_path:
|
||||
new_gem_restricted_path = gem_restricted_default_path / gem_restricted_path
|
||||
logger.info(f'Gem restricted path {gem_restricted_path} is not a full path, we must assume its'
|
||||
f' relative to default gems restricted path = {new_gem_restricted_path}')
|
||||
gem_restricted_path = new_gem_restricted_path
|
||||
else:
|
||||
gem_restricted_default_path = manifest.get_registered(restricted_name='gems')
|
||||
logger.info(f'--gem-restricted-path is not specified, using default gem restricted path / gem name'
|
||||
f' = {gem_restricted_default_path}')
|
||||
gem_restricted_path = gem_restricted_default_path
|
||||
if gem_restricted_default_path:
|
||||
logger.info(f'--gem-restricted-path is not specified, using default <gem restricted path> / <gem name>'
|
||||
f' = {gem_restricted_default_path}')
|
||||
gem_restricted_path = gem_restricted_default_path / gem_name
|
||||
|
||||
# gem restricted relative
|
||||
if not gem_restricted_platform_relative_path:
|
||||
@@ -1964,7 +1955,7 @@ def create_gem(gem_path: pathlib.Path,
|
||||
replacements.append(("${NameUpper}", gem_name.upper()))
|
||||
replacements.append(("${NameLower}", gem_name.lower()))
|
||||
replacements.append(("${SanitizedCppName}", sanitized_cpp_name))
|
||||
|
||||
|
||||
|
||||
# module id is a uuid with { and -
|
||||
if module_id:
|
||||
@@ -2244,14 +2235,14 @@ def add_args(subparsers) -> None:
|
||||
create_from_template_subparser = subparsers.add_parser('create-from-template')
|
||||
create_from_template_subparser.add_argument('-dp', '--destination-path', type=pathlib.Path, required=True,
|
||||
help='The path to where you want the template instantiated,'
|
||||
' can be absolute or dev root relative.'
|
||||
' can be absolute or relative to the current working directory.'
|
||||
'Ex. C:/o3de/Test'
|
||||
'Test = <destination_name>')
|
||||
|
||||
group = create_from_template_subparser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('-tp', '--template-path', type=pathlib.Path, required=False,
|
||||
help='The path to the template you want to instantiate, can be absolute'
|
||||
' or dev root/Templates relative.'
|
||||
' or relative to the current working directory.'
|
||||
'Ex. C:/o3de/Template/TestTemplate'
|
||||
'TestTemplate = <template_name>')
|
||||
group.add_argument('-tn', '--template-name', type=str, required=False,
|
||||
@@ -2327,7 +2318,7 @@ def add_args(subparsers) -> None:
|
||||
create_project_subparser = subparsers.add_parser('create-project')
|
||||
create_project_subparser.add_argument('-pp', '--project-path', type=pathlib.Path, required=True,
|
||||
help='The location of the project you wish to create from the template,'
|
||||
' can be an absolute path or dev root relative.'
|
||||
' can be an absolute path or relative to the current working directory.'
|
||||
' Ex. C:/o3de/TestProject'
|
||||
' TestProject = <project_name> if --project-name not provided')
|
||||
create_project_subparser.add_argument('-pn', '--project-name', type=str, required=False,
|
||||
@@ -2349,8 +2340,8 @@ def add_args(subparsers) -> None:
|
||||
group = create_project_subparser.add_mutually_exclusive_group(required=False)
|
||||
group.add_argument('-prp', '--project-restricted-path', type=pathlib.Path, required=False,
|
||||
default=None,
|
||||
help='path to the projects restricted folder, can be absolute or relative'
|
||||
' to the restricted="projects"')
|
||||
help='path to the projects restricted folder, can be absolute or relative to'
|
||||
' the default restricted projects directory')
|
||||
group.add_argument('-prn', '--project-restricted-name', type=str, required=False,
|
||||
default=None,
|
||||
help='The name of the registered projects restricted path. If supplied this will resolve'
|
||||
@@ -2360,7 +2351,7 @@ def add_args(subparsers) -> None:
|
||||
group.add_argument('-trp', '--template-restricted-path', type=pathlib.Path, required=False,
|
||||
default=None,
|
||||
help='The templates restricted path can be absolute or relative to'
|
||||
' restricted="templates"')
|
||||
'the default restricted templates directory')
|
||||
group.add_argument('-trn', '--template-restricted-name', type=str, required=False,
|
||||
default=None,
|
||||
help='The name of the registered templates restricted path. If supplied this will resolve'
|
||||
@@ -2423,7 +2414,7 @@ def add_args(subparsers) -> None:
|
||||
# creation of a gem from a template (like create from template but makes gem assumptions)
|
||||
create_gem_subparser = subparsers.add_parser('create-gem')
|
||||
create_gem_subparser.add_argument('-gp', '--gem-path', type=pathlib.Path, required=True,
|
||||
help='The gem path, can be absolute or relative to default gems path')
|
||||
help='The gem path, can be absolute or relative to the current working directory')
|
||||
create_gem_subparser.add_argument('-gn', '--gem-name', type=str,
|
||||
help='The name to use when substituting the ${Name} placeholder for the gem,'
|
||||
' must be alphanumeric, '
|
||||
@@ -2444,19 +2435,18 @@ def add_args(subparsers) -> None:
|
||||
group = create_gem_subparser.add_mutually_exclusive_group(required=False)
|
||||
group.add_argument('-grp', '--gem-restricted-path', type=pathlib.Path, required=False,
|
||||
default=None,
|
||||
help='The path to the gem restricted to write to folder if any, can be'
|
||||
'absolute or dev root relative, default is dev root/restricted.')
|
||||
help='The gem restricted path, can be absolute or relative to'
|
||||
' the default restricted gems directory')
|
||||
group.add_argument('-grn', '--gem-restricted-name', type=str, required=False,
|
||||
default=None,
|
||||
help='The path to the gem restricted to write to folder if any, can be'
|
||||
'absolute or dev root relative, default is dev root/restricted. If supplied'
|
||||
' this will resolve the --gem-restricted-path.')
|
||||
help='The name of the gem to look up the gem restricted path if any.'
|
||||
'If supplied this will resolve the --gem-restricted-path.')
|
||||
|
||||
group = create_gem_subparser.add_mutually_exclusive_group(required=False)
|
||||
group.add_argument('-trp', '--template-restricted-path', type=pathlib.Path, required=False,
|
||||
default=None,
|
||||
help='The templates restricted path, can be absolute or relative to'
|
||||
' the restricted="templates"')
|
||||
' the default restricted templates directory')
|
||||
group.add_argument('-trn', '--template-restricted-name', type=str, required=False,
|
||||
default=None,
|
||||
help='The name of the registered templates restricted path. If supplied'
|
||||
|
||||
@@ -467,7 +467,7 @@ def register_restricted_path(json_data: dict,
|
||||
|
||||
|
||||
def register_repo(json_data: dict,
|
||||
repo_uri: str or pathlib.Path,
|
||||
repo_uri: str,
|
||||
remove: bool = False) -> int:
|
||||
if not repo_uri:
|
||||
logger.error(f'Repo URI cannot be empty.')
|
||||
@@ -480,9 +480,9 @@ def register_repo(json_data: dict,
|
||||
while repo_uri in json_data['repos']:
|
||||
json_data['repos'].remove(repo_uri)
|
||||
else:
|
||||
repo_uri = pathlib.Path(repo_uri).resolve()
|
||||
while repo_uri.as_posix() in json_data['repos']:
|
||||
json_data['repos'].remove(repo_uri.as_posix())
|
||||
repo_uri = pathlib.Path(repo_uri).resolve().as_posix()
|
||||
while repo_uri in json_data['repos']:
|
||||
json_data['repos'].remove(repo_uri)
|
||||
|
||||
if remove:
|
||||
logger.warn(f'Removing repo uri {repo_uri}.')
|
||||
@@ -566,7 +566,7 @@ def register(engine_path: pathlib.Path = None,
|
||||
external_subdir_path: pathlib.Path = None,
|
||||
template_path: pathlib.Path = None,
|
||||
restricted_path: pathlib.Path = None,
|
||||
repo_uri: str or pathlib.Path = None,
|
||||
repo_uri: str = None,
|
||||
default_engines_folder: pathlib.Path = None,
|
||||
default_projects_folder: pathlib.Path = None,
|
||||
default_gems_folder: pathlib.Path = None,
|
||||
@@ -641,7 +641,7 @@ def register(engine_path: pathlib.Path = None,
|
||||
return 1
|
||||
result = result or register_restricted_path(json_data, restricted_path, remove, project_path, engine_path)
|
||||
|
||||
if isinstance(repo_uri, str) or isinstance(repo_uri, pathlib.PurePath):
|
||||
if isinstance(repo_uri, str):
|
||||
if not repo_uri:
|
||||
logger.error(f'Repo URI cannot be empty.')
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user