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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 with open(file_path, 'wb') as f: 435 with open(file_path, 'wb') as f:
436 f.write(data) 436 f.write(data)
437 437
438 438
439 def input_fn(text): 439 def input_fn(text):
440 try: 440 try:
441 return raw_input(text) 441 return raw_input(text)
442 except Exception: 442 except Exception:
443 return input(text) 443 return input(text)
444
445
446 def extract_workflow_id(api, args):
447 """Extract the workflow id, using the arguments provided by the user.
448
449 Parameters
450 ----------
451 api: XTMCloudAPI
452 Used to interact with the XTM API.
453 args: argparse.Namespace
454 With the arguments provided to the script.
455
456 Returns
457 -------
458 int
459 With the corresponding workflow id.
460
461 Raises
462 ------
463 XTMCloudException
464 If the API communication fails in any way.
465 Exception
466 In one of the following situations:
467 1. If both `--workflow-id` and `--workflow-name` are provided.
468 2. If none of the parameters above are provided.
469 3. If there are no workflows associated with a given name.
470
471 """
472 if args.workflow_id and args.workflow_name:
473 raise Exception(const.ErrorMessages.WORKFLOW_NAME_AND_ID_PROVIDED)
474
475 if not (args.workflow_id or args.workflow_name):
476 raise Exception(const.ErrorMessages.NO_WORKFLOW_INFO)
477
478 if args.workflow_id:
479 return args.workflow_id
480
481 possible_ids = api.get_workflows_by_name(args.workflow_name)
482
483 if len(possible_ids) == 0:
484 raise Exception(const.ErrorMessages.NO_WORKFLOW_FOR_NAME.format(
485 args.workflow_name))
486
487 return possible_ids[0]
OLDNEW

Powered by Google App Engine
This is Rietveld