2014-07-15 17:08:48 +02:00
|
|
|
import re
|
2015-02-26 14:48:40 +01:00
|
|
|
import urllib2
|
2015-02-19 10:57:55 +01:00
|
|
|
import warnings
|
2014-07-15 17:08:48 +02:00
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
|
2014-02-28 11:45:06 +01:00
|
|
|
from osc.core import change_request_state
|
2015-01-16 15:37:07 +00:00
|
|
|
from osc.core import http_GET, http_PUT, http_DELETE
|
2014-07-15 10:43:11 +02:00
|
|
|
from datetime import date
|
2014-05-20 12:26:29 +02:00
|
|
|
from osclib.comments import CommentAPI
|
2014-02-28 11:45:06 +01:00
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-03-06 18:22:19 +01:00
|
|
|
class AcceptCommand(object):
|
2014-02-19 11:48:16 +01:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
2014-05-20 12:26:29 +02:00
|
|
|
self.comment = CommentAPI(self.api.apiurl)
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-06-01 19:51:18 +02:00
|
|
|
def find_new_requests(self, project):
|
|
|
|
query = "match=state/@name='new'+and+(action/target/@project='{}'+and+action/@type='submit')".format(project)
|
|
|
|
url = self.api.makeurl(['search', 'request'], query)
|
|
|
|
|
|
|
|
f = http_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
2014-07-15 17:08:48 +02:00
|
|
|
|
2014-08-15 15:38:27 +02:00
|
|
|
rqs = []
|
2014-06-01 19:51:18 +02:00
|
|
|
for rq in root.findall('request'):
|
2014-08-15 15:38:27 +02:00
|
|
|
pkgs = []
|
|
|
|
actions = rq.findall('action')
|
|
|
|
for action in actions:
|
|
|
|
targets = action.findall('target')
|
|
|
|
for t in targets:
|
|
|
|
pkgs.append(str(t.get('package')))
|
|
|
|
|
2014-09-01 09:43:44 +02:00
|
|
|
rqs.append({'id': int(rq.get('id')), 'packages': pkgs})
|
2014-08-15 15:38:27 +02:00
|
|
|
return rqs
|
2014-07-15 17:08:48 +02:00
|
|
|
|
2014-03-05 15:49:48 +01:00
|
|
|
def perform(self, project):
|
2015-02-26 14:48:40 +01:00
|
|
|
"""Accept the staging project for review and submit to Factory /
|
2014-09-29 11:14:40 +02:00
|
|
|
openSUSE 13.2 ...
|
|
|
|
|
2014-02-26 14:51:01 +01:00
|
|
|
Then disable the build to disabled
|
|
|
|
:param project: staging project we are working with
|
2014-09-29 11:14:40 +02:00
|
|
|
|
2014-02-26 14:51:01 +01:00
|
|
|
"""
|
2014-07-15 10:43:11 +02:00
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
status = self.api.check_project_status(project)
|
|
|
|
|
|
|
|
if not status:
|
2014-09-01 09:43:44 +02:00
|
|
|
print('The project "{}" is not yet acceptable.'.format(project))
|
2014-07-15 10:43:11 +02:00
|
|
|
return False
|
2014-02-19 11:48:16 +01:00
|
|
|
|
|
|
|
meta = self.api.get_prj_pseudometa(project)
|
|
|
|
requests = []
|
2014-06-16 17:15:24 +02:00
|
|
|
packages = []
|
2014-02-19 11:48:16 +01:00
|
|
|
for req in meta['requests']:
|
|
|
|
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept')
|
2014-06-16 17:15:24 +02:00
|
|
|
requests.append(req['id'])
|
|
|
|
packages.append(req['package'])
|
2014-09-01 09:43:44 +02:00
|
|
|
msg = 'Accepting staging review for {}'.format(req['package'])
|
2014-05-20 12:26:29 +02:00
|
|
|
print(msg)
|
|
|
|
|
2015-02-26 14:48:40 +01:00
|
|
|
oldspecs = self.api.get_filelist_for_package(pkgname=req['package'],
|
|
|
|
project=self.api.project,
|
|
|
|
extension='spec')
|
|
|
|
change_request_state(self.api.apiurl,
|
|
|
|
str(req['id']),
|
|
|
|
'accepted',
|
|
|
|
message='Accept to %s' % self.api.project)
|
2015-02-19 10:57:55 +01:00
|
|
|
self.create_new_links(self.api.project, req['package'], oldspecs)
|
2014-02-19 11:48:16 +01:00
|
|
|
|
2014-09-29 11:14:40 +02:00
|
|
|
# A single comment should be enough to notify everybody, since
|
|
|
|
# they are already mentioned in the comments created by
|
|
|
|
# select/unselect
|
2014-06-16 17:15:24 +02:00
|
|
|
pkg_list = ", ".join(packages)
|
2015-02-26 14:48:40 +01:00
|
|
|
cmmt = 'Project "{}" accepted.' \
|
|
|
|
' The following packages have been submitted to {}: {}.'.format(project,
|
|
|
|
self.api.project,
|
|
|
|
pkg_list)
|
2014-06-16 17:15:24 +02:00
|
|
|
self.comment.add_comment(project_name=project, comment=cmmt)
|
|
|
|
|
2014-05-20 12:26:29 +02:00
|
|
|
# XXX CAUTION - AFAIK the 'accept' command is expected to clean the messages here.
|
|
|
|
self.comment.delete_from(project_name=project)
|
|
|
|
|
2014-02-19 11:48:16 +01:00
|
|
|
self.api.build_switch_prj(project, 'disable')
|
2015-01-19 21:41:02 +01:00
|
|
|
if self.api.item_exists(project + ':DVD'):
|
2014-09-01 09:43:44 +02:00
|
|
|
self.api.build_switch_prj(project + ':DVD', 'disable')
|
2014-05-27 18:32:51 +02:00
|
|
|
|
2014-06-01 19:51:18 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def accept_other_new(self):
|
2014-07-15 10:43:11 +02:00
|
|
|
changed = False
|
2015-02-19 10:57:55 +01:00
|
|
|
rqlist = self.find_new_requests(self.api.project)
|
|
|
|
if self.api.cnonfree:
|
|
|
|
rqlist += self.find_new_requests(self.api.cnonfree)
|
|
|
|
|
2014-12-19 10:41:20 +01:00
|
|
|
for req in rqlist:
|
2015-02-19 10:57:55 +01:00
|
|
|
oldspecs = self.api.get_filelist_for_package(pkgname=req['packages'][0], project=self.api.project, extension='spec')
|
2014-09-01 09:43:44 +02:00
|
|
|
print 'Accepting request %d: %s' % (req['id'], ','.join(req['packages']))
|
2015-02-19 10:57:55 +01:00
|
|
|
change_request_state(self.api.apiurl, str(req['id']), 'accepted', message='Accept to %s' % self.api.project)
|
2015-01-16 15:37:07 +00:00
|
|
|
# Check if all .spec files of the package we just accepted has a package container to build
|
2015-02-19 10:57:55 +01:00
|
|
|
self.create_new_links(self.api.project, req['packages'][0], oldspecs)
|
2014-07-15 10:43:11 +02:00
|
|
|
changed = True
|
2014-06-01 19:51:18 +02:00
|
|
|
|
2014-07-15 10:43:11 +02:00
|
|
|
return changed
|
|
|
|
|
2015-01-16 15:37:07 +00:00
|
|
|
def create_new_links(self, project, pkgname, oldspeclist):
|
|
|
|
filelist = self.api.get_filelist_for_package(pkgname=pkgname, project=project, extension='spec')
|
|
|
|
removedspecs = set(oldspeclist) - set(filelist)
|
|
|
|
for spec in removedspecs:
|
|
|
|
# Deleting all the packages that no longer have a .spec file
|
|
|
|
url = self.api.makeurl(['source', project, spec[:-5]])
|
|
|
|
print "Deleting package %s from project %s" % (spec[:-5], project)
|
|
|
|
try:
|
|
|
|
http_DELETE(url)
|
|
|
|
except urllib2.HTTPError, err:
|
|
|
|
if err.code == 404:
|
|
|
|
# the package link was not yet created, which was likely a mistake from earlier
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# If the package was there bug could not be delete, raise the error
|
|
|
|
raise
|
|
|
|
if len(filelist) > 1:
|
|
|
|
# There is more than one .spec file in the package; link package containers as needed
|
|
|
|
origmeta = self.api.load_file_content(project, pkgname, '_meta')
|
|
|
|
for specfile in filelist:
|
2015-02-26 14:48:40 +01:00
|
|
|
package = specfile[:-5] # stripping .spec off the filename gives the packagename
|
2015-01-16 15:37:07 +00:00
|
|
|
if package == pkgname:
|
|
|
|
# This is the original package and does not need to be linked to itself
|
|
|
|
continue
|
|
|
|
# Check if the target package already exists, if it does not, we get a HTTP error 404 to catch
|
|
|
|
if not self.api.item_exists(project, package):
|
|
|
|
print "Creating new package %s linked to %s" % (package, pkgname)
|
|
|
|
# new package does not exist. Let's link it with new metadata
|
2015-02-26 14:48:40 +01:00
|
|
|
newmeta = re.sub(r'(<package.*name=.){}'.format(pkgname),
|
|
|
|
r'\1{}'.format(package),
|
|
|
|
origmeta)
|
|
|
|
newmeta = re.sub(r'<devel.*>\$',
|
|
|
|
r'<devel package=\'{}\'/>'.format(pkgname),
|
|
|
|
newmeta)
|
|
|
|
newmeta = re.sub(r'<bcntsynctag>.*</bcntsynctag>',
|
|
|
|
r'',
|
|
|
|
newmeta)
|
|
|
|
newmeta = re.sub(r'</package>',
|
|
|
|
r'<bcntsynctag>{}</bcntsynctag></package>'.format(pkgname),
|
|
|
|
newmeta)
|
2015-01-16 15:37:07 +00:00
|
|
|
self.api.save_file_content(project, package, '_meta', newmeta)
|
|
|
|
link = "<link package=\"{}\" cicount=\"copy\" />".format(pkgname)
|
|
|
|
self.api.save_file_content(project, package, '_link', link)
|
|
|
|
return True
|
|
|
|
|
2014-07-15 10:43:11 +02:00
|
|
|
def update_factory_version(self):
|
2015-02-19 10:57:55 +01:00
|
|
|
"""Update project (Factory, 13.2, ...) version if is necessary."""
|
|
|
|
|
|
|
|
# XXX TODO - This method have `factory` in the name. Can be
|
|
|
|
# missleading.
|
|
|
|
|
|
|
|
# If thereis not product defined for this project, show the
|
|
|
|
# warning and return.
|
|
|
|
if not self.api.cproduct:
|
|
|
|
warnings.warn('There is not product defined in the configuration file.')
|
|
|
|
return
|
|
|
|
|
|
|
|
project = self.api.project
|
|
|
|
url = self.api.makeurl(['source', project, '_product', self.api.cproduct])
|
2014-07-15 10:43:11 +02:00
|
|
|
|
2014-07-15 17:08:48 +02:00
|
|
|
product = http_GET(url).read()
|
|
|
|
curr_version = date.today().strftime('%Y%m%d')
|
|
|
|
new_product = re.sub(r'<version>\d{8}</version>', '<version>%s</version>' % curr_version, product)
|
|
|
|
|
|
|
|
if product != new_product:
|
2014-09-01 09:43:44 +02:00
|
|
|
http_PUT(url + '?comment=Update+version', data=new_product)
|
2015-02-02 15:02:57 +01:00
|
|
|
|
2015-05-03 16:21:10 +02:00
|
|
|
service = {'cmd': 'runservice'}
|
|
|
|
|
|
|
|
ports_prjs = ['PowerPC', 'ARM' ]
|
|
|
|
|
|
|
|
for ports in ports_prjs:
|
|
|
|
project = project + ':' + ports
|
|
|
|
if self.api.item_exists(project):
|
|
|
|
baseurl = ['source', project, '_product']
|
|
|
|
url = self.api.makeurl(baseurl, query=service)
|
|
|
|
self.api.retried_POST(url)
|
|
|
|
|
2015-02-02 15:02:57 +01:00
|
|
|
def sync_buildfailures(self):
|
2015-02-19 10:57:55 +01:00
|
|
|
"""
|
|
|
|
Trigger rebuild of packages that failed build in either
|
|
|
|
openSUSE:Factory or openSUSE:Factory:Rebuild, but not the
|
|
|
|
other Helps over the fact that openSUSE:Factory uses
|
|
|
|
rebuild=local, thus sometimes 'hiding' build failures.
|
|
|
|
"""
|
2015-02-02 15:02:57 +01:00
|
|
|
|
2015-02-19 10:57:55 +01:00
|
|
|
for arch in ["x86_64", "i586"]:
|
|
|
|
fact_result = self.api.get_prj_results(self.api.project, arch)
|
2015-02-02 15:02:57 +01:00
|
|
|
fact_result = self.api.check_pkgs(fact_result)
|
2015-02-19 10:57:55 +01:00
|
|
|
rebuild_result = self.api.get_prj_results(self.api.crebuild, arch)
|
2015-02-02 15:02:57 +01:00
|
|
|
rebuild_result = self.api.check_pkgs(rebuild_result)
|
|
|
|
result = set(rebuild_result) ^ set(fact_result)
|
|
|
|
|
|
|
|
print sorted(result)
|
|
|
|
|
|
|
|
for package in result:
|
2015-02-19 10:57:55 +01:00
|
|
|
self.api.rebuild_pkg(package, self.api.project, arch, None)
|
|
|
|
self.api.rebuild_pkg(package, self.api.crebuild, arch, None)
|