From 5448ea463a44c5c5dee8fb17df40c5f7c269b1ea Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Tue, 14 Jun 2016 16:38:42 +0900 Subject: [PATCH] Job : check_scm_meta_git Add new feature for using scm/meta/git. It's submit type option in git-trees. It's add checking syntax and applying to system related submit type option. Change-Id: Iaeec73c57b30e4d47d8e3f901c0ed5c6ec3f32cf Signed-off-by: Sehong Na --- common/apply_scm_meta_git.py | 42 ++++++++++++++++++++----------- common/check_scm_meta_git.py | 60 +++++++++++++++++++++++++++++++++----------- job_check_scm_meta_git.py | 12 ++++----- scripts/check_section.sh | 2 +- scripts/get_git_desc_info.sh | 2 +- 5 files changed, 81 insertions(+), 37 deletions(-) diff --git a/common/apply_scm_meta_git.py b/common/apply_scm_meta_git.py index 8b34808..ed01bd9 100644 --- a/common/apply_scm_meta_git.py +++ b/common/apply_scm_meta_git.py @@ -46,25 +46,25 @@ def get_diff_info(dic): break def get_key_list(dic, readme_file): - with open('%s' % readme_file, 'r') as lines: - read_status = False - cur_file = '' - for line in lines: - if line.split(':')[0] == 'Filename': - cur_file = line.split(':')[1].split('"')[1] + with open('%s' % readme_file, 'r') as lines: + read_status = False + cur_file = '' + for line in lines: + if line.split(':')[0] == 'Filename': + cur_file = line.split(':')[1].split('"')[1] if cur_file in meta_file_list: - read_status = True - continue - if read_status: - if line.strip() == '': - read_status = False - else: + read_status = True + continue + if read_status: + if line.strip() == '': + read_status = False + else: temp = line.strip().split(' ') if temp[len(temp) - 2] + ' ' + temp[len(temp) - 1] == 'Read Only': attr = 1 else: attr = 0 - dic[cur_file][line.strip()[0]] = attr + dic[cur_file][line.strip()[0]] = attr def init_info(file_list, readme_file, sdir): global meta_file_list @@ -133,7 +133,7 @@ def arrange_desc(desc_list, git_list): final_desc = final_desc + '; ' final_desc = final_desc.rstrip(' ') - ret_list.append([git_list[i], final_desc]) + ret_list.append([git_list[i], final_desc]) return ret_list @@ -148,11 +148,17 @@ def get_desc_list(git_list): def get_domain_info(name, server): return subprocess.check_output("ssh -p %s %s@%s gerrit ls-projects --has-acl-for \'%s\ -\ Maintainers\' --type ALL | grep scm/acls/domain_" % (server.port, server.account, server.url, name.replace(' ', '\ ')), shell = True).strip() +def get_submit_type_info(git): + git_line = int(subprocess.check_output("cat git-trees | grep -n %s" % git, shell = True).strip().split(':')[0]) + return subprocess.check_output("head -%d git-trees | tail -1" % (git_line + 2), shell = True).strip() + def apply_git_trees(desc_list, server, cur_file): for i in range(len(desc_list)): git = desc_list[i][0] desc = desc_list[i][1].replace('\\n', '\\\r\\\n').replace('; ', '; \\\r\\\n').replace(' ', '\ ').replace('&', '\&') domain_info = get_domain_info(desc_list[i][1].split(';')[0].split('Domain:')[1].strip(), server) + submit_type_info = get_submit_type_info(git) + submit_type_info = submit_type_info.split('%s: ' % submit_type_info[0])[1] line_num = int(subprocess.check_output("grep -n %s %s" % (git, cur_file), shell = True).split(':')[0]) line_message = "G: " + git @@ -171,6 +177,14 @@ def apply_git_trees(desc_list, server, cur_file): else: print_message('OK', cur_file, line_num, line_message, 'apply_git_trees - domain') + ## set submit type + ret = os.system('ssh -p %s %s@%s gerrit set-project %s -t %s' % (server.port, server.account, server.url, git, submit_type_info)) + if ret: + raise SyntaxError(print_message('Error', cur_file, line_num, line_message, "%s can't set as %s." % (git, submit_type_info))) + else: + print_message('OK', cur_file, line_num, line_message, 'apply_git_trees - submit type') + + def apply_member_to_domain(cur_file, obj, line_num, line_message, cur_domain, server): if obj[0] == '-': opt = '-r' diff --git a/common/check_scm_meta_git.py b/common/check_scm_meta_git.py index 32ae651..a42cf3b 100644 --- a/common/check_scm_meta_git.py +++ b/common/check_scm_meta_git.py @@ -46,27 +46,27 @@ def get_diff_info(dic): break def get_key_list(dic, readme_file): - with open('%s' % readme_file, 'r') as lines: - read_status = False - cur_file = '' - for line in lines: - if line.split(':')[0] == 'Filename': - cur_file = line.split(':')[1].split('"')[1] + with open('%s' % readme_file, 'r') as lines: + read_status = False + cur_file = '' + for line in lines: + if line.split(':')[0] == 'Filename': + cur_file = line.split(':')[1].split('"')[1] if cur_file in meta_file_list: - read_status = True - continue - if read_status: - if line.strip() == '': - read_status = False - else: + read_status = True + continue + if read_status: + if line.strip() == '': + read_status = False + else: temp = line.strip().split(' ') if temp[len(temp) - 2] + ' ' + temp[len(temp) - 1] == 'Read Only': attr = 1 else: attr = 0 - dic[cur_file][line.strip()[0]] = attr + dic[cur_file][line.strip()[0]] = attr -def init_info(file_list, readme_file, sdir): +def init_info(file_list, readme_file, sdir, server): global meta_file_list global meta_info global key_list @@ -87,11 +87,15 @@ def init_info(file_list, readme_file, sdir): global group_list global git_domain + global git_submit_type global domain_list + global submit_type_list group_list = {'A' : 'Architects', 'M' : 'Maintainers', 'I' : 'Integrators', 'R' : 'Reviewers'} git_domain = {} + git_submit_type = {} domain_list = subprocess.check_output("cat domains | grep D:", shell = True).split('\n') + submit_type_list = subprocess.check_output("cat %s | grep \'S\ -\ \'" % readme_file, shell = True).strip().split(':')[1].strip().strip('[').strip(']').split(' | ') def print_message(status, fn, ln, lm, comment): if status == 'OK': @@ -169,6 +173,22 @@ def check_git_domain(cur_file, obj, line_num, line_message, cur_git): else: git_domain[cur_git] = [[line_num, line_message]] +def check_submit_type(cur_file, obj, line_num, line_message, cur_git): + if obj[0] == '+': + ret = 1 + for i in range(len(submit_type_list)): + if submit_type_list[i] == line_message.split('S: ')[1]: + ret = 0 + break + if ret: + raise SyntaxError(print_message('Error', cur_file, line_num, line_message, "%s is wrong submit type." % line_message.split('S: ')[1])) + else: + print_message('OK', cur_file, line_num, line_message, 'check_submit_type') + if cur_git in git_submit_type: + git_submit_type[cur_git].append([line_num, line_message]) + else: + git_submit_type[cur_git] = [[line_num, line_message]] + def is_email(name): ret = '' @@ -258,6 +278,8 @@ def check_semantics(cur_file, obj, line_num, line_message, cur_section, server): elif cur_file == 'git-trees': if obj[1] == 'D': check_git_domain(cur_file, obj, line_num, line_message, cur_section) + if obj[1] == 'S': + check_submit_type(cur_file, obj, line_num, line_message, cur_section) if obj[1] == 'O': check_user(cur_file, obj, line_num, line_message, server) @@ -286,13 +308,21 @@ def check_domain_edit(): else: print_message('OK', 'git-trees', git_domain[git_project][0][0], git_domain[git_project][0][1], 'check_domain_edit') +def check_submit_type_edit(): + for git_project in git_submit_type.keys(): + if len(git_submit_type[git_project]) != 2: + raise SyntaxError(print_message('Error', 'git-trees', git_submit_type[git_project][0][0], git_submit_type[git_project][0][1], "Submit type can't be added or removed.")) + else: + print_message('OK', 'git-trees', git_submit_type[git_project][0][0], git_submit_type[git_project][0][1], 'check_submit_type_edit') + def check_patchset_is_valid(meta_files, readme_file, sdir, port, account, url): - init_info(meta_files, readme_file, sdir) + init_info(meta_files, readme_file, sdir, Server(port, account, url)) try: check_each_object(Server(port, account, url)) check_domain_edit() + check_submit_type_edit() except SyntaxError, ret: return ret diff --git a/job_check_scm_meta_git.py b/job_check_scm_meta_git.py index 1f798a2..718ec40 100755 --- a/job_check_scm_meta_git.py +++ b/job_check_scm_meta_git.py @@ -48,12 +48,12 @@ def check_scm_meta_git(gerrit, events): def update_system(gerrit, events): ret = apply_to_system(meta_file_list, readme_file, scripts_path, gerrit.port, gerrit.username, gerrit.host) - if ret: - gerrit.review(commit = events['patchset_revision'], message = "There is something wrong. Contact to %s" % events['event_account_email']) - return 1 - else: - gerrit.review(commit = events['patchset_revision'], message = "Complete to apply to system.") - return 0 + if ret: + gerrit.review(commit = events['patchset_revision'], message = "There is something wrong. Contact to %s" % events['event_account_email']) + return 1 + else: + gerrit.review(commit = events['patchset_revision'], message = "Complete to apply to system.") + return 0 def main(): events = get_gerrit_event() diff --git a/scripts/check_section.sh b/scripts/check_section.sh index 0d586c4..e34e702 100755 --- a/scripts/check_section.sh +++ b/scripts/check_section.sh @@ -16,8 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -"""Search first line in current paragraph""" +### "Search first line in current paragraph" ### CNT=$1 INDEX=$2 diff --git a/scripts/get_git_desc_info.sh b/scripts/get_git_desc_info.sh index 5502c02..3283a38 100755 --- a/scripts/get_git_desc_info.sh +++ b/scripts/get_git_desc_info.sh @@ -16,8 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -"""Search some data in git-trees file""" +### "Search some data in git-trees file" ### GIT=$1 -- 2.7.4