本文整理汇总了Python中buildservice.BuildService类的典型用法代码示例。如果您正苦于以下问题:Python BuildService类的具体用法?Python BuildService怎么用?Python BuildService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuildService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def check_and_mark_project(self, project, attribute):
"""
Checks an OBS project for the existence of attribute needs_nightly_build.
Return True if the project didn't have one and create the attibute.False
otherwise.
"""
if self.obs.projectAttributeExists(project, attribute):
return False
else:
self.obs.createProjectAttribute(project,
attribute)
return True
def handle_wi(self, wid):
""" actual job thread """
wid.status = False
wid.fields.needs_build = False
self.setup_obs(wid.fields.ev.namespace)
if wid.params.delete:
stat = self.obs.deleteProjectAttribute(wid.fields.project,
wid.params.attribute)
if stat:
wid.status = True
else:
wid.status = False
else:
if self.check_and_mark_project(wid.fields.project,
wid.params.attribute):
wid.fields.needs_build = True
else:
wid.fields.needs_build = False
示例2: get_repositories
def get_repositories(self, wid, project):
if not wid.fields.ev or not wid.fields.ev.namespace:
raise RuntimeError("Missing field: ev.namespace")
obs = BuildService(oscrc=self.oscrc, apiurl=wid.fields.ev.namespace)
try:
repositories = obs.getProjectRepositories(project)
except HTTPError, exobj:
if exobj.code == 404:
raise RuntimeError("Project %s not found in OBS" % project)
raise
示例3: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def get_changes_file(self, prj, pkg, rev=None):
""" Get a package's changes file """
changelog = ""
file_list = self.obs.getPackageFileList(prj, pkg, revision=rev)
for fil in file_list:
if fil.endswith(".changes"):
changelog = self.obs.getFile(prj, pkg, fil)
return changelog
def handle_wi(self, wid):
""" actual job thread """
wid.result = False
missing = [name for name in ["project", "package"]
if not getattr(wid.fields, name, None)]
if missing:
raise RuntimeError("Missing mandatory field(s): %s" %
", ".join(missing))
self.setup_obs(wid.fields.ev.namespace)
wid.fields.changelog = self.get_changes_file(
wid.fields.project,
wid.fields.package)
wid.result = True
示例4: ParticipantHandler
class ParticipantHandler(object):
"""Participant class as defined by the SkyNET API"""
def __init__(self):
self.obs = None
self.oscrc = None
self.validator = Validator()
def handle_wi_control(self, ctrl):
"""Job control thread"""
pass
def handle_lifecycle_control(self, ctrl):
"""Handle messages for the participant itself, like start and stop."""
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
"""Setup the Buildservice instance
:param namespace: Alias to the OBS apiurl.
"""
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def check_spec_version_match(self, version, prj, pkg, rev=None):
"""Check that spec version matches given version"""
spec = ""
file_list = self.obs.getPackageFileList(prj, pkg, revision=rev)
for fil in file_list:
if fil.endswith(".spec"):
spec = self.obs.getFile(prj, pkg, fil, revision=rev)
break
if not spec:
return False, "No specfile in %s" % pkg
with NamedTemporaryFile() as specf:
specf.write(spec)
specf.flush()
try:
specob = parse_spec(specf.name)
except ValueError, exobj:
return False, "Could not parse spec in %s: %s" % (pkg, exobj)
src_hdrs = [pkg for pkg in specob.packages if pkg.header.isSource()][0]
spec_version = src_hdrs.header[rpm.RPMTAG_VERSION]
if spec_version != version.split('-')[0]:
return False, "Last changelog version %s does not match" \
" version %s in spec file." % (version, spec_version)
return True, None
示例5: setup_obs
def setup_obs(self, namespace):
"""Setup the Buildservice instance
Using namespace as an alias to the apiurl.
"""
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
示例6: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.reposerver = ""
self.ksstore = ""
self.oscrc = ""
self.namespace = None
self.obs = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
self.reposerver = ctrl.config.get("build_ks", "reposerver")
self.ksstore = ctrl.config.get("build_ks", "ksstore")
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def get_repositories(self, wid, project):
if not (wid.fields.ev and wid.fields.ev.namespace):
raise RuntimeError("Missing field: ev.namespace")
if self.obs is None or self.namespace != wid.fields.ev.namespace:
self.namespace = wid.fields.ev.namespace
self.obs = BuildService(oscrc=self.oscrc, apiurl=self.namespace)
try:
repositories = self.obs.getProjectRepositories(project)
except HTTPError, exobj:
if exobj.code == 404:
raise RuntimeError("Project %s not found in OBS" % project)
raise
return repositories
示例7: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def handle_wi(self, wid):
""" """
self.setup_obs(wid.fields.ev.namespace)
user = Verify.assertMandatoryParameter(wid, "user")
field = Verify.assertMandatoryParameter(wid, "field")
user_realname, user_email = self.obs.getUserData(user, "realname", "email")
wid.set_field(field + ".realname", user_realname)
wid.set_field(field + ".email", user_email)
示例8: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def handle_wi(self, wid):
""" actual job thread """
wid.result = False
if not wid.fields.msg:
wid.fields.msg = []
if not wid.fields.ev:
raise RuntimeError("Missing mandatory field 'ev'")
if not wid.fields.ev.namespace:
raise RuntimeError("Missing mandatory field 'ev.namespace'")
if not wid.fields.ev.actions:
raise RuntimeError("Missing mandatory field 'ev.actions'")
self.setup_obs(wid.fields.ev.namespace)
all_ok = True
for action in wid.fields.ev.actions:
if action['type'] != 'submit':
continue
if not self.obs.hasChanges(action['sourceproject'],
action['sourcepackage'],
action['sourcerevision'],
action['targetproject'],
action['targetpackage']):
wid.fields.msg.append(
"Package %(sourceproject)s %(sourcepackage)s"
" does not introduce any changes compared to"
" %(targetproject)s %(targetpackage)s" % action)
all_ok = False
wid.result = all_ok
示例9: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def get_changes_file(self, prj, pkg, rev=None):
""" Get a package's changes file """
changelog = ""
try:
file_list = self.obs.getPackageFileList(prj, pkg, revision=rev)
for fil in file_list:
if fil.endswith(".changes"):
changelog = self.obs.getFile(prj, pkg, fil, revision=rev)
except HTTPError, e:
if e.code == 404:
pass
return changelog
示例10: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def handle_wi(self, wid):
""" actual job thread """
wid.result = False
if not wid.fields.msg:
wid.fields.msg = []
if not wid.fields.ev or not wid.fields.ev.actions:
raise RuntimeError("Missing mandatory field 'ev.actions'")
self.setup_obs(wid.fields.ev.namespace)
for action in wid.fields.ev.actions:
if not self.obs.isMaintainer(action["sourceproject"],
wid.fields.ev.who):
wid.fields.status = "FAILED"
wid.fields.msg.append("%s who submitted request %s "\
"from project %s is not allowed to do "\
"so." % (wid.fields.ev.who,
wid.fields.ev.rid,
action["sourceproject"]))
return
wid.result = True
示例11: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def handle_wi(self, wid):
""" actual job thread """
wid.result = False
if not wid.fields.msg:
wid.fields.msg = []
if not wid.fields.mail_to:
wid.fields.mail_to = []
if not wid.fields.ev or not wid.fields.ev.who:
raise RuntimeError("Missing mandatory field 'ev.who'")
who = wid.fields.ev.who
self.setup_obs(wid.fields.ev.namespace)
user_email = self.obs.getUserEmail(who)
if user_email:
wid.fields.mail_to.append(user_email)
wid.result = True
else:
wid.fields.msg.append("User %s doesn't have an email" % who)
示例12: ParticipantHandler
class ParticipantHandler(object):
"""Participant class as defined by the SkyNET API."""
def __init__(self):
self.oscrc = None
self.obs = None
def handle_wi_control(self, ctrl):
"""Job control thread."""
pass
def handle_lifecycle_control(self, ctrl):
"""Participant control thread."""
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
"""Setup the Buildservice instance
Using namespace as an alias to the apiurl.
"""
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def build_trial_results(self, wid):
"""Main function to get new failures related to a build trial."""
wid.result = False
if not wid.fields.msg:
wid.fields.msg = []
target_prj = wid.fields.project
build_in_prj = wid.params.build_in
exclude_repos = wid.fields.exclude_repos or []
exclude_archs = wid.fields.exclude_archs or []
new_failures = set()
for target_repo in self.obs.getProjectRepositories(target_prj):
if target_repo in exclude_repos:
continue
archs = self.obs.getRepositoryArchs(target_prj, target_repo)
archs = [arch for arch in archs if arch not in exclude_archs]
# Get the repository of the build trial which builds against the
# required target repo in the target prj
build_in_repo = self.obs.getTargetRepo(build_in_prj, target_prj,
target_repo, archs)
# Get trial build results
trial_results = self.obs.getRepoResults(build_in_prj, build_in_repo)
# Get destination results
orig_results = self.obs.getRepoResults(target_prj, target_repo)
# compare them and return new failures
new_failures.update(get_new_failures(trial_results, orig_results,
archs))
if len(new_failures):
wid.fields.msg.append("During the trial build in %s, %s failed to"\
" build for one of the archs : %s" %
(build_in_prj, " ".join(new_failures),
" ".join(archs)))
wid.fields.new_failures = list(new_failures)
else:
wid.fields.msg.append("Trial build of packages in %s successful" %
build_in_prj)
wid.result = True
def handle_wi(self, wid):
"""Actual job thread."""
self.setup_obs(wid.fields.ev.namespace)
self.build_trial_results(wid)
示例13: ParticipantHandler
class ParticipantHandler(object):
""" Participant class as defined by the SkyNET API """
def __init__(self):
self.obs = None
self.oscrc = None
def handle_wi_control(self, ctrl):
""" job control thread """
pass
def handle_lifecycle_control(self, ctrl):
""" participant control thread """
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
""" setup the Buildservice instance using the namespace as an alias
to the apiurl """
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def get_l10n_stats(self, source_project, target_project, package):
tmp_dir_old = mkdtemp()
tmp_dir_new = mkdtemp()
old_ts_dir = tmp_dir_old + "/ts"
new_ts_dir = tmp_dir_new + "/ts"
target = self.obs.getTargets(str(source_project))[0]
#get src.rpm as it contains all .ts files
src_rpm = [rpm for rpm in self.obs.getBinaryList(
source_project, target, package) if "src.rpm" in rpm]
target_rpm = [rpm for rpm in self.obs.getBinaryList(
target_project, target, package) if "src.rpm" in rpm]
#download source and target rpms
self.obs.getBinary(target_project, target, package, target_rpm[0],
tmp_dir_old + "/old.rpm")
self.obs.getBinary(source_project, target, package, src_rpm[0],
tmp_dir_new + "/new.rpm")
# extract rpms
old_file = extract_rpm(tmp_dir_old + "/old.rpm", tmp_dir_old)
new_file = extract_rpm(tmp_dir_new + "/new.rpm", tmp_dir_new)
#rpm contains tar.bz2 and .spec file. Open and extract tar.bz2
old_tar = tarfile.open(tmp_dir_old + '/' + old_file[0])
old_tar.extractall(old_ts_dir)
new_tar = tarfile.open(tmp_dir_new + '/' + new_file[0])
new_tar.extractall(new_ts_dir)
old_ts_files = {}
for member in old_tar.members:
# rpm directrory has .spec file
if member.name.split('/')[1] == 'rpm':
continue
# "lang : path_to_ts_file" pair
old_ts_files.update({member.name.split('/')[1] : member.name })
new_ts_files = {}
for member in new_tar.members:
# rpm directrory has .spec file
if member.name.split('/')[1] == 'rpm':
continue
# "lang : path_to_ts_file" pair
new_ts_files.update({member.name.split('/')[1] : member.name })
l10n_stats = {}
for key in set(new_ts_files.keys()) & set(old_ts_files.keys()):
_old_path = tmp_dir_old + "/ts/" + old_ts_files[key]
_new_path = tmp_dir_new + "/ts/" + new_ts_files[key]
unit_diff = _make_ts_diff(_old_path, _new_path)
l10n_stats.update({ key : unit_diff })
l10n_stats.update({"removed_langs" : list(set(old_ts_files.keys()) - set(new_ts_files.keys())) })
l10n_stats.update({"added_langs" : list(set(new_ts_files.keys()) - set(old_ts_files.keys())) })
# possible removed strings
l10n_stats.update({ "removed_strings" : [] })
#check that -ts-devel package is not going out of sync
src_pkg = package.replace("-l10n", "")
#is there a package that is using -l10n pakcage already
src_pkg = [rpm for rpm in self.obs.getPackageList(target_project) if src_pkg == rpm]
if len(src_pkg) > 0:
#get -ts-devel rpm
src_ts_devel_rpm = [rpm for rpm in self.obs.getBinaryList(target_project, target, src_pkg[0]) if "-ts-devel" in rpm]
if len(src_ts_devel_rpm) > 0:
tmp_dir_ts = mkdtemp()
self.obs.getBinary(target_project, target, src_pkg[0], src_ts_devel_rpm[0], tmp_dir_ts + "/orig.rpm")
orig_ts_file = extract_rpm(tmp_dir_ts + "/orig.rpm", tmp_dir_ts, patterns="*.ts")
original_units = factory.getobject(tmp_dir_ts + "/" + orig_ts_file[0])
new_units = factory.getobject(tmp_dir_new + "/ts/" + new_ts_files['templates'])
removed_units = set(original_units.getids()) - set(new_units.getids())
l10n_stats.update({"removed_strings" : list(removed_units)})
shutil.rmtree(tmp_dir_ts)
#.........这里部分代码省略.........
示例14: ParticipantHandler
class ParticipantHandler(object):
"""Participant class as defined by the SkyNET API."""
def __init__(self):
self.oscrc = None
self.obs = None
def handle_wi_control(self, ctrl):
"""Job control thread."""
pass
def handle_lifecycle_control(self, ctrl):
"""Participant control thread."""
if ctrl.message == "start":
if ctrl.config.has_option("obs", "oscrc"):
self.oscrc = ctrl.config.get("obs", "oscrc")
def setup_obs(self, namespace):
"""Setup the Buildservice instance
Using namespace as an alias to the apiurl.
"""
self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
def check_trial(self, prj, targets, acts, exc):
exclude_repos, exclude_archs = exc
new_failures = set()
old_failures = set()
for target_prj in targets:
for target_repo in self.obs.getProjectRepositories(target_prj):
if target_repo in exclude_repos:
continue
archs = self.obs.getRepositoryArchs(target_prj, target_repo)
archs = [arch for arch in archs if arch not in exclude_archs]
print archs
# Get the repository of the build trial which builds against the
# required target repo in the target prj
#build_in_repo = self.obs.getTargetRepo(build_in_prj, target_prj,
# target_repo, archs)
# Get trial build results
trial_results = self.obs.getRepoResults(prj, target_repo)
# Get destination results
orig_results = self.obs.getRepoResults(target_prj, target_repo)
# compare them and return new failures
comparison = get_new_failures(trial_results, orig_results, archs, acts)
new_failures.update(comparison[0])
old_failures.update(comparison[1])
return new_failures - old_failures
def build_trial_results(self, wid):
"""Main function to get new failures related to a build trial."""
wid.result = False
if not wid.fields.msg:
wid.fields.msg = []
exclude_repos = wid.fields.exclude_repos or []
exclude_archs = wid.fields.exclude_archs or []
trial_project = wid.fields.build_trial.project
trial_subprjs = wid.fields.build_trial.as_dict().get('subprojects', {})
subtargets = list(itertools.chain.from_iterable(trial_subprjs.values()))
actions = [act for act in wid.fields.ev.actions if act["targetproject"] not in subtargets]
targets = [act["targetproject"] for act in actions]
messages = []
all_fails = []
fails = self.check_trial(trial_project, targets, actions, exc=(exclude_repos, exclude_archs))
if fails:
all_fails.extend(fails)
wid.fields.msg.append("During the trial build in %s, %s failed to"\
" build" %
(trial_project, " ".join(fails)))
else:
wid.fields.msg.append("Trial build of packages in %s successful" % trial_project)
for trial_sub, subtargets in trial_subprjs.items():
subactions = [act for act in wid.fields.ev.actions if act["targetproject"] in subtargets]
fails = self.check_trial(trial_sub, subtargets, subactions, exc=(exclude_repos, exclude_archs))
if fails:
all_fails.extend(fails)
wid.fields.msg.append("During the trial build in %s, %s failed to build" %
(trial_sub, " ".join(fails)))
else:
wid.fields.msg.append("Trial build of packages in %s successful" % trial_sub)
if all_fails:
wid.fields.new_failures = all_fails
else:
wid.result = True
def handle_wi(self, wid):
#.........这里部分代码省略.........
示例15: BuildService
#!/usr/bin/python
from pprint import pprint
from buildservice import BuildService
bs = BuildService(apiurl='http://api.meego.com', oscrc='/etc/boss/oscrc' )
print 'devel project of Trunk:'
pprint(bs.getProjectDevel('Trunk'))
print 'devel package of Trunk/bash:'
pprint(bs.getPackageDevel('Trunk', 'bash'))