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

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

Issue 29968558: Issue 7037 - [XTM Integration] Make REST API url customizable
Patch Set: Removed one more print statement Created Sept. 17, 2019, 12:36 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
« no previous file with comments | « cms/translations/xtm/projects_handler.py ('k') | cms/translations/xtm/xtm_api.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/translations/xtm/utils.py
diff --git a/cms/translations/xtm/utils.py b/cms/translations/xtm/utils.py
index 22afc4bd2a12d94a773d20b50ce93a7d921f1cf3..8713e81890982e1aacf0c89737d19984d873c072 100644
--- a/cms/translations/xtm/utils.py
+++ b/cms/translations/xtm/utils.py
@@ -20,6 +20,7 @@ import logging
import os
import time
import json
+import ConfigParser
from cms.utils import process_page
import cms.translations.xtm.constants as const
@@ -487,3 +488,41 @@ def extract_workflow_id(api, args):
args.workflow_name))
return possible_ids[0]
+
+
+def get_api_url(args, source):
+ """Extract the appropriate API url to be used.
+
+ In order of priority, from highest to lowest, the returned url will be:
+
+ 1. As an argument of the script: `--api-url`
+ 2. The url from `settings.ini`, under `XTM` section and `url` option
+ (If `source` is not None)
+ 3. The hardcoded url, from `constants.API_URL`
+
+
+ Parameters
+ ----------
+ args: argparse.Namespace
+ The script arguments.
+ source: FileSource
+ Representing the website to get the url for.
+
+ Returns
+ -------
+ str
+ With the API url.
+
+ """
+ if args.api_url:
+ return args.api_url
+
+ if source is None:
+ return const.API_URL
+
+ config = source.read_config()
+
+ try:
+ return config.get(const.Config.XTM_SECTION, const.Config.URL_OPTION)
+ except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
+ return const.API_URL
« no previous file with comments | « cms/translations/xtm/projects_handler.py ('k') | cms/translations/xtm/xtm_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld