From 6d6f8413c8fa260ff2dec8dc1aaa674125a915ad Mon Sep 17 00:00:00 2001 From: mgwynn Date: Mon, 7 Jun 2021 14:14:32 -0400 Subject: [PATCH] Incorporating review comments. Some parameter modifications. Some cli edge case handling. Remove remove_tag member from project info --- .../ProjectManager/Source/ProjectInfo.cpp | 2 - .../Tools/ProjectManager/Source/ProjectInfo.h | 14 ++++--- .../ProjectManager/Source/PythonBindings.cpp | 20 +++++----- scripts/o3de/o3de/project_properties.py | 39 +++++++++++-------- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Code/Tools/ProjectManager/Source/ProjectInfo.cpp b/Code/Tools/ProjectManager/Source/ProjectInfo.cpp index 85716fccfa..99649cbfdf 100644 --- a/Code/Tools/ProjectManager/Source/ProjectInfo.cpp +++ b/Code/Tools/ProjectManager/Source/ProjectInfo.cpp @@ -26,8 +26,6 @@ namespace O3DE::ProjectManager , m_backgroundImagePath(backgroundImagePath) , m_needsBuild(needsBuild) { - m_userTags = QStringList(); - m_userTagsForRemoval = QStringList(); } bool ProjectInfo::operator==(const ProjectInfo& rhs) diff --git a/Code/Tools/ProjectManager/Source/ProjectInfo.h b/Code/Tools/ProjectManager/Source/ProjectInfo.h index 47a10dbc14..184916a514 100644 --- a/Code/Tools/ProjectManager/Source/ProjectInfo.h +++ b/Code/Tools/ProjectManager/Source/ProjectInfo.h @@ -25,8 +25,15 @@ namespace O3DE::ProjectManager public: ProjectInfo() = default; - ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, const QString& origin, - const QString& summary, const QString& imagePath, const QString& backgroundImagePath, bool needsBuild + ProjectInfo( + const QString& path, + const QString& projectName, + const QString& displayName, + const QString& origin, + const QString& summary, + const QString& imagePath, + const QString& backgroundImagePath, + bool needsBuild); bool operator==(const ProjectInfo& rhs); bool operator!=(const ProjectInfo& rhs); @@ -49,9 +56,6 @@ namespace O3DE::ProjectManager // Used in project creation - // Used to flag tags for removal - QStringList m_userTagsForRemoval; - bool m_needsBuild = false; //! Does this project need to be built }; } // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 9fa10ce3d8..fe01209172 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -53,6 +53,7 @@ namespace Platform #define Py_To_String(obj) obj.cast().c_str() #define Py_To_String_Optional(dict, key, default_string) dict.contains(key) ? Py_To_String(dict[key]) : default_string +#define Py_To_List(obj) obj.cast> namespace RedirectOutput { @@ -678,6 +679,12 @@ namespace O3DE::ProjectManager { projectInfo.m_projectName = Py_To_String(projectData["project_name"]); projectInfo.m_displayName = Py_To_String_Optional(projectData, "display_name", projectInfo.m_projectName); + projectInfo.m_origin = Py_To_String_Optional(projectData, "origin", projectInfo.m_origin); + projectInfo.m_summary = Py_To_String_Optional(projectData, "summary", projectInfo.m_summary); + for (const auto& tag : projectData["user_tags"]) + { + projectInfo.m_userTags.append(Py_To_String(tag)); + } } catch ([[maybe_unused]] const std::exception& e) { @@ -753,17 +760,11 @@ namespace O3DE::ProjectManager return ExecuteWithLockErrorHandling([&] { std::list newTags; - for (auto& i : projectInfo.m_userTags) + for (const auto& i : projectInfo.m_userTags) { newTags.push_back(i.toStdString()); } - std::list removedTags; - for (auto& i : projectInfo.m_userTagsForRemoval) - { - removedTags.push_back(i.toStdString()); - } - m_editProjectProperties.attr("edit_project_props")( pybind11::str(projectInfo.m_path.toStdString()), // proj_path pybind11::none(), // proj_name not used @@ -771,8 +772,9 @@ namespace O3DE::ProjectManager pybind11::str(projectInfo.m_displayName.toStdString()), // new_display pybind11::str(projectInfo.m_summary.toStdString()), // new_summary pybind11::str(projectInfo.m_imagePath.toStdString()), // new_icon - pybind11::list(pybind11::cast(newTags)), // new_tag - pybind11::list(pybind11::cast(removedTags))); // remove_tag + pybind11::none(), // add_tags not used + pybind11::none(), // remove_tags not used + pybind11::list(pybind11::cast(newTags))); // replace_tags }); } diff --git a/scripts/o3de/o3de/project_properties.py b/scripts/o3de/o3de/project_properties.py index 83e76fc18f..b2268131c0 100644 --- a/scripts/o3de/o3de/project_properties.py +++ b/scripts/o3de/o3de/project_properties.py @@ -30,7 +30,7 @@ def get_project_props(name: str = None, path: pathlib.Path = None) -> dict: return proj_json def edit_project_props(proj_path, proj_name, new_origin, new_display, - new_summary, new_icon, new_tag, remove_tag) -> int: + new_summary, new_icon, new_tags, delete_tags, replace_tags) -> int: proj_json = get_project_props(proj_name, proj_path) if not proj_json: @@ -44,18 +44,22 @@ def edit_project_props(proj_path, proj_name, new_origin, new_display, proj_json['summary'] = new_summary if new_icon: proj_json['icon_path'] = new_icon - if new_tag: - for tag in new_tag: - proj_json.setdefault('user_tags', []).append(tag) - if remove_tag: + if new_tags: + tag_list = [new_tags] if isinstance(new_tags, str) else new_tags + proj_json.setdefault('user_tags', []).extend(tag_list) + if delete_tags: + removal_list = [delete_tags] if isinstance(delete_tags, str) else delete_tags if 'user_tags' in proj_json: - for del_tag in remove_tag: - if del_tag in proj_json['user_tags']: - proj_json['user_tags'].remove(del_tag) + for tag in removal_list: + if tag in proj_json['user_tags']: + proj_json['user_tags'].remove(tag) else: - logger.warn(f'{del_tag} not found in user_tags for removal.') + logger.warn(f'{tag} not found in user_tags for removal.') else: - logger.warn(f'user_tags property not found for removal of {remove_tag}.') + logger.warn(f'user_tags property not found for removal of {remove_tags}.') + if replace_tags: + tag_list = [replace_tags] if isinstance(replace_tags, str) else replace_tags + proj_json['user_tags'] = tag_list manifest.save_o3de_manifest(proj_json, pathlib.Path(proj_path) / 'project.json') return 0 @@ -67,8 +71,9 @@ def _edit_project_props(args: argparse) -> int: args.project_display, args.project_summary, args.project_icon, - args.project_tag, - args.remove_tag) + args.add_tags, + args.delete_tags, + args.replace_tags) def add_parser_args(parser): group = parser.add_mutually_exclusive_group(required=True) @@ -85,10 +90,12 @@ def add_parser_args(parser): 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=default, required=False, - help='Adds tag(s) to user_tags property. These tags are intended for documentation and filtering.') - group.add_argument('-rt', '--remove-tag', type=default, required=False, - help='Removes tag(s) from the user_tags property.') + group.add_argument('-at', '--add-tags', type=str, nargs='*', required=False, + help='Adds tag(s) to user_tags property. Space delimited list (ex. -at A B C)') + group.add_argument('-dt', '--delete-tags', type=str, nargs ='*', required=False, + help='Removes tag(s) from the user_tags property. Space delimited list (ex. -dt A B C') + group.add_argument('-rt', '--replace-tags', type=str, nargs ='*', required=False, + help='Replace entirety of user_tags proeprty with space delimited list of values') parser.set_defaults(func=_edit_project_props) def add_args(subparsers) -> None: