Script for generating git-trees file from Gerrit project info
[scm/meta/git.git] / scripts / generate-git-tree.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # vim: ts=4 et sw=4 sts=4 ai sta:
4
5 import sys
6 import json
7 import re
8 import codecs
9
10
11 def main(argv):
12
13     if len(argv) < 2:
14         raise SystemExit("Usage: %s <projects.json>" % argv[0])
15
16     # TODO: read from domains file
17     domains = [
18         'App Framework',
19         'Applications',
20         'Automotive',
21         'Base',
22         'Graphics & UI Framework',
23         'Location',
24         'Messaging',
25         'Multimedia',
26         'Network & Connectivity',
27         'Platform Development',
28         'SDK',
29         'Security',
30         'Social & Content',
31         'System',
32         'Telephony',
33         'Testing',
34         'Web Framework'
35     ]
36
37     # Interesting for us branches.
38     # TODO: read from branches file
39     branches = [
40         'tizen', 'tizen_2.2', 'tizen_2.1', 'tizen_2.0'
41     ]
42
43     # Mappings between domain names and ACLs
44     domain_to_acl = {}
45     acl_to_domain = {}
46
47     # Populate mappings
48     for domain in domains:
49         domain_converted = "scm/acls/domain_"+domain.replace("&","and").replace(" ","_").lower()
50         domain_to_acl[domain] = domain_converted
51         acl_to_domain[domain_converted] = domain
52
53     projects = json.load(open(argv[1],"r"))
54
55     git_names = sorted(projects.keys())
56
57     out_projects = {}
58
59     # Gather data
60     for name in git_names:
61         if 'parent' not in projects[name]:
62             # Top-level git tree
63             continue
64         if name.startswith("scm/"):
65             # special hierarchy
66             continue
67         out_projects[name] = {
68                 'maintainers': [], 
69                 'integrators': [], 
70                 'reviewers': [], 
71                 'licenses': [],
72                 'comments': [],
73                 'path': name
74             }
75         if projects[name]['parent'] in acl_to_domain:
76             out_projects[name]['domain'] = acl_to_domain[projects[name]['parent']]
77         else:
78             out_projects[name]['domain'] = ''
79             out_projects[name]['comments'].append('Missing domain!')
80         if 'description' in projects[name] and projects[name]['description']:
81             for line in re.split(r";[\n ]", projects[name]['description']):
82                 if not line:
83                     continue 
84                 if line[-1] == ';':
85                     line = line[:-1]
86                 tup = line.split(": ", 1)
87                 if len(tup) != 2:
88                     # Not well known line
89                     continue
90                 if tup[0] == 'Domain':
91                     # Let's check if domain matches with ACLs
92                     if out_projects[name]['domain'] != tup[1]:
93                         out_projects[name]['description_domain'] = tup[1]
94                         emes="Domain mismatch: '%s' vs. '%s'" % \
95                             (out_projects[name]['domain'], tup[1]) 
96                         out_projects[name]['comments'].append(emes)
97                 else:
98                     out_projects[name][tup[0].lower()] = re.split(r", ?", tup[1])
99         if 'branches' in projects[name]:
100             # TODO: Add information about branches
101             interesting = False
102             out_projects[name]['branches'] = { branch: False for branch in branches }
103             for branch in branches:
104                 if branch in projects[name]['branches']:
105                     out_projects[name]['branches'][branch] = True 
106                     interesting = True
107                 else:
108                     out_projects[name]['branches'][branch] = False
109             if not interesting:
110                 # Project doesn't have any of interesting for us branches
111                 del out_projects[name]
112
113
114     with codecs.open("git-trees.new", "wb", encoding="utf-8") as outfile:
115         dump_all(out_projects, outfile)
116
117
118 def dump_all(git_trees, outfp = None):
119     names = sorted(git_trees.keys())
120     for name in names:
121         out = dumps_one_project(git_trees[name])
122         if outfp:
123             outfp.write("\n"+out)
124
125
126 def dumps_one_project(git_dict):
127     out = []
128
129     #out.append("")
130     out.append("T: %s" % git_dict['path'])
131     out.append("D: %s" % git_dict['domain'])
132     if 'description' in git_dict:
133         for line in git_dict['description']:
134             out.append("O: %s" % line)
135     if 'profiles' in git_dict:
136         for profile in git_dict['profiles']:
137             out.append("P: %s" % profile)
138     if 'status' in git_dict:
139         out.append("S: %s" % git_dict['status'])
140     for role in ("maintainers", "integrators", "reviewers"):
141         if role in git_dict:
142             for person in git_dict[role]:
143                 out.append("%s: %s" % (role[0].upper(), person))
144     if 'branches' in git_dict:
145         for branch in git_dict['branches']:
146             if git_dict['branches'][branch]:
147                 out.append("B: %s" % branch)
148     if 'licenses' in git_dict:
149         for license in git_dict['licenses']:
150             out.append("L: %s" % license)
151     if 'homepage' in git_dict:
152         out.append("H: %s" % git_dict['homepage'])
153     if 'upstream url' in git_dict:
154         out.append("U: %s" % git_dict['upstream url'])
155     if 'upstream vcs' in git_dict:
156         out.append("V: %s" % git_dict['upstream vcs'])
157     if 'comments' in git_dict:
158         for line in git_dict['comments']:
159             out.append("C: %s" % line)
160     return "\n".join(out)+"\n"
161
162
163 if __name__ == '__main__':
164     main(sys.argv)
165