From ff9a5f1933f1d929f3fb4f28bbe6f84cd649af5e Mon Sep 17 00:00:00 2001 From: Junghyun Kim Date: Tue, 28 Feb 2017 13:17:52 +0900 Subject: [PATCH] NEW JOB: update_scm_meta_git_for_dashboard This job makes two mappings: 1) mappings between git projects and gerrit domans 2) mappings between gerrit domains and user-emails This information is saved in JSON format. This will be used in Tizen dashboard. -- Previous version uses source management by Jenkins, but it does not work properly. Hence, it is changed to cloning git repositories manually. Change-Id: I1198143e9f72a46807ffffb2d841f4c9c792c1dd Signed-off-by: Junghyun Kim --- job_update_scm_meta_git_for_dashboard.py | 180 +++++++++++++++++++++++++++++++ packaging/jenkins-scripts.spec | 1 + 2 files changed, 181 insertions(+) create mode 100644 job_update_scm_meta_git_for_dashboard.py diff --git a/job_update_scm_meta_git_for_dashboard.py b/job_update_scm_meta_git_for_dashboard.py new file mode 100644 index 0000000..25ba98f --- /dev/null +++ b/job_update_scm_meta_git_for_dashboard.py @@ -0,0 +1,180 @@ +#!/usr/bin/python +import json +import os +import copy +from common.utils import sync +from common.gerrit import Gerrit, get_gerrit_event +from common.git import clone_gitproject + +#================================================================================ +# class DomainUserMap +#================================================================================ +class DomainUserMap: + def __init__(self, filename): + self.f = open(filename, "r") + self.domain_user_map = {} + self.parse_domain(self.f) + + def __del__(self): + self.f.close() + + def parse_email(self, line): + lpos = line.find("<"); + rpos = line.rfind(">"); + return line[lpos+1 : rpos].strip() + + def append_person(self, level, email): + if level not in self.domain_user_map[self.cur_domain]: + self.domain_user_map[self.cur_domain][level] = [] + + self.domain_user_map[self.cur_domain][level].append(email) + + def parse_parent_domain(self, parent_domain): + # propagate parent domain's info + self.domain_user_map[self.cur_domain] = copy.deepcopy(self.domain_user_map[parent_domain]) + + + def parse_domain_line(self, line): + line = line.strip() + if len(line) == 0: + pass + elif line[0] == 'D': + # domain + self.cur_domain = line[3:] + if self.cur_domain in self.domain_user_map: + raise Exception("Already declared domain name: "+self.cur_domain) + self.domain_user_map[self.cur_domain] = {} + elif line[0] == 'N': + # parent domain + self.parse_parent_domain(line[3:]) + elif line[0] == 'A': + # architect + self.append_person("A", self.parse_email(line)) + elif line[0] == 'M': + self.append_person("M", self.parse_email(line)) + # maintainer + elif line[0] == 'I': + # integrator + self.append_person("I", self.parse_email(line)) + elif line[0] == 'R': + # reviewer + self.append_person("R", self.parse_email(line)) + else: + print "undefined : ", line, + + def parse_domain(self, f): + while True: + line = f.readline() + if not line: break; + self.parse_domain_line(line) + + def dump(self): + print self.domain_user_map + + def print_to_file(self, filename): + with open(filename, "w") as f: + f.write(json.dumps(self.domain_user_map)) + +#================================================================================ +# class GitDomainMap +#================================================================================ +class GitDomainMap: + def __init__(self, filename): + self.f = open(filename, "r") + self.git_domain_map = {} + self.parse_git_tree(self.f) + + def __del__(self): + self.f.close() + + def parse_line(self, line): + line = line.strip() + if len(line) == 0: + pass + elif line[0] == 'G': + # git path + self.cur_project = line[3:] + elif line[0] == 'D': + # domain + domain = line[3:] + if self.cur_project in self.git_domain_map: + raise Exception("A project " + self.cur_project + "is matched to more than two domains:(" + self.cur_project + "," + self.git_domain_map[self.cur_project] + ")!!") + self.git_domain_map[self.cur_project] = domain + elif line[0] == 'S': + # submit type + pass + elif line[0] == 'T': + # package type + pass + elif line[0] == 'O': + # owner + pass + elif line[0] == 'B': + # branch + pass + elif line[0] == 'L': + # license + pass + elif line[0] == 'C': + # comments + pass + else: + print "undefined : ", line, + + def parse_git_tree(self, f): + while True: + line = f.readline() + if not line: break; + self.parse_line(line) + + def dump(self): + print self.git_domain_map + + def print_to_file(self, filename): + with open(filename, "w") as f: + f.write(json.dumps(self.git_domain_map)) + +#================================================================================ +# generate_mappings +#================================================================================ +def generate_mappings(prjdir, target_dir): + d = DomainUserMap(os.path.join(prjdir, "domains")) + g = GitDomainMap(os.path.join(prjdir,"git-trees")) + + domain_user_map_filename = "domain_user_map.json" + git_domain_filename = "git_domain_map.json" + + if not os.path.exists(target_dir): + os.makedirs(target_dir) + + d.print_to_file(os.path.join(target_dir, domain_user_map_filename)); + g.print_to_file(os.path.join(target_dir, git_domain_filename)); + +#target_dir = ".dashboard" + +#generate_mappings(".", target_dir) +#exit(0) +#================================================================================ +# main +#================================================================================ +GERRIT_PROJECT = os.getenv('GERRIT_PROJECT') +WORKSPACE = os.getenv('WORKSPACE') +GERRIT_HOSTNAME = os.getenv('GERRIT_HOSTNAME') +GERRIT_USERNAME = os.getenv('GERRIT_USERNAME') +GERRIT_SSHPORT = os.getenv('GERRIT_SSHPORT') +GERRIT_SILENT_MODE = int(os.getenv('GERRIT_SILENT_MODE')) + +events = get_gerrit_event() +print(events) + +prjdir = os.path.join(WORKSPACE, "meta-git") + +clone_gitproject(GERRIT_PROJECT, prjdir) + +target_dir = ".dashboard" + +generate_mappings("meta-git", target_dir) + +sync_dest = os.path.join(os.getenv("IMG_SYNC_DEST_BASE"), "snapshots", target_dir) +# sync to the download server. +sync(target_dir, sync_dest) diff --git a/packaging/jenkins-scripts.spec b/packaging/jenkins-scripts.spec index 2c445ea..df1ef10 100644 --- a/packaging/jenkins-scripts.spec +++ b/packaging/jenkins-scripts.spec @@ -140,6 +140,7 @@ fi %{destdir}/job_add_git_tag.py %{destdir}/job_repa.py %{destdir}/job_trbs_test_result_receiver.py +%{destdir}/job_update_scm_meta_git_for_dashboard.py %dir %{destdir}/templates %{destdir}/templates/index.html %{destdir}/job_update_local_git.py -- 2.7.4