From: Hasan Wan Date: Sun, 6 Jan 2013 13:05:42 +0000 (+0800) Subject: impove the function of linkedbuild X-Git-Tag: 0.12~76 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9ae607d9f7e0a0a43ce1b35333d1052ef40a9a7;p=services%2Fjenkins-scripts.git impove the function of linkedbuild Change-Id: Idcc35e2760c2a4204baf045925435bd435c9cb33 Signed-off-by: Hasan Wan --- diff --git a/common/tempbuildpkg.py b/common/tempbuildpkg.py index 5259814..453e718 100644 --- a/common/tempbuildpkg.py +++ b/common/tempbuildpkg.py @@ -5,6 +5,10 @@ import base64 import runner import buildservice +from urllib import quote_plus +from osc import core +from xml.etree import cElementTree as ET + def encode_passwd(passwd): '''encode passwd by bz2 and base64''' return base64.b64encode(passwd.encode('bz2')) @@ -84,8 +88,25 @@ class BuildService2(buildservice.BuildService): self.apiurl = apiurl tmpf = Temp(prefix='.oscrc', content=oscrc) - oscrcpath = tmpf.path - buildservice.BuildService(apiurl, oscrc=oscrcpath) + self.oscrcpath = tmpf.path + buildservice.BuildService(apiurl, oscrc=self.oscrcpath) + + def update_meta(self, project, metaconf): + """ + update meta configuration for project + """ + meta_url = core.make_meta_url('prj', + path_args=quote_plus(project)) + + core.http_PUT(meta_url, file=metaconf) + + def get_meta(self, project): + """ + update meta configuration for project + """ + meta_url = core.make_meta_url('prj', + path_args=quote_plus(project)) + return core.http_GET(meta_url).readlines() class TempPackageBuild: @@ -178,21 +199,6 @@ class TempPackageBuild: def del_itself(self): self.bs.deleteProject(self.project) -PRJ_TEMPLATE = """ - - %(desp)s - - - - - <%(build)s/> - - - - i586 - -""" - class TempBuildService(): def __init__(self, project, apiurl, apiuser, apipasswd): @@ -205,7 +211,6 @@ class TempBuildService(): return self.bs.getRepoState(self.project) def cleanup(self): - os.system("osc -H -d -v rdelete --recursive %s -m 'deleted'" %(self.project)) return self.bs.deleteProject(self.project) def is_published(self): @@ -251,34 +256,48 @@ class TempBuildService(): if not found: print "did not find any image configurations" - def disable_build(self, user): - - targetmeta = """ - - - - - - <%(build)s/> - -"""% {'target': self.project, 'user': user, 'build': 'disable'} - print targetmeta + + def disable_build(self): + """ disable the project""" + origin_meta = self.bs.get_meta(self.project) + + root = ET.fromstringlist(origin_meta) + build = root.find('build') + + if build: + build.clear() + build.append(ET.Element('disable')) + else: + build = ET.Element('build') + build.append(ET.Element('disable')) + root.append(build) + fileh, filename = tempfile.mkstemp(prefix="osc_metafile.", suffix=".xml", text=True) - os.write(fileh, targetmeta) + os.write(fileh, ET.tostring(root)) + + self.bs.update_meta(self.project, filename) + os.close(fileh) - os.system("osc -d -v meta prj %s -F %s" %(self.project, filename)) - sys.stdout.flush() os.unlink(filename) - - def link_project(self, src, user, desp = ''): - targetmeta = PRJ_TEMPLATE % {'target': self.project, 'src': src, - 'user': user, 'build': 'enable', - 'desp': desp} + + def linkbuild_localdep(self, desp=''): + """ Link the project build against repo with dependency (localdep)""" + origin_meta = self.bs.get_meta(self.project) + + root = ET.fromstringlist(origin_meta) + for repo_setting in root.findall('repository'): + repo_setting.set('linkedbuild', 'localdep') + + if desp: + description = root.find('description') + description.text = desp fileh, filename = tempfile.mkstemp(prefix="osc_metafile.", suffix=".xml", text=True) - os.write(fileh, targetmeta) + os.write(fileh, ET.tostring(root)) + + self.bs.update_meta(self.project, filename) + os.close(fileh) - os.system("osc meta prj %s -F %s" %(self.project, filename)) os.unlink(filename) diff --git a/repomaker/__init__.py b/repomaker/__init__.py index 35f308e..a6b25ce 100644 --- a/repomaker/__init__.py +++ b/repomaker/__init__.py @@ -762,10 +762,14 @@ class ReviewRepo(RepoManager): def get_gitinfo(self): ret_dict = {} + meta = self.bs.get_meta(self.project) - stdin, stdout = os.popen2("osc meta prj %s" %self.project) + try: + root = ET.fromstringlist(meta) + except Exception, e: + print e + return {} - root = ET.parse(stdout) if root: try: for line in root.find('description').text.split('\n'): diff --git a/testprojects/prerelease.py b/testprojects/prerelease.py index 7e4d3ab..b2b1144 100644 --- a/testprojects/prerelease.py +++ b/testprojects/prerelease.py @@ -59,12 +59,12 @@ class PreRelease: print "Temporary review project created on OBS: %s" %(self.obs_project) - project_info = "OBS_REQ_PRJ: %s\n\GIT_PROJECT: %s\n\GIT_TAG: %s\n" %( + project_info = "OBS_REQ_PRJ: %s\nGIT_PROJECT: %s\nGIT_TAG: %s\n" %( self.target_project, self.git_project, self.git_tag) - bs.link_project(self.target_project, self.user, desp = project_info) + bs.linkbuild_localdep(desp = project_info) time.sleep(2)