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: Addressed comments from Patch Set 1 Created Oct. 18, 2018, 4:23 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 436
437 with open(file_path, 'wb') as f: 437 with open(file_path, 'wb') as f:
438 f.write(data) 438 f.write(data)
439 439
440 440
441 def input_fn(text): 441 def input_fn(text):
442 try: 442 try:
443 return raw_input(text) 443 return raw_input(text)
444 except Exception: 444 except Exception:
445 return input(text) 445 return input(text)
446
447
448 def extract_workflow_id(api, args):
449 """Extract the workflow id, using the arguments provided by the user.
450
451 Parameters
452 ----------
453 api: XTMCloudAPI
454 Used to interact with the XTM API.
455 args: argparse.Namespace
456 With the arguments provided to the script.
457
458 Returns
459 -------
460 int
461 With the corresponding workflow id.
462
463 Raises
464 ------
465 XTMCloudException
466 If the API communication fails in any way.
467 Exception
468 In one of the following situations:
469 1. If both `--workflow-id` and `--workflow-name` are provided.
470 2. If none of the parameters above are provided.
471 3. If there are no workflows associated with a given name.
472
473 """
474 if args.workflow_id and args.workflow_name:
475 raise Exception(const.ErrorMessages.WORKFLOW_NAME_AND_ID_PROVIDED)
476
477 if not (args.workflow_id or args.workflow_name):
478 raise Exception(const.ErrorMessages.NO_WORKFLOW_INFO)
479
480 if args.workflow_id:
481 return args.workflow_id
482
483 possible_ids = api.get_workflows_by_name(args.workflow_name)
484
485 if len(possible_ids) == 0:
486 raise Exception(const.ErrorMessages.NO_WORKFLOW_FOR_NAME.format(
487 args.workflow_name))
488
489 return possible_ids[0]
OLDNEW

Powered by Google App Engine
This is Rietveld