2017-06-22 23:16:27 -05:00
|
|
|
from collections import namedtuple
|
2017-06-22 23:14:31 -05:00
|
|
|
from datetime import datetime
|
|
|
|
import dateutil.parser
|
2017-06-22 23:16:27 -05:00
|
|
|
import re
|
2017-06-14 23:50:28 -05:00
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
|
2017-06-22 23:16:27 -05:00
|
|
|
from osc.core import get_binarylist
|
2017-06-20 16:37:16 -05:00
|
|
|
from osc.core import get_dependson
|
2017-06-14 23:50:28 -05:00
|
|
|
from osc.core import http_GET
|
|
|
|
from osc.core import makeurl
|
2017-06-22 23:12:45 -05:00
|
|
|
from osc.core import owner
|
2017-06-14 23:50:57 -05:00
|
|
|
from osc.core import show_project_meta
|
2017-06-14 23:50:28 -05:00
|
|
|
from osclib.memoize import memoize
|
|
|
|
|
2017-08-02 21:04:08 -05:00
|
|
|
BINARY_REGEX = r'(?:.*::)?(?P<filename>(?P<name>.*?)-(?P<version>[^-]+)-(?P<release>[^-]+)\.(?P<arch>[^-\.]+))'
|
|
|
|
RPM_REGEX = BINARY_REGEX + '\.rpm'
|
2017-06-22 23:16:27 -05:00
|
|
|
BinaryParsed = namedtuple('BinaryParsed', ('filename', 'name', 'arch'))
|
|
|
|
|
2017-05-11 23:31:27 -05:00
|
|
|
|
|
|
|
@memoize(session=True)
|
|
|
|
def owner_fallback(apiurl, project, package):
|
2017-06-22 23:12:45 -05:00
|
|
|
root = owner(apiurl, package, project=project)
|
|
|
|
entry = root.find('owner')
|
|
|
|
if not entry or entry.get('project') == project:
|
2017-05-11 23:31:27 -05:00
|
|
|
# Fallback to global (ex Factory) maintainer.
|
2017-06-22 23:12:45 -05:00
|
|
|
root = owner(apiurl, package)
|
2017-05-11 23:31:27 -05:00
|
|
|
return root
|
|
|
|
|
2017-06-20 16:34:35 -05:00
|
|
|
@memoize(session=True)
|
|
|
|
def maintainers_get(apiurl, project, package=None):
|
|
|
|
if package is None:
|
|
|
|
meta = ET.fromstring(''.join(show_project_meta(apiurl, project)))
|
|
|
|
return [p.get('userid') for p in meta.findall('.//person') if p.get('role') == 'maintainer']
|
|
|
|
|
2017-05-11 23:31:27 -05:00
|
|
|
root = owner_fallback(apiurl, project, package)
|
|
|
|
maintainers = [p.get('name') for p in root.findall('.//person') if p.get('role') == 'maintainer']
|
|
|
|
if not maintainers:
|
|
|
|
for group in [p.get('name') for p in root.findall('.//group') if p.get('role') == 'maintainer']:
|
|
|
|
url = makeurl(apiurl, ('group', group))
|
|
|
|
root = ET.parse(http_GET(url)).getroot()
|
|
|
|
maintainers = maintainers + [p.get('userid') for p in root.findall('./person/person')]
|
|
|
|
return maintainers
|
|
|
|
|
2017-06-14 23:50:28 -05:00
|
|
|
@memoize(session=True)
|
|
|
|
def package_list(apiurl, project):
|
|
|
|
url = makeurl(apiurl, ['source', project], { 'expand': 1 })
|
|
|
|
root = ET.parse(http_GET(url)).getroot()
|
|
|
|
|
|
|
|
packages = []
|
|
|
|
for package in root.findall('entry'):
|
|
|
|
packages.append(package.get('name'))
|
|
|
|
|
|
|
|
return sorted(packages)
|
2017-06-14 23:50:57 -05:00
|
|
|
|
|
|
|
@memoize(session=True)
|
|
|
|
def target_archs(apiurl, project):
|
|
|
|
meta = show_project_meta(apiurl, project)
|
|
|
|
meta = ET.fromstring(''.join(meta))
|
|
|
|
archs = []
|
|
|
|
for arch in meta.findall('repository[@name="standard"]/arch'):
|
|
|
|
archs.append(arch.text)
|
|
|
|
return archs
|
2017-06-20 16:37:16 -05:00
|
|
|
|
|
|
|
@memoize(session=True)
|
|
|
|
def depends_on(apiurl, project, repository, packages=None, reverse=None):
|
|
|
|
dependencies = set()
|
|
|
|
for arch in target_archs(apiurl, project):
|
|
|
|
root = ET.fromstring(get_dependson(apiurl, project, repository, arch, packages, reverse))
|
|
|
|
dependencies.update(pkgdep.text for pkgdep in root.findall('.//pkgdep'))
|
|
|
|
|
|
|
|
return dependencies
|
2017-06-22 23:14:31 -05:00
|
|
|
|
|
|
|
def request_when_staged(request, project, first=False):
|
|
|
|
when = None
|
|
|
|
for history in request.statehistory:
|
|
|
|
if project in history.comment:
|
|
|
|
when = history.when
|
|
|
|
|
|
|
|
return dateutil.parser.parse(when)
|
|
|
|
|
|
|
|
def request_staged(request):
|
|
|
|
for review in request.reviews:
|
|
|
|
if (review.state == 'new' and review.by_project and
|
|
|
|
review.by_project.startswith(request.actions[0].tgt_project)):
|
|
|
|
|
|
|
|
# Allow time for things to settle.
|
|
|
|
when = request_when_staged(request, review.by_project)
|
|
|
|
if (datetime.utcnow() - when).total_seconds() > 10 * 60:
|
|
|
|
return review.by_project
|
|
|
|
|
|
|
|
return None
|
2017-06-22 23:16:27 -05:00
|
|
|
|
|
|
|
def binary_list(apiurl, project, repository, arch, package=None):
|
|
|
|
parsed = []
|
|
|
|
for binary in get_binarylist(apiurl, project, repository, arch, package):
|
2017-08-02 21:04:08 -05:00
|
|
|
result = re.match(RPM_REGEX, binary)
|
2017-06-22 23:16:27 -05:00
|
|
|
if not result:
|
|
|
|
continue
|
|
|
|
|
2017-08-02 21:04:08 -05:00
|
|
|
name = result.group('name')
|
2017-06-22 23:16:27 -05:00
|
|
|
if name.endswith('-debuginfo') or name.endswith('-debuginfo-32bit'):
|
|
|
|
continue
|
|
|
|
if name.endswith('-debugsource'):
|
|
|
|
continue
|
2017-08-02 21:04:08 -05:00
|
|
|
if result.group('arch') == 'src':
|
2017-06-22 23:16:27 -05:00
|
|
|
continue
|
|
|
|
|
2017-08-02 21:04:08 -05:00
|
|
|
parsed.append(BinaryParsed(result.group('filename'), name, result.group('arch')))
|
2017-06-22 23:16:27 -05:00
|
|
|
|
|
|
|
return parsed
|