Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | """Create configuration for code search.""" |
| 5 | |
| 6 | import json |
| 7 | import urllib.request |
| 8 | import sys |
| 9 | |
| 10 | ONAP_GERRIT = "https://gerrit.onap.org/r" |
Pawel Wieczorek | 5aed5e7 | 2020-01-07 15:27:54 +0100 | [diff] [blame^] | 11 | ONAP_CGIT = "https://git.onap.org" |
Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 12 | API_PROJECTS = "/projects/" |
| 13 | |
| 14 | MAGIC_PREFIX = ")]}'" |
| 15 | |
| 16 | |
| 17 | def get_projects_list(): |
| 18 | """Request list of all available projects from ONAP Gerrit.""" |
| 19 | resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS) |
| 20 | resp_body = resp.read() |
| 21 | |
| 22 | no_magic = resp_body[len(MAGIC_PREFIX):] |
| 23 | decoded = no_magic.decode("utf-8") |
| 24 | projects = json.loads(decoded) |
| 25 | |
| 26 | return projects.keys() |
| 27 | |
| 28 | |
| 29 | def create_repos_list(projects): |
| 30 | """Create a map of all projects to their repositories' URLs.""" |
Pawel Wieczorek | 5aed5e7 | 2020-01-07 15:27:54 +0100 | [diff] [blame^] | 31 | return {p: {"url": "{}/{}".format(ONAP_CGIT, p), "url-pattern": {"base-url": "{url}/tree/{path}{anchor}", "anchor": "#n{line}"}} for p in projects} |
Pawel Wieczorek | 9ee1258 | 2020-01-07 15:26:52 +0100 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def main(): |
| 35 | """Main entry point for the script.""" |
| 36 | repos = create_repos_list(get_projects_list()) |
| 37 | config = { |
| 38 | "max-concurrent-indexers": 2, |
| 39 | "dbpath": "data", |
| 40 | "health-check-uri": "/healthz", |
| 41 | "repos": repos |
| 42 | } |
| 43 | print(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))) |
| 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | sys.exit(main()) |