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" |
| 11 | API_PROJECTS = "/projects/" |
| 12 | |
| 13 | MAGIC_PREFIX = ")]}'" |
| 14 | |
| 15 | |
| 16 | def get_projects_list(): |
| 17 | """Request list of all available projects from ONAP Gerrit.""" |
| 18 | resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS) |
| 19 | resp_body = resp.read() |
| 20 | |
| 21 | no_magic = resp_body[len(MAGIC_PREFIX):] |
| 22 | decoded = no_magic.decode("utf-8") |
| 23 | projects = json.loads(decoded) |
| 24 | |
| 25 | return projects.keys() |
| 26 | |
| 27 | |
| 28 | def create_repos_list(projects): |
| 29 | """Create a map of all projects to their repositories' URLs.""" |
| 30 | return {p: {"url": "{}/{}.git".format(ONAP_GERRIT, p)} for p in projects} |
| 31 | |
| 32 | |
| 33 | def main(): |
| 34 | """Main entry point for the script.""" |
| 35 | repos = create_repos_list(get_projects_list()) |
| 36 | config = { |
| 37 | "max-concurrent-indexers": 2, |
| 38 | "dbpath": "data", |
| 39 | "health-check-uri": "/healthz", |
| 40 | "repos": repos |
| 41 | } |
| 42 | print(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))) |
| 43 | |
| 44 | |
| 45 | if __name__ == '__main__': |
| 46 | sys.exit(main()) |