PythonBindingsInterface.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/EBus.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzCore/Outcome/Outcome.h>
  14. #include <EngineInfo.h>
  15. #include <GemCatalog/GemInfo.h>
  16. #include <ProjectInfo.h>
  17. #include <ProjectTemplateInfo.h>
  18. #include <GemRepo/GemRepoInfo.h>
  19. namespace O3DE::ProjectManager
  20. {
  21. //! Interface used to interact with the o3de cli python functions
  22. class IPythonBindings
  23. {
  24. public:
  25. AZ_RTTI(O3DE::ProjectManager::IPythonBindings, "{C2B72CA4-56A9-4601-A584-3B40E83AA17C}");
  26. AZ_DISABLE_COPY_MOVE(IPythonBindings);
  27. IPythonBindings() = default;
  28. virtual ~IPythonBindings() = default;
  29. //! First string in pair is general error, second is detailed
  30. using ErrorPair = AZStd::pair<AZStd::string, AZStd::string>;
  31. using DetailedOutcome = AZ::Outcome<void, ErrorPair>;
  32. /**
  33. * Get whether Python was started or not. All Python functionality will fail if Python
  34. * failed to start.
  35. * @return true if Python was started successfully, false on failure
  36. */
  37. virtual bool PythonStarted() = 0;
  38. /**
  39. * Attempt to start Python. Normally, Python is started when the bindings are created,
  40. * but this method allows you to attempt to retry starting Python in case the configuration
  41. * has changed.
  42. * @return true if Python was started successfully, false on failure
  43. */
  44. virtual bool StartPython() = 0;
  45. // Engine
  46. /**
  47. * Get info about the current engine
  48. * @return an outcome with EngineInfo on success
  49. */
  50. virtual AZ::Outcome<EngineInfo> GetEngineInfo() = 0;
  51. /**
  52. * Get info about an engine by name
  53. * @param engineName The name of the engine to get info about
  54. * @return an outcome with EngineInfo on success
  55. */
  56. virtual AZ::Outcome<EngineInfo> GetEngineInfo(const QString& engineName) = 0;
  57. /**
  58. * Set info about the engine
  59. * @param force True to force registration even if an engine with the same name is already registered
  60. * @param engineInfo an EngineInfo object
  61. * @return a detailed error outcome on failure.
  62. */
  63. virtual DetailedOutcome SetEngineInfo(const EngineInfo& engineInfo, bool force = false) = 0;
  64. // Gems
  65. /**
  66. * Get info about a Gem.
  67. * @param path The absolute path to the Gem
  68. * @param projectPath (Optional) The absolute path to the Gem project
  69. * @return an outcome with GemInfo on success
  70. */
  71. virtual AZ::Outcome<GemInfo> GetGemInfo(const QString& path, const QString& projectPath = {}) = 0;
  72. /**
  73. * Get all available gem infos. This concatenates gems registered by the engine and the project.
  74. * @param projectPath The absolute path to the project.
  75. * @return A list of gem infos.
  76. */
  77. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetAllGemInfos(const QString& projectPath) = 0;
  78. /**
  79. * Get engine gem infos.
  80. * @return A list of all registered gem infos.
  81. */
  82. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetEngineGemInfos() = 0;
  83. /**
  84. * Get a list of all enabled gem names for a given project.
  85. * @param[in] projectPath Absolute file path to the project.
  86. * @return A list of gem names of all the enabled gems for a given project or a error message on failure.
  87. */
  88. virtual AZ::Outcome<QVector<AZStd::string>, AZStd::string> GetEnabledGemNames(const QString& projectPath) = 0;
  89. /**
  90. * Registers the gem to the specified project, or to the o3de_manifest.json if no project path is given
  91. * @param gemPath the path to the gem
  92. * @param projectPath the path to the project. If empty, will register the external path in o3de_manifest.json
  93. * @return An outcome with the success flag as well as an error message in case of a failure.
  94. */
  95. virtual AZ::Outcome<void, AZStd::string> RegisterGem(const QString& gemPath, const QString& projectPath = {}) = 0;
  96. /**
  97. * Unregisters the gem from the specified project, or from the o3de_manifest.json if no project path is given
  98. * @param gemPath the path to the gem
  99. * @param projectPath the path to the project. If empty, will unregister the external path in o3de_manifest.json
  100. * @return An outcome with the success flag as well as an error message in case of a failure.
  101. */
  102. virtual AZ::Outcome<void, AZStd::string> UnregisterGem(const QString& gemPath, const QString& projectPath = {}) = 0;
  103. // Projects
  104. /**
  105. * Create a project
  106. * @param projectTemplatePath the path to the project template to use
  107. * @param projectInfo the project info to use
  108. * @param registerProject whether to register the project or not
  109. * @return an outcome with ProjectInfo on success
  110. */
  111. virtual AZ::Outcome<ProjectInfo> CreateProject(const QString& projectTemplatePath, const ProjectInfo& projectInfo, bool registerProject = true) = 0;
  112. /**
  113. * Get info about a project
  114. * @param path the absolute path to the project
  115. * @return an outcome with ProjectInfo on success
  116. */
  117. virtual AZ::Outcome<ProjectInfo> GetProject(const QString& path) = 0;
  118. /**
  119. * Get info about all known projects
  120. * @return an outcome with ProjectInfos on success
  121. */
  122. virtual AZ::Outcome<QVector<ProjectInfo>> GetProjects() = 0;
  123. /**
  124. * Gathers all projects from the provided repo
  125. * @param repoUri the absolute filesystem path or url to the gem repo.
  126. * @return A list of project infos or an error string on failure.
  127. */
  128. virtual AZ::Outcome<QVector<ProjectInfo>, AZStd::string> GetProjectsForRepo(const QString& repoUri) = 0;
  129. /**
  130. * Gathers all projects from all registered repos
  131. * @return A list of project infos or an error string on failure.
  132. */
  133. virtual AZ::Outcome<QVector<ProjectInfo>, AZStd::string> GetProjectsForAllRepos() = 0;
  134. /**
  135. * Adds existing project on disk
  136. * @param path the absolute path to the project
  137. * @return true on success, false on failure
  138. */
  139. virtual bool AddProject(const QString& path) = 0;
  140. /**
  141. * Adds existing project on disk
  142. * @param path the absolute path to the project
  143. * @return true on success, false on failure
  144. */
  145. virtual bool RemoveProject(const QString& path) = 0;
  146. /**
  147. * Update a project
  148. * @param projectInfo the info to use to update the project
  149. * @return true on success, false on failure
  150. */
  151. virtual AZ::Outcome<void, AZStd::string> UpdateProject(const ProjectInfo& projectInfo) = 0;
  152. /**
  153. * Add a gem to a project
  154. * @param gemPath the absolute path to the gem
  155. * @param projectPath the absolute path to the project
  156. * @return An outcome with the success flag as well as an error message in case of a failure.
  157. */
  158. virtual AZ::Outcome<void, AZStd::string> AddGemToProject(const QString& gemPath, const QString& projectPath) = 0;
  159. /**
  160. * Remove gem to a project
  161. * @param gemPath the absolute path to the gem
  162. * @param projectPath the absolute path to the project
  163. * @return An outcome with the success flag as well as an error message in case of a failure.
  164. */
  165. virtual AZ::Outcome<void, AZStd::string> RemoveGemFromProject(const QString& gemPath, const QString& projectPath) = 0;
  166. /**
  167. * Removes invalid projects from the manifest
  168. */
  169. virtual bool RemoveInvalidProjects() = 0;
  170. // Project Templates
  171. /**
  172. * Get info about all known project templates
  173. * @return an outcome with ProjectTemplateInfos on success
  174. */
  175. virtual AZ::Outcome<QVector<ProjectTemplateInfo>> GetProjectTemplates(const QString& projectPath = {}) = 0;
  176. // Gem Repos
  177. /**
  178. * Refresh gem repo in the current engine.
  179. * @param repoUri the absolute filesystem path or url to the gem repo.
  180. * @return An outcome with the success flag as well as an error message in case of a failure.
  181. */
  182. virtual AZ::Outcome<void, AZStd::string> RefreshGemRepo(const QString& repoUri) = 0;
  183. /**
  184. * Refresh all gem repos in the current engine.
  185. * @return true on success, false on failure.
  186. */
  187. virtual bool RefreshAllGemRepos() = 0;
  188. /**
  189. * Registers this gem repo with the current engine.
  190. * @param repoUri the absolute filesystem path or url to the gem repo.
  191. * @return an outcome with a pair of string error and detailed messages on failure.
  192. */
  193. virtual DetailedOutcome AddGemRepo(const QString& repoUri) = 0;
  194. /**
  195. * Unregisters this gem repo with the current engine.
  196. * @param repoUri the absolute filesystem path or url to the gem repo.
  197. * @return true on success, false on failure.
  198. */
  199. virtual bool RemoveGemRepo(const QString& repoUri) = 0;
  200. /**
  201. * Get all available gem repo infos. Gathers all repos registered with the engine.
  202. * @return A list of gem repo infos.
  203. */
  204. virtual AZ::Outcome<QVector<GemRepoInfo>, AZStd::string> GetAllGemRepoInfos() = 0;
  205. /**
  206. * Gathers all gem infos from the provided repo
  207. * @param repoUri the absolute filesystem path or url to the gem repo.
  208. * @return A list of gem infos.
  209. */
  210. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetGemInfosForRepo(const QString& repoUri) = 0;
  211. /**
  212. * Gathers all gem infos for all gems registered from repos.
  213. * @return A list of gem infos.
  214. */
  215. virtual AZ::Outcome<QVector<GemInfo>, AZStd::string> GetGemInfosForAllRepos() = 0;
  216. /**
  217. * Downloads and registers a Gem.
  218. * @param gemName the name of the Gem to download.
  219. * @param gemProgressCallback a callback function that is called with an int percentage download value.
  220. * @param force should we forcibly overwrite the old version of the gem.
  221. * @return an outcome with a pair of string error and detailed messages on failure.
  222. */
  223. virtual DetailedOutcome DownloadGem(
  224. const QString& gemName, std::function<void(int, int)> gemProgressCallback, bool force = false) = 0;
  225. /**
  226. * Downloads and registers a Gem.
  227. * @param gemName the name of the Gem to download.
  228. * @param gemProgressCallback a callback function that is called with an int percentage download value.
  229. * @param force should we forcibly overwrite the old version of the gem.
  230. * @return an outcome with a pair of string error and detailed messages on failure.
  231. */
  232. virtual DetailedOutcome DownloadProject(
  233. const QString& projectName, std::function<void(int, int)> projectProgressCallback, bool force = false) = 0;
  234. /**
  235. * Downloads and registers a Gem.
  236. * @param gemName the name of the Gem to download.
  237. * @param gemProgressCallback a callback function that is called with an int percentage download value.
  238. * @param force should we forcibly overwrite the old version of the gem.
  239. * @return an outcome with a pair of string error and detailed messages on failure.
  240. */
  241. virtual DetailedOutcome DownloadTemplate(
  242. const QString& templateName, std::function<void(int, int)> templateProgressCallback, bool force = false) = 0;
  243. /**
  244. * Cancels the current download.
  245. */
  246. virtual void CancelDownload() = 0;
  247. /**
  248. * Checks if there is an update avaliable for a gem on a repo.
  249. * @param gemName the name of the gem to check.
  250. * @param lastUpdated last time the gem was update.
  251. * @return true if update is avaliable, false if not.
  252. */
  253. virtual bool IsGemUpdateAvaliable(const QString& gemName, const QString& lastUpdated) = 0;
  254. /**
  255. * Add an error string to be returned when the current python call is complete.
  256. * @param The error string to be displayed.
  257. */
  258. virtual void AddErrorString(AZStd::string errorString) = 0;
  259. /**
  260. * Clears the current list of error strings.
  261. */
  262. virtual void ClearErrorStrings() = 0;
  263. };
  264. using PythonBindingsInterface = AZ::Interface<IPythonBindings>;
  265. } // namespace O3DE::ProjectManager