From 7984f82e481b2ddac0a8ebb7f2b28b4aa9d8f9d8 Mon Sep 17 00:00:00 2001 From: mgwynn Date: Fri, 4 Jun 2021 23:03:17 -0400 Subject: [PATCH] Bing project_properties CLI to updateProject method. Update project info struct. Update project properties cli to support lists for tags. Minor adjustments to support changes. --- .../ProjectManager/Source/ProjectInfo.cpp | 7 ++- .../Tools/ProjectManager/Source/ProjectInfo.h | 13 ++++-- .../ProjectManager/Source/PythonBindings.cpp | 45 +++++++++++-------- .../ProjectManager/Source/PythonBindings.h | 7 +-- .../Source/PythonBindingsInterface.h | 21 +-------- .../Source/UpdateProjectCtrl.cpp | 6 +-- scripts/o3de/o3de/project_properties.py | 22 ++++----- 7 files changed, 59 insertions(+), 62 deletions(-) diff --git a/Code/Tools/ProjectManager/Source/ProjectInfo.cpp b/Code/Tools/ProjectManager/Source/ProjectInfo.cpp index f0dc05cc62..f470841f09 100644 --- a/Code/Tools/ProjectManager/Source/ProjectInfo.cpp +++ b/Code/Tools/ProjectManager/Source/ProjectInfo.cpp @@ -15,14 +15,19 @@ namespace O3DE::ProjectManager { ProjectInfo::ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, - const QString& imagePath, const QString& backgroundImagePath, bool isNew) + const QString& origin, const QString& summary, const QString& imagePath, const QString& backgroundImagePath, + bool isNew) : m_path(path) , m_projectName(projectName) , m_displayName(displayName) + , m_origin(origin) + , m_summary(summary) , m_imagePath(imagePath) , m_backgroundImagePath(backgroundImagePath) , m_isNew(isNew) { + 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 71fa12b344..699d0997c6 100644 --- a/Code/Tools/ProjectManager/Source/ProjectInfo.h +++ b/Code/Tools/ProjectManager/Source/ProjectInfo.h @@ -15,6 +15,7 @@ #if !defined(Q_MOC_RUN) #include #include +#include #endif namespace O3DE::ProjectManager @@ -23,8 +24,8 @@ namespace O3DE::ProjectManager { public: ProjectInfo() = default; - ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, - const QString& imagePath, const QString& backgroundImagePath, bool isNew); + ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, const QString& origin, + const QString& summary, const QString& imagePath, const QString& backgroundImagePath, bool isNew); bool operator==(const ProjectInfo& rhs); bool operator!=(const ProjectInfo& rhs); @@ -36,12 +37,18 @@ namespace O3DE::ProjectManager // From project.json QString m_projectName; QString m_displayName; + QString m_origin; + QString m_summary; + QStringList m_userTags; // Used on projects home screen QString m_imagePath; - QString m_backgroundImagePath; + QStringList m_backgroundImagePath; // Used in project creation bool m_isNew = false; //! Is this a new project or existing + + // Used to flag tags for removal + QStringList m_userTagsForRemoval; }; } // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 0acbf8ffaf..16bcd6e122 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #pragma pop_macro("slots") #include @@ -687,23 +688,6 @@ namespace O3DE::ProjectManager return projectInfo; } - AZ::Outcome PythonBindings::ModifyProjectProperties(const QString& path, const QString& origin, const QString& displayName, - const QString& summary, const QString& icon, const QString& addTag, const QString& removeTag) - { - return ExecuteWithLockErrorHandling([&] - { - m_editProjectProperties.attr("edit_project_props")( - pybind11::str(path.toStdString()), //proj_path - pybind11::none(), //proj_name not used - origin.isNull() ? pybind11::none() : pybind11::str(origin.toStdString()), //new_origin - displayName.isNull() ? pybind11::none() : pybind11::str(displayName.toStdString()), //new_display - summary.isNull() ? pybind11::none() : pybind11::str(summary.toStdString()), //new_summary - icon.isNull() ? pybind11::none() : pybind11::str(icon.toStdString()), //new_icon - addTag.isNull() ? pybind11::none() : pybind11::str(addTag.toStdString()), //new_tag - removeTag.isNull() ? pybind11::none() : pybind11::str(removeTag.toStdString())); //remove_tag - }); - } - AZ::Outcome> PythonBindings::GetProjects() { QVector projects; @@ -764,9 +748,32 @@ namespace O3DE::ProjectManager }); } - bool PythonBindings::UpdateProject([[maybe_unused]] const ProjectInfo& projectInfo) + AZ::Outcome PythonBindings::UpdateProject(const ProjectInfo& projectInfo) { - return false; + return ExecuteWithLockErrorHandling([&] + { + std::list newTags; + for (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 + pybind11::str(projectInfo.m_origin.toStdString()), // new_origin + 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 + }); } ProjectTemplateInfo PythonBindings::ProjectTemplateInfoFromPath(pybind11::handle path) diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.h b/Code/Tools/ProjectManager/Source/PythonBindings.h index 5f03d0ab28..707595b6fd 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.h +++ b/Code/Tools/ProjectManager/Source/PythonBindings.h @@ -50,14 +50,9 @@ namespace O3DE::ProjectManager AZ::Outcome> GetProjects() override; bool AddProject(const QString& path) override; bool RemoveProject(const QString& path) override; - bool UpdateProject(const ProjectInfo& projectInfo) override; + AZ::Outcome UpdateProject(const ProjectInfo& projectInfo) override; AZ::Outcome AddGemToProject(const QString& gemPath, const QString& projectPath) override; AZ::Outcome RemoveGemFromProject(const QString& gemPath, const QString& projectPath) override; - AZ::Outcome ModifyProjectProperties( - const QString& path, - const QString& origin = 0, - const QString& displayName = 0, - const QString& summary = 0, const QString& icon = 0, const QString& addTag = 0, const QString& removeTag = 0) override; // ProjectTemplate AZ::Outcome> GetProjectTemplates() override; diff --git a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h index edc9510236..fd94a4e964 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h +++ b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h @@ -122,7 +122,7 @@ namespace O3DE::ProjectManager * @param projectInfo the info to use to update the project * @return true on success, false on failure */ - virtual bool UpdateProject(const ProjectInfo& projectInfo) = 0; + virtual AZ::Outcome UpdateProject(const ProjectInfo& projectInfo) = 0; /** * Add a gem to a project @@ -132,25 +132,6 @@ namespace O3DE::ProjectManager */ virtual AZ::Outcome AddGemToProject(const QString& gemPath, const QString& projectPath) = 0; - /** - * Change property in project json file - * @param path the absolute path to the gem - * @param origin the description or url for project origin (such as project host, repository, owner...etc) - * @param displayName the project display name - * @param summary short description of the project - * @param icon image used to represent the project - * @param addTag user tag to be added - * @param removeTag user tag to be removed - */ - virtual AZ::Outcome ModifyProjectProperties( - const QString& path, - const QString& origin = 0, - const QString& displayName = 0, - const QString& summary = 0, - const QString& icon = 0, - const QString& addTag = 0, - const QString& removeTag = 0) = 0; - /** * Remove gem to a project * @param gemPath the absolute path to the gem diff --git a/Code/Tools/ProjectManager/Source/UpdateProjectCtrl.cpp b/Code/Tools/ProjectManager/Source/UpdateProjectCtrl.cpp index a383a0f93b..19078f65ea 100644 --- a/Code/Tools/ProjectManager/Source/UpdateProjectCtrl.cpp +++ b/Code/Tools/ProjectManager/Source/UpdateProjectCtrl.cpp @@ -134,10 +134,10 @@ namespace O3DE::ProjectManager // Update project if settings changed if (m_projectInfo != newProjectSettings) { - bool result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings); - if (!result) + auto result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings); + if (!result.IsSuccess()) { - QMessageBox::critical(this, tr("Project update failed"), tr("Failed to update project.")); + QMessageBox::critical(this, tr("Project update failed"), tr(result.GetError().c_str())); return; } } diff --git a/scripts/o3de/o3de/project_properties.py b/scripts/o3de/o3de/project_properties.py index 69bd1b9406..83e76fc18f 100644 --- a/scripts/o3de/o3de/project_properties.py +++ b/scripts/o3de/o3de/project_properties.py @@ -45,15 +45,17 @@ def edit_project_props(proj_path, proj_name, new_origin, new_display, if new_icon: proj_json['icon_path'] = new_icon if new_tag: - proj_json.setdefault('user_tags', []).append(new_tag) + for tag in new_tag: + proj_json.setdefault('user_tags', []).append(tag) if remove_tag: if 'user_tags' in proj_json: - if remove_tag in proj_json['user_tags']: - proj_json['user_tags'].remove(remove_tag) - else: - logger.warn(f'{remove_tag} not found in user_tags for removal.') + for del_tag in remove_tag: + if del_tag in proj_json['user_tags']: + proj_json['user_tags'].remove(del_tag) + else: + logger.warn(f'{del_tag} not found in user_tags for removal.') else: - logger.warn(f'user_tags property not found for removal of tag {remove_tag}.') + logger.warn(f'user_tags property not found for removal of {remove_tag}.') manifest.save_o3de_manifest(proj_json, pathlib.Path(proj_path) / 'project.json') return 0 @@ -83,10 +85,10 @@ 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=str, required=False, - help='Adds a tag to user_tags property. These tags are intended for documentation and filtering.') - group.add_argument('-rt', '--remove-tag', type=str, required=False, - help='Removes a tag from the user_tags property.') + 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.') parser.set_defaults(func=_edit_project_props) def add_args(subparsers) -> None: