diff options
author | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-07 15:28:51 +0100 |
---|---|---|
committer | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-07 15:28:51 +0100 |
commit | e2aa848b52d50e98e2463088254668772a3c8d25 (patch) | |
tree | f23dc6adb5b418d6430328a98991f1d50ebb3207 | |
parent | e7c5ed589026a6629a219b71b35e8a20036bc94a (diff) |
Make Gerrit and cgit URLs configurable
Issue-ID: ONAPARC-540
Change-Id: I3d7f04379e31ab73964b8cc6184ca2e4413acb7b
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
-rwxr-xr-x | bootstrap/codesearch/create_config.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py index def4b3ecd..e7a55c39d 100755 --- a/bootstrap/codesearch/create_config.py +++ b/bootstrap/codesearch/create_config.py @@ -3,20 +3,21 @@ """Create configuration for code search.""" +import argparse import json import urllib.request import sys -ONAP_GERRIT = "https://gerrit.onap.org/r" -ONAP_CGIT = "https://git.onap.org" +DEFAULT_GERRIT = "https://gerrit.onap.org/r" +DEFAULT_CGIT = "https://git.onap.org" API_PROJECTS = "/projects/" MAGIC_PREFIX = ")]}'" -def get_projects_list(): +def get_projects_list(gerrit): """Request list of all available projects from ONAP Gerrit.""" - resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS) + resp = urllib.request.urlopen(gerrit + API_PROJECTS) resp_body = resp.read() no_magic = resp_body[len(MAGIC_PREFIX):] @@ -26,12 +27,12 @@ def get_projects_list(): return projects.keys() -def create_repos_list(projects): +def create_repos_list(projects, cgit): """Create a map of all projects to their repositories' URLs.""" repos_list = {} for project in projects: repos_list[project] = { - "url": "{}/{}".format(ONAP_CGIT, project), + "url": "{}/{}".format(cgit, project), "url-pattern": { "base-url": "{url}/tree/{path}{anchor}", "anchor": "#n{line}" @@ -41,9 +42,20 @@ def create_repos_list(projects): return repos_list +def parse_arguments(): + """Return parsed command-line arguments.""" + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--gerrit', help='Gerrit address', default=DEFAULT_GERRIT) + parser.add_argument('--cgit', help='cgit address', default=DEFAULT_CGIT) + + return parser.parse_args() + + def main(): """Main entry point for the script.""" - repos = create_repos_list(get_projects_list()) + arguments = parse_arguments() + + repos = create_repos_list(get_projects_list(arguments.gerrit), arguments.cgit) config = { "max-concurrent-indexers": 2, "dbpath": "data", |