From: Yonghee Han Date: Mon, 28 Nov 2016 00:06:23 +0000 (+0900) Subject: add lock/unlock function for the re.job X-Git-Tag: submit/trunk/20190927.012743~574^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F34%2F100334%2F1;p=services%2Fjenkins-scripts.git add lock/unlock function for the re.job cmd: unlock cmd: lock Change-Id: I9e22dae616a8ff3023dbc9399a5340c65c5a95ea --- diff --git a/common/buildservice.py b/common/buildservice.py index 0fc06bb..1e64841 100755 --- a/common/buildservice.py +++ b/common/buildservice.py @@ -977,3 +977,63 @@ class BuildService(OSC): ''.join([node.get('project') + '/' + node.get('package') for node in s.findall('linked')]) return s_dict + def is_lock_project(self, project): + """ + is lock project + """ + flag = 'lock' + value = 'enable' + meta = self.get_meta(project) + root = ElementTree.fromstring(meta) + elem = root.find(flag) + if elem is None: + return False + + return True + + def set_lock_project(self, project): + """ + set lock project in meta + """ + flag = 'lock' + value = 'enable' + meta = self.get_meta(project) + root = ElementTree.fromstring(meta) + elem = root.find(flag) + if elem is None: + elem = ElementTree.SubElement(root, flag) + else: + # remove all globel subelements, i.e. subelements without + # properties: or + for subelem in list(elem): + if not subelem.keys(): + elem.remove(subelem) + ElementTree.SubElement(elem, value) + self.set_meta(ElementTree.tostring(root), project) + + def set_unlock_project(self, project, comment): + """ + set unlock project + """ + flag = 'lock' + value = 'enable' + meta = self.get_meta(project) + root = ElementTree.fromstring(meta) + elem = root.find(flag) + if elem is None: + raise ObsError("This project is not locked status") + + query = { 'cmd': 'unlock' } + if comment: + query['comment'] = comment + else: + raise ObsError("could not unlock for project") + + u = core.makeurl(self.apiurl, ['source', project], query=query) + try: + f = core.http_POST(u) + except urllib2.HTTPError, e: + raise ObsError("could not unlock for project \'%s\'" % (project)) + + return + diff --git a/job_re.py b/job_re.py index 6bee2d2..a1027fb 100755 --- a/job_re.py +++ b/job_re.py @@ -103,6 +103,10 @@ def main(): if action in ("accept", "accepted", "reject", "declined"): state = "accepted" if action == "accept" or action == "accepted" else "declined" print "Submission %s has been %sed" % (submission, action) + prj = get_project_by_name(build, submission, target_project)[0] + if build.is_lock_project(prj): + build.set_unlock_project(prj, comment) + return accept_or_reject(build, submission, state, target_project, comment) elif action == "rebuild": @@ -119,11 +123,24 @@ def main(): print "Submission %s has been rebuilt" % submission elif action == "remove": prj = get_project_by_name(build, submission, target_project)[0] + if build.is_lock_project(prj): + build.set_unlock_project(prj, comment) build.delete_project(prj, force=True, msg=comment) print "Submission %s has been removed" % submission elif action in ("lock", "unlock"): prj = get_project_by_name(build, submission, target_project)[0] - status = "disable" if action == "lock" else "enable" + if action == "lock": + build.set_lock_project(prj) + elif action == "unlock": + comment = "Comments: submission %s \n" \ + % (submission) + build.set_unlock_project(prj, comment) + else: + print "exception" + print "Submission %s has been %sed" % (submission, action) + elif action in ("enable", "disable"): + prj = get_project_by_name(build, submission, target_project)[0] + status = "disable" if action == "disable" else "enable" build.set_global_flag("build", status, prj) print "Submission %s has been %sed" % (submission, action) else: