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.
main
mgwynn 5 years ago
parent accd473ff5
commit 7984f82e48

@ -15,14 +15,19 @@
namespace O3DE::ProjectManager namespace O3DE::ProjectManager
{ {
ProjectInfo::ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, 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_path(path)
, m_projectName(projectName) , m_projectName(projectName)
, m_displayName(displayName) , m_displayName(displayName)
, m_origin(origin)
, m_summary(summary)
, m_imagePath(imagePath) , m_imagePath(imagePath)
, m_backgroundImagePath(backgroundImagePath) , m_backgroundImagePath(backgroundImagePath)
, m_isNew(isNew) , m_isNew(isNew)
{ {
m_userTags = QStringList();
m_userTagsForRemoval = QStringList();
} }
bool ProjectInfo::operator==(const ProjectInfo& rhs) bool ProjectInfo::operator==(const ProjectInfo& rhs)

@ -15,6 +15,7 @@
#if !defined(Q_MOC_RUN) #if !defined(Q_MOC_RUN)
#include <AzCore/Math/Uuid.h> #include <AzCore/Math/Uuid.h>
#include <QString> #include <QString>
#include <QStringList>
#endif #endif
namespace O3DE::ProjectManager namespace O3DE::ProjectManager
@ -23,8 +24,8 @@ namespace O3DE::ProjectManager
{ {
public: public:
ProjectInfo() = default; ProjectInfo() = default;
ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, ProjectInfo(const QString& path, const QString& projectName, const QString& displayName, const QString& origin,
const QString& imagePath, const QString& backgroundImagePath, bool isNew); const QString& summary, const QString& imagePath, const QString& backgroundImagePath, bool isNew);
bool operator==(const ProjectInfo& rhs); bool operator==(const ProjectInfo& rhs);
bool operator!=(const ProjectInfo& rhs); bool operator!=(const ProjectInfo& rhs);
@ -36,12 +37,18 @@ namespace O3DE::ProjectManager
// From project.json // From project.json
QString m_projectName; QString m_projectName;
QString m_displayName; QString m_displayName;
QString m_origin;
QString m_summary;
QStringList m_userTags;
// Used on projects home screen // Used on projects home screen
QString m_imagePath; QString m_imagePath;
QString m_backgroundImagePath; QStringList m_backgroundImagePath;
// Used in project creation // Used in project creation
bool m_isNew = false; //! Is this a new project or existing bool m_isNew = false; //! Is this a new project or existing
// Used to flag tags for removal
QStringList m_userTagsForRemoval;
}; };
} // namespace O3DE::ProjectManager } // namespace O3DE::ProjectManager

@ -19,6 +19,7 @@
#include <pybind11/functional.h> #include <pybind11/functional.h>
#include <pybind11/embed.h> #include <pybind11/embed.h>
#include <pybind11/eval.h> #include <pybind11/eval.h>
#include <pybind11/stl.h>
#pragma pop_macro("slots") #pragma pop_macro("slots")
#include <AzCore/IO/FileIO.h> #include <AzCore/IO/FileIO.h>
@ -687,23 +688,6 @@ namespace O3DE::ProjectManager
return projectInfo; return projectInfo;
} }
AZ::Outcome<void, AZStd::string> 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<QVector<ProjectInfo>> PythonBindings::GetProjects() AZ::Outcome<QVector<ProjectInfo>> PythonBindings::GetProjects()
{ {
QVector<ProjectInfo> projects; QVector<ProjectInfo> projects;
@ -764,9 +748,32 @@ namespace O3DE::ProjectManager
}); });
} }
bool PythonBindings::UpdateProject([[maybe_unused]] const ProjectInfo& projectInfo) AZ::Outcome<void, AZStd::string> PythonBindings::UpdateProject(const ProjectInfo& projectInfo)
{ {
return false; return ExecuteWithLockErrorHandling([&]
{
std::list<std::string> newTags;
for (auto& i : projectInfo.m_userTags)
{
newTags.push_back(i.toStdString());
}
std::list<std::string> 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) ProjectTemplateInfo PythonBindings::ProjectTemplateInfoFromPath(pybind11::handle path)

@ -50,14 +50,9 @@ namespace O3DE::ProjectManager
AZ::Outcome<QVector<ProjectInfo>> GetProjects() override; AZ::Outcome<QVector<ProjectInfo>> GetProjects() override;
bool AddProject(const QString& path) override; bool AddProject(const QString& path) override;
bool RemoveProject(const QString& path) override; bool RemoveProject(const QString& path) override;
bool UpdateProject(const ProjectInfo& projectInfo) override; AZ::Outcome<void, AZStd::string> UpdateProject(const ProjectInfo& projectInfo) override;
AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) override; AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) override;
AZ::Outcome<void, AZStd::string> RemoveGemFromProject(const QString& gemPath, const QString& projectPath) override; AZ::Outcome<void, AZStd::string> RemoveGemFromProject(const QString& gemPath, const QString& projectPath) override;
AZ::Outcome<void, AZStd::string> 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 // ProjectTemplate
AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplates() override; AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplates() override;

@ -122,7 +122,7 @@ namespace O3DE::ProjectManager
* @param projectInfo the info to use to update the project * @param projectInfo the info to use to update the project
* @return true on success, false on failure * @return true on success, false on failure
*/ */
virtual bool UpdateProject(const ProjectInfo& projectInfo) = 0; virtual AZ::Outcome<void, AZStd::string> UpdateProject(const ProjectInfo& projectInfo) = 0;
/** /**
* Add a gem to a project * Add a gem to a project
@ -132,25 +132,6 @@ namespace O3DE::ProjectManager
*/ */
virtual AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) = 0; virtual AZ::Outcome<void, AZStd::string> 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<void, AZStd::string> 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 * Remove gem to a project
* @param gemPath the absolute path to the gem * @param gemPath the absolute path to the gem

@ -134,10 +134,10 @@ namespace O3DE::ProjectManager
// Update project if settings changed // Update project if settings changed
if (m_projectInfo != newProjectSettings) if (m_projectInfo != newProjectSettings)
{ {
bool result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings); auto result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings);
if (!result) 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; return;
} }
} }

@ -45,15 +45,17 @@ def edit_project_props(proj_path, proj_name, new_origin, new_display,
if new_icon: if new_icon:
proj_json['icon_path'] = new_icon proj_json['icon_path'] = new_icon
if new_tag: 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 remove_tag:
if 'user_tags' in proj_json: if 'user_tags' in proj_json:
if remove_tag in proj_json['user_tags']: for del_tag in remove_tag:
proj_json['user_tags'].remove(remove_tag) if del_tag in proj_json['user_tags']:
proj_json['user_tags'].remove(del_tag)
else: else:
logger.warn(f'{remove_tag} not found in user_tags for removal.') logger.warn(f'{del_tag} not found in user_tags for removal.')
else: 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') manifest.save_o3de_manifest(proj_json, pathlib.Path(proj_path) / 'project.json')
return 0 return 0
@ -83,10 +85,10 @@ def add_parser_args(parser):
help='Sets the summary description of the project.') help='Sets the summary description of the project.')
group.add_argument('-pi', '--project-icon', type=str, required=False, group.add_argument('-pi', '--project-icon', type=str, required=False,
help='Sets the path to the projects icon resource.') help='Sets the path to the projects icon resource.')
group.add_argument('-pt', '--project-tag', type=str, required=False, group.add_argument('-pt', '--project-tag', type=default, required=False,
help='Adds a tag to user_tags property. These tags are intended for documentation and filtering.') help='Adds tag(s) to user_tags property. These tags are intended for documentation and filtering.')
group.add_argument('-rt', '--remove-tag', type=str, required=False, group.add_argument('-rt', '--remove-tag', type=default, required=False,
help='Removes a tag from the user_tags property.') help='Removes tag(s) from the user_tags property.')
parser.set_defaults(func=_edit_project_props) parser.set_defaults(func=_edit_project_props)
def add_args(subparsers) -> None: def add_args(subparsers) -> None:

Loading…
Cancel
Save