2015-08-14 05:47:59 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (c) 2015 SUSE Linux GmbH
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import urllib2
|
|
|
|
import random
|
2015-08-21 21:10:06 +08:00
|
|
|
import re
|
2015-08-14 05:47:59 +08:00
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
|
|
|
|
import osc.conf
|
|
|
|
import osc.core
|
|
|
|
|
2015-08-17 20:28:15 +08:00
|
|
|
from osc import oscerr
|
2015-08-14 05:47:59 +08:00
|
|
|
from osclib.memoize import memoize
|
|
|
|
|
2015-08-14 06:09:08 +08:00
|
|
|
OPENSUSE = 'openSUSE:42'
|
2015-08-14 05:47:59 +08:00
|
|
|
FCC = 'openSUSE:42:Factory-Candidates-Check'
|
|
|
|
|
|
|
|
makeurl = osc.core.makeurl
|
|
|
|
http_GET = osc.core.http_GET
|
2015-08-17 20:28:15 +08:00
|
|
|
http_POST = osc.core.http_POST
|
2015-08-14 05:47:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
class FccSubmitter(object):
|
|
|
|
def __init__(self, from_prj, to_prj, submit_limit):
|
|
|
|
self.from_prj = from_prj
|
|
|
|
self.to_prj = to_prj
|
2015-08-14 13:53:11 +08:00
|
|
|
self.factory = 'openSUSE:Factory'
|
|
|
|
self.submit_limit = int(submit_limit)
|
2015-08-14 05:47:59 +08:00
|
|
|
self.apiurl = osc.conf.config['apiurl']
|
|
|
|
self.debug = osc.conf.config['debug']
|
2015-08-19 17:58:33 +08:00
|
|
|
self.sle_base_prjs = [
|
|
|
|
'SUSE:SLE-12-SP1:GA',
|
|
|
|
'SUSE:SLE-12:Update',
|
|
|
|
'SUSE:SLE-12:GA',
|
|
|
|
]
|
2015-08-18 19:18:56 +08:00
|
|
|
# the skip list against devel project
|
2015-08-18 19:19:53 +08:00
|
|
|
self.skip_devel_project_list = [
|
|
|
|
'X11:Enlightenment:Factory',
|
2015-08-21 21:10:06 +08:00
|
|
|
'devel:languages:nodejs',
|
|
|
|
'devel:languages:go',
|
2015-08-23 17:46:55 +08:00
|
|
|
'mobile:synchronization:FACTORY',
|
2015-08-21 21:10:06 +08:00
|
|
|
]
|
|
|
|
# put the except packages from skip_devel_project_list, use regex in this list
|
|
|
|
self.except_pkgs_list = [
|
|
|
|
"^golang-x-(\w+)",
|
|
|
|
"^go$",
|
|
|
|
"^nodejs$",
|
2015-08-18 19:19:53 +08:00
|
|
|
]
|
2015-08-18 21:40:43 +08:00
|
|
|
self.skip_pkgs_list = [
|
2015-08-21 21:10:06 +08:00
|
|
|
"^mozaddon-adblock_edge",
|
|
|
|
"^gnome-python-desktop",
|
|
|
|
"^compiz-manager",
|
|
|
|
"^lua$",
|
|
|
|
"^lua52$",
|
|
|
|
"^python-plaso",
|
|
|
|
"^pidgin-openfetion",
|
|
|
|
"^sobby",
|
|
|
|
"^conduit",
|
|
|
|
"^devilspie",
|
|
|
|
"^radiotray",
|
|
|
|
"^decibel-audio-player",
|
|
|
|
"^cttop",
|
|
|
|
"^kimtoy",
|
|
|
|
"^scim$",
|
|
|
|
"^scim-(\w+)",
|
2015-08-23 17:46:55 +08:00
|
|
|
"^freeradius-(\w+)",
|
|
|
|
"x-tile",
|
|
|
|
"imhangul",
|
|
|
|
"libgnomeuimm",
|
|
|
|
"guake",
|
|
|
|
"gstreamer-0_10-plugins-gl",
|
|
|
|
"python-jmespath",
|
|
|
|
"pybliographer",
|
2015-08-24 19:49:31 +08:00
|
|
|
"scpm",
|
|
|
|
"ghc-asn1-data",
|
|
|
|
"novel-pinyin",
|
|
|
|
"xplatproviders",
|
|
|
|
"libu2f-host",
|
2015-08-27 22:17:53 +08:00
|
|
|
"pycarddav",
|
|
|
|
"rubygem-json_pure-1_5",
|
|
|
|
"Crystalcursors",
|
|
|
|
"python-dfVFS",
|
|
|
|
"python-gcs-oauth2-boto-plugin",
|
|
|
|
"texinfo4",
|
|
|
|
"mozaddon-bugmenot",
|
2015-08-28 20:04:55 +08:00
|
|
|
"virt-utils",
|
|
|
|
"^kdelibs3",
|
|
|
|
"python-oslo.version",
|
2015-09-02 19:23:12 +08:00
|
|
|
"seed",
|
|
|
|
"gtk3-metatheme-sonar",
|
|
|
|
"metacity-themes",
|
|
|
|
"tuxcursors",
|
|
|
|
"yast2-fonts",
|
|
|
|
"python-ncclient",
|
|
|
|
"tweets2pdf",
|
|
|
|
"perl-Net-OpenID-Consumer",
|
2015-08-18 21:40:43 +08:00
|
|
|
]
|
2015-08-14 05:47:59 +08:00
|
|
|
|
|
|
|
def get_source_packages(self, project, expand=False):
|
|
|
|
"""Return the list of packages in a project."""
|
|
|
|
query = {'expand': 1} if expand else {}
|
|
|
|
root = ET.parse(http_GET(makeurl(self.apiurl,['source', project],
|
|
|
|
query=query))).getroot()
|
|
|
|
packages = [i.get('name') for i in root.findall('entry')]
|
|
|
|
|
|
|
|
return packages
|
|
|
|
|
|
|
|
def get_request_list(self, package):
|
|
|
|
return osc.core.get_request_list(self.apiurl, self.to_prj, package, req_state=('new', 'review'))
|
|
|
|
|
2015-08-19 17:58:33 +08:00
|
|
|
def get_link(self, project, package):
|
|
|
|
try:
|
2015-08-19 21:57:35 +08:00
|
|
|
link = http_GET(makeurl(self.apiurl,['source', project, package, '_link'])).read()
|
2015-08-19 17:58:33 +08:00
|
|
|
except (urllib2.HTTPError, urllib2.URLError):
|
|
|
|
return None
|
|
|
|
return ET.fromstring(link)
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
def get_build_succeeded_packages(self, project):
|
|
|
|
"""Get the build succeeded packages from `from_prj` project.
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = osc.core.show_prj_results_meta(self.apiurl, project)
|
|
|
|
root = ET.fromstring(''.join(f))
|
|
|
|
#print ET.dump(root)
|
|
|
|
|
|
|
|
pacs = []
|
|
|
|
for node in root.findall('result'):
|
|
|
|
if node.get('repository') == 'pure_42' and node.get('arch') == 'x86_64':
|
|
|
|
for pacnode in node.findall('status'):
|
|
|
|
if pacnode.get('code') == 'succeeded':
|
|
|
|
pacs.append(pacnode.get('package'))
|
|
|
|
else:
|
|
|
|
logging.error("Can not find pure_42/x86_64 results")
|
|
|
|
|
|
|
|
return pacs
|
|
|
|
|
2015-08-18 21:04:38 +08:00
|
|
|
def is_new_package(self, tgt_project, tgt_package):
|
|
|
|
try:
|
2015-08-18 21:08:22 +08:00
|
|
|
logging.debug("Gathering package_meta %s/%s" % (tgt_project, tgt_package))
|
2015-08-18 21:04:38 +08:00
|
|
|
osc.core.show_package_meta(self.apiurl, tgt_project, tgt_package)
|
|
|
|
except (urllib2.HTTPError, urllib2.URLError):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-08-17 20:28:15 +08:00
|
|
|
def get_devel_project(self, package):
|
|
|
|
m = osc.core.show_package_meta(self.apiurl, self.factory, package)
|
|
|
|
node = ET.fromstring(''.join(m)).find('devel')
|
|
|
|
if node is None:
|
|
|
|
return None, None
|
|
|
|
else:
|
|
|
|
return node.get('project'), node.get('package', None)
|
|
|
|
|
|
|
|
def add_review(self, requestid, by_project=None, by_package=None, msg=None):
|
|
|
|
query = {}
|
|
|
|
query['by_project'] = by_project
|
|
|
|
query['by_package'] = by_package
|
|
|
|
if not msg:
|
|
|
|
msg = "Being evaluated by {}/{}. This is submitted by a tool to Leap, please review this change and decline it if Leap do not need this!"
|
|
|
|
msg = msg.format(by_project, by_package)
|
|
|
|
|
|
|
|
if not query:
|
|
|
|
raise oscerr.WrongArgs('We need a project')
|
|
|
|
|
|
|
|
query['cmd'] = 'addreview'
|
|
|
|
url = makeurl(self.apiurl, ['request', str(requestid)], query)
|
|
|
|
http_POST(url, data=msg)
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
def create_submitrequest(self, package):
|
|
|
|
"""Create a submit request using the osc.commandline.Osc class."""
|
2015-08-14 13:53:11 +08:00
|
|
|
src_project = self.factory # submit from Factory only
|
2015-08-14 05:47:59 +08:00
|
|
|
dst_project = self.to_prj
|
2015-08-17 20:28:15 +08:00
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
msg = 'Automatic request from %s by F-C-C Submitter' % src_project
|
|
|
|
res = osc.core.create_submit_request(self.apiurl,
|
|
|
|
src_project,
|
|
|
|
package,
|
|
|
|
dst_project,
|
|
|
|
package,
|
|
|
|
message=msg)
|
|
|
|
return res
|
|
|
|
|
2015-08-14 06:09:08 +08:00
|
|
|
def check_multiple_specfiles(self, project, package):
|
|
|
|
url = makeurl(self.apiurl, ['source', project, package], { 'expand': '1' } )
|
|
|
|
root = ET.fromstring(http_GET(url).read())
|
|
|
|
files = [ entry.get('name').replace('.spec', '') for entry in root.findall('entry') if entry.get('name').endswith('.spec') ]
|
|
|
|
if len(files) == 1:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2015-08-19 17:58:33 +08:00
|
|
|
def is_sle_base_pkgs(self, package):
|
|
|
|
link = self.get_link(self.to_prj, package)
|
|
|
|
if link is None or link.get('project') not in self.sle_base_prjs:
|
|
|
|
logging.debug("%s not from SLE base"%package)
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
def crawl(self):
|
|
|
|
"""Main method"""
|
|
|
|
succeeded_packages = []
|
|
|
|
succeeded_packages = self.get_build_succeeded_packages(self.from_prj)
|
|
|
|
if not len(succeeded_packages) > 0:
|
|
|
|
logging.info('No build succeeded package in %s'%self.from_prj)
|
|
|
|
return
|
|
|
|
|
|
|
|
# randomize the list
|
|
|
|
random.shuffle(succeeded_packages)
|
|
|
|
# get souce packages from target
|
|
|
|
target_packages = self.get_source_packages(self.to_prj)
|
2015-08-14 13:53:11 +08:00
|
|
|
|
2015-08-18 19:34:29 +08:00
|
|
|
ms_packages = [] # collect multi specs packages
|
|
|
|
|
2015-08-14 13:53:11 +08:00
|
|
|
for i in range(0, min(int(self.submit_limit), len(succeeded_packages))):
|
2015-08-14 05:47:59 +08:00
|
|
|
package = succeeded_packages[i]
|
2015-08-19 17:58:33 +08:00
|
|
|
|
|
|
|
if self.is_sle_base_pkgs(package) is True:
|
|
|
|
logging.info('%s origin from SLE base, skip for now!'%package)
|
|
|
|
continue
|
|
|
|
|
2015-08-24 19:35:55 +08:00
|
|
|
# make sure it is new package
|
|
|
|
new_pkg = self.is_new_package(self.to_prj, package)
|
|
|
|
if new_pkg is not True:
|
|
|
|
logging.info('%s is not a new package, do not submit.' % package)
|
|
|
|
continue
|
|
|
|
|
2015-08-14 13:53:11 +08:00
|
|
|
multi_specs = self.check_multiple_specfiles(self.factory, package)
|
2015-08-14 06:09:08 +08:00
|
|
|
if multi_specs is True:
|
2015-08-14 13:53:11 +08:00
|
|
|
logging.info('%s in %s have multiple specs, skip for now and submit manually'%(package, 'openSUSE:Factory'))
|
2015-08-18 19:34:29 +08:00
|
|
|
ms_packages.append(package)
|
2015-08-14 06:09:08 +08:00
|
|
|
continue
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
# make sure the package non-exist in target yet ie. expand=False
|
|
|
|
if package not in target_packages:
|
|
|
|
# make sure there is no request against same package
|
|
|
|
request = self.get_request_list(package)
|
|
|
|
if request:
|
|
|
|
logging.debug("There is a request to %s / %s already, skip!"%(package, self.to_prj))
|
|
|
|
else:
|
|
|
|
logging.info("%d - Preparing submit %s to %s"%(i, package, self.to_prj))
|
2015-08-18 19:18:56 +08:00
|
|
|
# get devel project
|
|
|
|
devel_prj, devel_pkg = self.get_devel_project(package)
|
|
|
|
# check devel project does not in the skip list
|
|
|
|
if devel_prj in self.skip_devel_project_list:
|
2015-08-21 21:10:06 +08:00
|
|
|
# check the except packages list
|
2015-08-22 03:51:17 +08:00
|
|
|
match = None
|
2015-08-21 21:10:06 +08:00
|
|
|
for elem in self.except_pkgs_list:
|
|
|
|
m = re.search(elem, package)
|
|
|
|
if m is not None:
|
|
|
|
match = True
|
|
|
|
|
|
|
|
if match is not True:
|
|
|
|
logging.info('%s/%s is in the skip list, do not submit.' % (devel_prj, package))
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2015-08-18 21:36:10 +08:00
|
|
|
# check package does not in the skip list
|
2015-08-22 03:51:17 +08:00
|
|
|
match = None
|
2015-08-21 21:10:06 +08:00
|
|
|
for elem in self.skip_pkgs_list:
|
|
|
|
m = re.search(elem, package)
|
|
|
|
if m is not None:
|
|
|
|
match = True
|
|
|
|
|
|
|
|
if match is True:
|
2015-08-18 21:40:43 +08:00
|
|
|
logging.info('%s is in the skip list, do not submit.' % package)
|
2015-08-18 21:36:10 +08:00
|
|
|
continue
|
2015-08-21 21:10:06 +08:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
res = self.create_submitrequest(package)
|
2015-08-18 18:57:49 +08:00
|
|
|
if res and res is not None:
|
2015-08-14 05:47:59 +08:00
|
|
|
logging.info('Created request %s for %s' % (res, package))
|
2015-08-17 20:28:15 +08:00
|
|
|
# add review by package
|
2015-08-18 19:18:56 +08:00
|
|
|
logging.info("Adding review by %s/%s"%(devel_prj, devel_pkg))
|
2015-08-17 20:28:15 +08:00
|
|
|
self.add_review(res, devel_prj, devel_pkg)
|
2015-08-14 05:47:59 +08:00
|
|
|
else:
|
|
|
|
logging.error('Error occurred when creating submit request')
|
|
|
|
else:
|
|
|
|
logging.debug('%s is exist in %s, skip!'%(package, self.to_prj))
|
|
|
|
|
2015-08-18 19:34:29 +08:00
|
|
|
# dump multi specs packages
|
|
|
|
print("Multi-specs packages:")
|
|
|
|
if ms_packages:
|
|
|
|
for pkg in ms_packages:
|
|
|
|
print pkg
|
|
|
|
else:
|
|
|
|
print 'None'
|
|
|
|
|
2015-08-14 05:47:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main(args):
|
|
|
|
# Configure OSC
|
|
|
|
osc.conf.get_config(override_apiurl=args.apiurl)
|
|
|
|
osc.conf.config['debug'] = args.debug
|
|
|
|
|
|
|
|
uc = FccSubmitter(args.from_prj, args.to_prj, args.submit_limit)
|
|
|
|
uc.crawl()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
description = 'Create SR from openSUSE:42:Factory-Candidates-Check to the '\
|
|
|
|
'new openSUSE:42 project for every new build succeded package.'
|
|
|
|
parser = argparse.ArgumentParser(description=description)
|
|
|
|
parser.add_argument('-A', '--apiurl', metavar='URL', help='API URL')
|
|
|
|
parser.add_argument('-d', '--debug', action='store_true',
|
|
|
|
help='print info useful for debuging')
|
|
|
|
parser.add_argument('-f', '--from', dest='from_prj', metavar='PROJECT',
|
|
|
|
help='project where to check (default: %s)' % FCC,
|
|
|
|
default=FCC)
|
|
|
|
parser.add_argument('-t', '--to', dest='to_prj', metavar='PROJECT',
|
|
|
|
help='project where to submit the packages (default: %s)' % OPENSUSE,
|
|
|
|
default=OPENSUSE)
|
2015-08-14 13:53:11 +08:00
|
|
|
parser.add_argument('-l', '--limit', dest='submit_limit', metavar='NUMBERS', help='limit numbers packages to submit (default: 100)', default=100)
|
2015-08-14 05:47:59 +08:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Set logging configuration
|
|
|
|
logging.basicConfig(level=logging.DEBUG if args.debug
|
|
|
|
else logging.INFO)
|
|
|
|
|
|
|
|
sys.exit(main(args))
|