Pārlūkot izejas kodu

Adding CLI script for modifying project properties (LYN-3918). Updating O3de to support it.
Fixing some typo errors in manifest.py and minor optimizations

mgwynn 4 gadi atpakaļ
vecāks
revīzija
35fed77223

+ 5 - 2
scripts/o3de.py

@@ -32,7 +32,7 @@ def add_args(parser, subparsers) -> None:
     # add the scripts/o3de directory to the front of the sys.path
     sys.path.insert(0, str(o3de_package_dir))
     from o3de import engine_template, global_project, register, print_registration, get_registration, \
-        enable_gem, disable_gem, sha256
+        enable_gem, disable_gem, project_properties, sha256
     # Remove the temporarily added path
     sys.path = sys.path[1:]
 
@@ -55,7 +55,10 @@ def add_args(parser, subparsers) -> None:
 
     # remove a gem from a project
     disable_gem.add_args(subparsers)
-
+    
+    # modify project properties 
+    project_properties.add_args(subparsers)
+    
     # sha256
     sha256.add_args(subparsers)
 

+ 3 - 9
scripts/o3de/o3de/manifest.py

@@ -573,9 +573,7 @@ def get_registered(engine_name: str = None,
                         return engine_path
 
     elif isinstance(project_name, str):
-        enging_projects = get_engine_projects()
-        projects = json_data['projects'].copy()
-        projects.extend(engine_object['projects'])
+        projects = get_all_projects()
         for project_path in projects:
             project_path = pathlib.Path(project_path).resolve()
             project_json = project_path / 'project.json'
@@ -605,9 +603,7 @@ def get_registered(engine_name: str = None,
                         return gem_path
 
     elif isinstance(template_name, str):
-        engine_templates = get_engine_templates()
-        templates = json_data['templates'].copy()
-        templates.extend(engine_templates)
+        templates = get_all_templates()
         for template_path in templates:
             template_path = pathlib.Path(template_path).resolve()
             template_json = template_path / 'template.json'
@@ -622,9 +618,7 @@ def get_registered(engine_name: str = None,
                         return template_path
 
     elif isinstance(restricted_name, str):
-        engine_restricted = get_engine_restricted()
-        restricted = json_data['restricted'].copy()
-        restricted.extend(engine_restricted)
+        restricted = get_all_restricted()
         for restricted_path in restricted:
             restricted_path = pathlib.Path(restricted_path).resolve()
             restricted_json = restricted_path / 'restricted.json'

+ 82 - 0
scripts/o3de/o3de/project_properties.py

@@ -0,0 +1,82 @@
+import argparse
+import json
+import os
+import pathlib
+import sys
+import logging
+
+from o3de import manifest
+
+logger = logging.getLogger()
+logging.basicConfig()
+
+def get_project_props(name: str = None, path: pathlib.Path = None) -> dict:
+    proj_json = manifest.get_project_json_data(project_name=name, project_path=path)
+    if not proj_json:
+        logger.error('Could not retrieve project.json file')
+        return None
+    return proj_json
+
+def edit_project_props(proj_path, proj_name, new_origin, new_display,
+                       new_summary, new_icon, new_tag) -> int:
+    proj_json = get_project_props(proj_name, proj_path)
+    
+    try:
+        if new_origin and 'origin' in proj_json:
+            proj_json['origin'] = new_origin
+        if new_display and 'display_name' in proj_json:
+            proj_json['display_name'] = new_display
+        if new_summary and 'summary' in proj_json:
+            proj_json['summary'] = new_summary
+        if new_icon and 'icon_path' in proj_json:
+            proj_json['icon_path'] = new_icon
+        if new_tag and 'user_tags' in proj_json:
+            proj_json['user_tags'].append(new_tag)
+    except Exception as e:
+        logger.error(e)
+        return 1
+
+    manifest.save_o3de_manifest(proj_json, pathlib.Path(proj_path)/'project.json')
+    return 0
+
+def _edit_project_props(args: argparse) -> int:
+    return edit_project_props(args.project_path,
+                              args.project_name,
+                               args.project_origin,
+                               args.project_display,
+                               args.project_summary,
+                               args.project_icon,
+                               args.project_tag)
+
+def add_parser_args(parser):
+    group = parser.add_mutually_exclusive_group(required=True)
+    group.add_argument('-pp', '--project-path', type=pathlib.Path, required=False,
+                       help='The path to the project.')
+    group.add_argument('-pn', '--project-name', type=str, required=False,
+                       help='The name of the project.')
+    group = parser.add_argument_group('properties', 'arguments for modifying individual project properties.')
+    group.add_argument('-po', '--project-origin', type=str, required=False,
+                       help='Sets description or url for project origin.')
+    group.add_argument('-pd', '--project-display', type=str, required=False,
+                       help='Sets the project display name.')
+    group.add_argument('-ps', '--project-summary', type=str, required=False,
+                       help='Sets the summary description of the project.')
+    group.add_argument('-pi', '--project-icon', type=str, required=False,
+                       help='Sets the path to the projects icon resource.')
+    group.add_argument('-pt', '--project-tag', type=str, required=False,
+                       help='Adds a tag to canonical user tags.')
+    parser.set_defaults(func=_edit_project_props)
+
+def add_args(subparsers) -> None:
+    enable_project_props_subparser = subparsers.add_parser('edit-project-props')
+    add_parser_args(enable_project_props_subparser)
+    
+def main():
+    the_parser = argparse.ArgumentParser()
+    add_parser_args(the_parser)
+    the_args = the_parser.parse_args()
+    ret = the_args.func(the_args) if hasattr(the_args, 'func') else 1
+    sys.exit(ret)
+
+if __name__ == "__main__":
+    main()