From 7abf80886bb63a46acb88624a5296f4f8d51ece4 Mon Sep 17 00:00:00 2001 From: Alexander Kanevskiy Date: Thu, 10 Oct 2013 02:48:17 +0300 Subject: [PATCH 1/1] Script for generating git-trees file from Gerrit project info --- scripts/generate-git-tree.py | 165 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100755 scripts/generate-git-tree.py diff --git a/scripts/generate-git-tree.py b/scripts/generate-git-tree.py new file mode 100755 index 0000000..1927a0e --- /dev/null +++ b/scripts/generate-git-tree.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: ts=4 et sw=4 sts=4 ai sta: + +import sys +import json +import re +import codecs + + +def main(argv): + + if len(argv) < 2: + raise SystemExit("Usage: %s " % argv[0]) + + # TODO: read from domains file + domains = [ + 'App Framework', + 'Applications', + 'Automotive', + 'Base', + 'Graphics & UI Framework', + 'Location', + 'Messaging', + 'Multimedia', + 'Network & Connectivity', + 'Platform Development', + 'SDK', + 'Security', + 'Social & Content', + 'System', + 'Telephony', + 'Testing', + 'Web Framework' + ] + + # Interesting for us branches. + # TODO: read from branches file + branches = [ + 'tizen', 'tizen_2.2', 'tizen_2.1', 'tizen_2.0' + ] + + # Mappings between domain names and ACLs + domain_to_acl = {} + acl_to_domain = {} + + # Populate mappings + for domain in domains: + domain_converted = "scm/acls/domain_"+domain.replace("&","and").replace(" ","_").lower() + domain_to_acl[domain] = domain_converted + acl_to_domain[domain_converted] = domain + + projects = json.load(open(argv[1],"r")) + + git_names = sorted(projects.keys()) + + out_projects = {} + + # Gather data + for name in git_names: + if 'parent' not in projects[name]: + # Top-level git tree + continue + if name.startswith("scm/"): + # special hierarchy + continue + out_projects[name] = { + 'maintainers': [], + 'integrators': [], + 'reviewers': [], + 'licenses': [], + 'comments': [], + 'path': name + } + if projects[name]['parent'] in acl_to_domain: + out_projects[name]['domain'] = acl_to_domain[projects[name]['parent']] + else: + out_projects[name]['domain'] = '' + out_projects[name]['comments'].append('Missing domain!') + if 'description' in projects[name] and projects[name]['description']: + for line in re.split(r";[\n ]", projects[name]['description']): + if not line: + continue + if line[-1] == ';': + line = line[:-1] + tup = line.split(": ", 1) + if len(tup) != 2: + # Not well known line + continue + if tup[0] == 'Domain': + # Let's check if domain matches with ACLs + if out_projects[name]['domain'] != tup[1]: + out_projects[name]['description_domain'] = tup[1] + emes="Domain mismatch: '%s' vs. '%s'" % \ + (out_projects[name]['domain'], tup[1]) + out_projects[name]['comments'].append(emes) + else: + out_projects[name][tup[0].lower()] = re.split(r", ?", tup[1]) + if 'branches' in projects[name]: + # TODO: Add information about branches + interesting = False + out_projects[name]['branches'] = { branch: False for branch in branches } + for branch in branches: + if branch in projects[name]['branches']: + out_projects[name]['branches'][branch] = True + interesting = True + else: + out_projects[name]['branches'][branch] = False + if not interesting: + # Project doesn't have any of interesting for us branches + del out_projects[name] + + + with codecs.open("git-trees.new", "wb", encoding="utf-8") as outfile: + dump_all(out_projects, outfile) + + +def dump_all(git_trees, outfp = None): + names = sorted(git_trees.keys()) + for name in names: + out = dumps_one_project(git_trees[name]) + if outfp: + outfp.write("\n"+out) + + +def dumps_one_project(git_dict): + out = [] + + #out.append("") + out.append("T: %s" % git_dict['path']) + out.append("D: %s" % git_dict['domain']) + if 'description' in git_dict: + for line in git_dict['description']: + out.append("O: %s" % line) + if 'profiles' in git_dict: + for profile in git_dict['profiles']: + out.append("P: %s" % profile) + if 'status' in git_dict: + out.append("S: %s" % git_dict['status']) + for role in ("maintainers", "integrators", "reviewers"): + if role in git_dict: + for person in git_dict[role]: + out.append("%s: %s" % (role[0].upper(), person)) + if 'branches' in git_dict: + for branch in git_dict['branches']: + if git_dict['branches'][branch]: + out.append("B: %s" % branch) + if 'licenses' in git_dict: + for license in git_dict['licenses']: + out.append("L: %s" % license) + if 'homepage' in git_dict: + out.append("H: %s" % git_dict['homepage']) + if 'upstream url' in git_dict: + out.append("U: %s" % git_dict['upstream url']) + if 'upstream vcs' in git_dict: + out.append("V: %s" % git_dict['upstream vcs']) + if 'comments' in git_dict: + for line in git_dict['comments']: + out.append("C: %s" % line) + return "\n".join(out)+"\n" + + +if __name__ == '__main__': + main(sys.argv) + -- 2.7.4