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: Created Oct. 12, 2018, 2:03 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 2cb220cdcead84591c2582f53798f0308ff80014..0d4ee9e3e79261044c31da401604c050a80785e6 100644
--- a/cms/translations/xtm/utils.py
+++ b/cms/translations/xtm/utils.py
@@ -441,3 +441,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