except (M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError), err:
raise errors.ObsError(str(err))
-PRJ_TEMPLATE = """<project name="%(target)s">
- <title></title>
- <description>%(desp)s</description>
- <person role="maintainer" userid="%(user)s"/>
- <person role="bugowner" userid="%(user)s"/>
- <link project="%(src)s"/>
- <build>
- <%(build)s/>
- </build>
- <repository name="standard" linkedbuild="localdep">
- <path repository="standard" project="%(src)s"/>
- <arch>i586</arch>
- </repository>
-</project>"""
-
-class TempBuildService():
-
- def __init__(self, project, apiurl = None, oscrc = None):
- self.project = project
- self.bs = BuildService(apiurl = apiurl, oscrc = oscrc)
-
- def get_repostatus(self):
- 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):
- try:
- return set(self.get_repostatus().values()) == set(['published'])
- except:
- return False
-
- def get_abs_repopath(self):
- # FIXME: hard code here
- return "/srv/obs/repos/%s" %(self.project.replace(":", ":/"))
-
- def _su_osbrun(self):
- os.setuid(getpwnam('obsrun').pw_uid)
- os.setgid(getpwnam('obsrun').pw_gid)
-
- def extract_image_ks(self):
- pg = re.compile("image-configurations.*.rpm")
- repopath = self.get_abs_repopath()
- found = False
- for root, dirs, files in os.walk(repopath):
- for f in files:
- print root,f
- if re.match(pg, f):
- print "image configurations found: %s/%s" %(root,f)
- tmpdir = tempfile.mkdtemp()
- pwd = os.getcwd()
- os.chdir(tmpdir)
- os.system("rpm2cpio %s/%s | cpio -idmv" %(root,f))
- os.system("mkdir -p %s/%s" %(repopath, 'pre-release-images/image-configs'))
-
- if os.path.exists("%s/usr/share/image-configurations/image-configs.xml" %tmpdir):
- shutil.copyfile("%s/usr/share/image-configurations/image-configs.xml" %tmpdir, '%s/pre-release-images/image-configs.xml' %repopath)
-
- os.system("cp %s/usr/share/image-configurations/*.ks %s/builddata/image-configs" %(tmpdir, repopath))
- os.chdir(pwd)
- shutil.rmtree(tmpdir)
- found = True
- break
-
- if found: break
-
- if not found:
- print "did not find any image configurations"
-
- def disable_build(self, user):
-
- targetmeta = """<project name="%(target)s">
- <title></title>
- <description></description>
- <person role="maintainer" userid="%(user)s"/>
- <person role="bugowner" userid="%(user)s"/>
- <build>
- <%(build)s/>
- </build>
-</project>"""% {'target': self.project, 'user': user, 'build': 'disable'}
- print targetmeta
- fileh, filename = tempfile.mkstemp(prefix="osc_metafile.",
- suffix=".xml", text=True)
- os.write(fileh, targetmeta)
- 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}
-
- fileh, filename = tempfile.mkstemp(prefix="osc_metafile.",
- suffix=".xml", text=True)
- os.write(fileh, targetmeta)
- os.close(fileh)
- os.system("osc meta prj %s -F %s" %(self.project, filename))
- os.unlink(filename)
import os
import time
-
+import tempfile
+import base64
import runner
import buildservice
+def encode_passwd(passwd):
+ '''encode passwd by bz2 and base64'''
+ return base64.b64encode(passwd.encode('bz2'))
+
+OSCRC_TEMPLATE = """[general]
+apiurl = %(apiurl)s
+plaintext_passwd=0
+use_keyring=0
+http_debug = %(http_debug)s
+debug = %(debug)s
+gnome_keyring=0
+[%(apiurl)s]
+user=%(user)s
+passx=%(passwdx)s
+"""
+
+
+# Copy from gitbuildsys.utils
+class Temp(object):
+ """
+ Create temporary file or directory.
+ Delete it automatically when object is destroyed.
+
+ """
+
+ def __init__(self, suffix='', prefix='tmp', dirn=None,
+ directory=False, content=None):
+ """
+ Create file or directory using tempfile.mk[sd]temp.
+ If content is provided write it to the file.
+
+ """
+ self.directory = directory
+ self.path = None
+
+ try:
+ if dirn:
+ target_dir = os.path.abspath(os.path.join(dirn, prefix))
+ else:
+ target_dir = os.path.abspath(prefix)
+ target_dir = os.path.dirname(target_dir)
+
+ if not os.path.exists(target_dir):
+ os.makedirs(target_dir)
+
+ if directory:
+ path = tempfile.mkdtemp(suffix, prefix, dirn)
+ else:
+ (fds, path) = tempfile.mkstemp(suffix, prefix, dirn)
+ os.close(fds)
+ if content:
+ with file(path, 'w+') as fobj:
+ fobj.write(content)
+ except OSError, err:
+ raise errors.GbsError("Failed to create dir or file on %s: %s" % \
+ (target_dir, str(err)))
+ self.path = path
+
+ def __del__(self):
+ """Remove it when object is destroyed."""
+ if self.path and os.path.exists(self.path):
+ if self.directory:
+ shutil.rmtree(self.path, True)
+ else:
+ os.unlink(self.path)
+
+
+class BuildService2(buildservice.BuildService):
+ def __init__(self, apiurl, apiuser, apipasswd):
+ oscrc = OSCRC_TEMPLATE % {
+ "http_debug": 0,
+ "debug": 0,
+ "apiurl": apiurl,
+ "user": apiuser,
+ "passwdx": encode_passwd(apipasswd)
+ }
+
+ self.apiurl = apiurl
+ tmpf = Temp(prefix='.oscrc', content=oscrc)
+ oscrcpath = tmpf.path
+ buildservice.BuildService(apiurl, oscrc=oscrcpath)
+
class TempPackageBuild:
def __init__(self, apiurl, oscrc, project, package = None):
def del_itself(self):
self.bs.deleteProject(self.project)
+
+PRJ_TEMPLATE = """<project name="%(target)s">
+ <title></title>
+ <description>%(desp)s</description>
+ <person role="maintainer" userid="%(user)s"/>
+ <person role="bugowner" userid="%(user)s"/>
+ <link project="%(src)s"/>
+ <build>
+ <%(build)s/>
+ </build>
+ <repository name="standard" linkedbuild="localdep">
+ <path repository="standard" project="%(src)s"/>
+ <arch>i586</arch>
+ </repository>
+</project>"""
+
+class TempBuildService():
+
+ def __init__(self, project, apiurl, apiuser, apipasswd):
+ self.project = project
+ self.bs = BuildService2(apiurl = apiurl,
+ apiuser = apiuser,
+ apipasswd = apipasswd)
+
+ def get_repostatus(self):
+ 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):
+ try:
+ return set(self.get_repostatus().values()) == set(['published'])
+ except:
+ return False
+
+ def get_abs_repopath(self):
+ # FIXME: hard code here
+ return "/srv/obs/repos/%s" %(self.project.replace(":", ":/"))
+
+ def _su_osbrun(self):
+ os.setuid(getpwnam('obsrun').pw_uid)
+ os.setgid(getpwnam('obsrun').pw_gid)
+
+ def extract_image_ks(self):
+ pg = re.compile("image-configurations.*.rpm")
+ repopath = self.get_abs_repopath()
+ found = False
+ for root, dirs, files in os.walk(repopath):
+ for f in files:
+ print root,f
+ if re.match(pg, f):
+ print "image configurations found: %s/%s" %(root,f)
+ tmpdir = tempfile.mkdtemp()
+ pwd = os.getcwd()
+ os.chdir(tmpdir)
+ os.system("rpm2cpio %s/%s | cpio -idmv" %(root,f))
+ os.system("mkdir -p %s/%s" %(repopath, 'pre-release-images/image-configs'))
+
+ if os.path.exists("%s/usr/share/image-configurations/image-configs.xml" %tmpdir):
+ shutil.copyfile("%s/usr/share/image-configurations/image-configs.xml" %tmpdir, '%s/pre-release-images/image-configs.xml' %repopath)
+
+ os.system("cp %s/usr/share/image-configurations/*.ks %s/builddata/image-configs" %(tmpdir, repopath))
+ os.chdir(pwd)
+ shutil.rmtree(tmpdir)
+ found = True
+ break
+
+ if found: break
+
+ if not found:
+ print "did not find any image configurations"
+
+ def disable_build(self, user):
+
+ targetmeta = """<project name="%(target)s">
+ <title></title>
+ <description></description>
+ <person role="maintainer" userid="%(user)s"/>
+ <person role="bugowner" userid="%(user)s"/>
+ <build>
+ <%(build)s/>
+ </build>
+</project>"""% {'target': self.project, 'user': user, 'build': 'disable'}
+ print targetmeta
+ fileh, filename = tempfile.mkstemp(prefix="osc_metafile.",
+ suffix=".xml", text=True)
+ os.write(fileh, targetmeta)
+ 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}
+
+ fileh, filename = tempfile.mkstemp(prefix="osc_metafile.",
+ suffix=".xml", text=True)
+ os.write(fileh, targetmeta)
+ os.close(fileh)
+ os.system("osc meta prj %s -F %s" %(self.project, filename))
+ os.unlink(filename)
from common.envparas import export
from common import utils
from common import git
-from common import buildservice
+from common.tempbuildpkg import BuildService2, TempBuildService
from common.buildtrigger import trigger_info
-from common.buildservice import TempBuildService
from testprojects.prerelease import PreRelease
import os
import tempfile
'WORKSPACE',
'TRIGGER_INFO',
'OBS_API_URL',
- 'OBS_OSCRC_PATH',
+ 'OBS_API_USERNAME',
+ 'OBS_API_PASSWD',
'GERRIT_HOSTNAME',
'GERRIT_USERNAME',
'GERRIT_SSHPORT',
'PATH_BUILDS',
- 'PATH_OSCRC',
'GIT_PROJECT',
'GIT_CACHE_DIR']
mygit = git.Git(prjdir)
- bs = TempBuildService(prerelease.obs_project_name(), OBS_API_URL, OBS_OSCRC_PATH)
+ bs = TempBuildService(prerelease.obs_project_name(), OBS_API_URL, OBS_API_USERNAME, OBS_API_PASSWD)
prerelease.create(bs, mygit)
def cleanup(prerelease):
- bs = TempBuildService(prerelease.obs_project, OBS_API_URL, PATH_OSCRC)
+ bs = TempBuildService(prerelease.obs_project, OBS_API_URL, OBS_API_USERNAME, OBS_API_PASSWD)
bs.cleanup()
print "OBS Project %s deleted" %prerelease.obs_project
locals().update(trigger_info(TRIGGER_INFO))
- prerelease = PreRelease(OBS_REQ_PRJ, GERRIT_USERNAME, GIT_TAG, GIT_PROJECT)
+ prerelease = PreRelease(OBS_REQ_PRJ, OBS_API_USERNAME, GIT_TAG, GIT_PROJECT)
if action == 'create':
create(prerelease)
import simplejson as json
from common.envparas import export
-from common.buildservice import BuildService, TempBuildService
+from common.tempbuildpkg import BuildService2
from common.buildtrigger import trigger_info, trigger_next
import repomaker
import base64
PARAM_LIST = ['PATH_BUILDS',
'PATH_REPO_CONF',
'OBS_API_URL',
- 'OBS_USERNAME',
- 'PATH_OSCRC',
+ 'OBS_API_USERNAME',
+ 'OBS_API_PASSWD',
'WORKSPACE',
'PATH_RAW_REPOS',
'OBS_TRIGGERS_PATH',
'OBS_BUILDING_PATH',
+ 'REPOMAKER_PROJECTS',
'NO_ARMV8',
'MAILTO',
'SANDBOX_REPO_BASEURL',
export(PARAM_LIST, locals())
+def is_intrested_project(project):
+ for keyword in REPOMAKER_PROJECTS.split(' '):
+ if keyword.endswith('*'):
+ if project.startswith(keyword[:-1]):
+ return True
+ else:
+ if project == keyword:
+ return True
+ return False
+
def image_dispatch(repoinfo):
ready = repoinfo['SNAPSHOT']
def create_repo(serverconf, event_fields):
try:
- bs = BuildService(apiurl=serverconf.apiurl, oscrc=serverconf.oscrc)
+ bs = BuildService2(apiurl = serverconf.apiurl,
+ apiuser = serverconf.apiuser,
+ apipasswd = serverconf.apipasswd)
except Exception, e:
print 'OBS access errors: ', str(e)
sys.exit(-1)
AddRepos: %(addrepos)s
Target: %(target)s
SandboxOf: %(sandboxof)s
- SnapshotDir: /srv/snapshots/pre-release/
+ SnapshotDir: %(path_builds)s/pre-release/
Release: "%(release)s"
Architectures: %(arch)s
"""
project = event_files["project"]
repo = event_files["repo"]
- match = re.match("(.*):prerelease:([\.\w-]*)", project)
+ match = re.match(".*:prerelease:(.*):([\.\w-]*)", project)
if not match:
raise Exception, "Ivalid project name found"
"sandbox_repo": os.path.basename(repos_conf.get_repo(target_prj)['Location']),
"project": project,
"target": repo,
+ "path_builds": PATH_BUILDS,
"release": timestamp,
"arch":["ia32"],
"addrepos": ["Tizen:Base"] #FIXME
server_conf.raw_repos = PATH_RAW_REPOS
server_conf.repos_conf = PATH_REPO_CONF
server_conf.apiurl = OBS_API_URL
- server_conf.oscrc = PATH_OSCRC
+ server_conf.apiuser = OBS_API_USERNAME
+ server_conf.apipasswd = OBS_API_PASSWD
server_conf.builds = PATH_BUILDS
server_conf.obs_triggers_path = OBS_TRIGGERS_PATH or '/srv/obs/repos_sync'
server_conf.obs_building_path = OBS_BUILDING_PATH or '/srv/obs/build'
repo_conf_fn = None
event_fields = trigger_info(TRIGGER_INFO)
-
+
if not event_fields:
print "Invalid OBS event: %s" %(OBS_EVENT_STRING)
sys.exit(-1)
+ project = event_fields["project"]
+ if not is_intrested_project(project):
+ print "Pass, not intrested project %s" %project
+ sys.exit(0)
+
# Pre-release image creation temp project
tempbuild = None
if event_fields["project"].find(":prerelease:") > 0:
server_conf.repos_conf = temp_conf_fn
project = event_fields["project"]
- match = re.match("(.*):prerelease:([\.\w-]*)", project)
-
- bs = BuildService(apiurl=server_conf.apiurl, oscrc=server_conf.oscrc)
+ bs = BuildService2(apiurl = server_conf.apiurl,
+ apiuser = server_conf.apiuser,
+ apipasswd = server_conf.apipasswd)
review_repo = repomaker.ReviewRepo(project, server_conf, bs)
review_repo.create()