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

Side by Side Diff: cms/translations/xtm/utils.py

Issue 29968558: Issue 7037 - [XTM Integration] Make REST API url customizable
Patch Set: Merged with changes from 7039 Created Sept. 17, 2019, 1:37 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
« no previous file with comments | « cms/translations/xtm/constants.py ('k') | cms/translations/xtm/xtm_api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 from __future__ import unicode_literals 16 from __future__ import unicode_literals
17 17
18 import collections 18 import collections
19 import logging 19 import logging
20 import os 20 import os
21 import time 21 import time
22 import json 22 import json
23 import ConfigParser
23 24
24 from cms.utils import process_page 25 from cms.utils import process_page
25 import cms.translations.xtm.constants as const 26 import cms.translations.xtm.constants as const
26 from cms.translations.xtm.xtm_api import XTMCloudException 27 from cms.translations.xtm.xtm_api import XTMCloudException
27 28
28 29
29 __all__ = [ 30 __all__ = [
30 'extract_strings', 'resolve_locales', 'map_locales', 'local_to_remote', 31 'extract_strings', 'resolve_locales', 'map_locales', 'local_to_remote',
31 'remote_to_local', 'run_and_wait', 'sanitize_project_name', 'read_token', 32 'remote_to_local', 'run_and_wait', 'sanitize_project_name', 'read_token',
32 'get_files_to_upload', 'log_resulting_jobs', 'clear_files', 'input_fn', 33 'get_files_to_upload', 'log_resulting_jobs', 'clear_files', 'input_fn',
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if args.workflow_id: 481 if args.workflow_id:
481 return args.workflow_id 482 return args.workflow_id
482 483
483 possible_ids = api.get_workflows_by_name(args.workflow_name) 484 possible_ids = api.get_workflows_by_name(args.workflow_name)
484 485
485 if len(possible_ids) == 0: 486 if len(possible_ids) == 0:
486 raise Exception(const.ErrorMessages.NO_WORKFLOW_FOR_NAME.format( 487 raise Exception(const.ErrorMessages.NO_WORKFLOW_FOR_NAME.format(
487 args.workflow_name)) 488 args.workflow_name))
488 489
489 return possible_ids[0] 490 return possible_ids[0]
491
492
493 def get_api_url(args, source):
494 """Extract the appropriate API url to be used.
495
496 In order of priority, from highest to lowest, the returned url will be:
497
498 1. As an argument of the script: `--api-url`
499 2. The url from `settings.ini`, under `XTM` section and `url` option
500 (If `source` is not None)
501 3. The hardcoded url, from `constants.API_URL`
502
503
504 Parameters
505 ----------
506 args: argparse.Namespace
507 The script arguments.
508 source: FileSource
509 Representing the website to get the url for.
510
511 Returns
512 -------
513 str
514 With the API url.
515
516 """
517 if args.api_url:
518 return args.api_url
519
520 if source is None:
521 return const.API_URL
522
523 config = source.read_config()
524
525 try:
526 return config.get(const.Config.XTM_SECTION, const.Config.URL_OPTION)
527 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
528 return const.API_URL
OLDNEW
« no previous file with comments | « cms/translations/xtm/constants.py ('k') | cms/translations/xtm/xtm_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld