Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/translations/xtm/utils.py

Issue 29908581: Issue #7036 - [XTM Integration] Add support for providing workflow name (Closed)
Patch Set: Addressed comments from Patch Set 1 Created Oct. 18, 2018, 4:23 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cms/translations/xtm/utils.py
diff --git a/cms/translations/xtm/utils.py b/cms/translations/xtm/utils.py
index f0e1530cc8f6ecdd6f46ca6d4b404e72989cc3b8..22afc4bd2a12d94a773d20b50ce93a7d921f1cf3 100644
--- a/cms/translations/xtm/utils.py
+++ b/cms/translations/xtm/utils.py
@@ -443,3 +443,47 @@ def input_fn(text):
return raw_input(text)
except Exception:
return input(text)
+
+
+def extract_workflow_id(api, args):
+ """Extract the workflow id, using the arguments provided by the user.
+
+ Parameters
+ ----------
+ api: XTMCloudAPI
+ Used to interact with the XTM API.
+ args: argparse.Namespace
+ With the arguments provided to the script.
+
+ Returns
+ -------
+ int
+ With the corresponding workflow id.
+
+ Raises
+ ------
+ XTMCloudException
+ If the API communication fails in any way.
+ Exception
+ In one of the following situations:
+ 1. If both `--workflow-id` and `--workflow-name` are provided.
+ 2. If none of the parameters above are provided.
+ 3. If there are no workflows associated with a given name.
+
+ """
+ if args.workflow_id and args.workflow_name:
+ raise Exception(const.ErrorMessages.WORKFLOW_NAME_AND_ID_PROVIDED)
+
+ if not (args.workflow_id or args.workflow_name):
+ raise Exception(const.ErrorMessages.NO_WORKFLOW_INFO)
+
+ if args.workflow_id:
+ return args.workflow_id
+
+ possible_ids = api.get_workflows_by_name(args.workflow_name)
+
+ if len(possible_ids) == 0:
+ raise Exception(const.ErrorMessages.NO_WORKFLOW_FOR_NAME.format(
+ args.workflow_name))
+
+ return possible_ids[0]

Powered by Google App Engine
This is Rietveld