blob: 604338fd81151fe279b0cdae99fecb46a069b717 [file] [log] [blame]
Pawel Wieczorek9ee12582020-01-07 15:26:52 +01001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4"""Create configuration for code search."""
5
6import json
7import urllib.request
8import sys
9
10ONAP_GERRIT = "https://gerrit.onap.org/r"
Pawel Wieczorek5aed5e72020-01-07 15:27:54 +010011ONAP_CGIT = "https://git.onap.org"
Pawel Wieczorek9ee12582020-01-07 15:26:52 +010012API_PROJECTS = "/projects/"
13
14MAGIC_PREFIX = ")]}'"
15
16
17def 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
29def create_repos_list(projects):
30 """Create a map of all projects to their repositories' URLs."""
Pawel Wieczorek5aed5e72020-01-07 15:27:54 +010031 return {p: {"url": "{}/{}".format(ONAP_CGIT, p), "url-pattern": {"base-url": "{url}/tree/{path}{anchor}", "anchor": "#n{line}"}} for p in projects}
Pawel Wieczorek9ee12582020-01-07 15:26:52 +010032
33
34def 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
46if __name__ == '__main__':
47 sys.exit(main())