2015-02-19 10:57:55 +01:00
|
|
|
# Copyright (C) 2015 SUSE Linux GmbH
|
2015-02-17 17:50:20 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
from ConfigParser import ConfigParser
|
2017-04-28 22:12:32 -05:00
|
|
|
import io
|
2015-02-17 17:50:20 +01:00
|
|
|
import os
|
|
|
|
import operator
|
|
|
|
import re
|
|
|
|
|
|
|
|
from osc import conf
|
|
|
|
|
|
|
|
|
2015-02-19 10:57:55 +01:00
|
|
|
# Sane defatuls for openSUSE and SUSE. The string interpolation rule
|
|
|
|
# is as this:
|
|
|
|
#
|
|
|
|
# * %(project)s to replace the name of the project.
|
|
|
|
# * %(project.lower)s to replace the lower case version of the name of
|
|
|
|
# the project.
|
|
|
|
|
2015-02-17 17:50:20 +01:00
|
|
|
DEFAULT = {
|
2016-12-06 12:54:36 +01:00
|
|
|
r'openSUSE:(?P<project>Factory)': {
|
2015-02-17 17:50:20 +01:00
|
|
|
'staging': 'openSUSE:%(project)s:Staging',
|
2016-05-02 10:50:02 +02:00
|
|
|
'staging-group': 'factory-staging',
|
2017-09-15 09:55:23 +02:00
|
|
|
'staging-archs': 'i586 x86_64',
|
|
|
|
'staging-dvd-archs': 'x86_64',
|
2016-06-02 14:55:02 +02:00
|
|
|
'nocleanup-packages': 'Test-DVD-x86_64 Test-DVD-ppc64le bootstrap-copy',
|
2015-02-19 10:57:55 +01:00
|
|
|
'rings': 'openSUSE:%(project)s:Rings',
|
2016-12-06 12:54:36 +01:00
|
|
|
'nonfree': 'openSUSE:%(project)s:NonFree',
|
|
|
|
'rebuild': 'openSUSE:%(project)s:Rebuild',
|
|
|
|
'product': 'openSUSE.product',
|
|
|
|
'openqa': 'https://openqa.opensuse.org',
|
|
|
|
'lock': 'openSUSE:%(project)s:Staging',
|
|
|
|
'lock-ns': 'openSUSE',
|
2017-09-26 18:53:05 +08:00
|
|
|
'delreq-review': 'factory-maintainers',
|
|
|
|
'main-repo': 'standard',
|
2017-10-11 22:19:24 -05:00
|
|
|
# check_source.py
|
|
|
|
'devel-project-enforce': 'True',
|
|
|
|
'review-team': 'opensuse-review-team',
|
|
|
|
'repo-checker': 'repo-checker',
|
2016-12-06 12:54:36 +01:00
|
|
|
},
|
|
|
|
r'openSUSE:(?P<project>Leap:[\d.]+)': {
|
|
|
|
'staging': 'openSUSE:%(project)s:Staging',
|
|
|
|
'staging-group': 'factory-staging',
|
|
|
|
'staging-archs': 'i586 x86_64',
|
|
|
|
'staging-dvd-archs': 'x86_64',
|
|
|
|
'nocleanup-packages': 'Test-DVD-x86_64 bootstrap-copy',
|
|
|
|
'rings': 'openSUSE:%(project)s:Rings',
|
2015-02-19 10:57:55 +01:00
|
|
|
'nonfree': 'openSUSE:%(project)s:NonFree',
|
|
|
|
'rebuild': 'openSUSE:%(project)s:Rebuild',
|
|
|
|
'product': 'openSUSE.product',
|
|
|
|
'openqa': 'https://openqa.opensuse.org',
|
2015-02-17 17:50:20 +01:00
|
|
|
'lock': 'openSUSE:%(project)s:Staging',
|
2015-02-19 10:57:55 +01:00
|
|
|
'lock-ns': 'openSUSE',
|
2017-10-02 20:14:31 +08:00
|
|
|
'delreq-review': None,
|
2017-10-02 20:49:41 +08:00
|
|
|
'main-repo': 'standard',
|
2017-10-11 22:19:24 -05:00
|
|
|
# check_source.py
|
|
|
|
# review-team optionally added by leaper.py.
|
|
|
|
'repo-checker': 'repo-checker',
|
2017-12-21 00:32:20 -06:00
|
|
|
'pkglistgen-archs': 'x86_64',
|
|
|
|
'pkglistgen-archs-ports': 'aarch64',
|
|
|
|
'pkglistgen-locals-from': 'openSUSE-product',
|
|
|
|
'pkglistgen-include-suggested': '1',
|
|
|
|
'pkglistgen-delete-kiwis': 'openSUSE-ftp-ftp-x86_64.kiwi openSUSE-cd-mini-x86_64.kiwi',
|
2015-02-17 17:50:20 +01:00
|
|
|
},
|
2017-08-05 15:04:37 +02:00
|
|
|
r'SUSE:(?P<project>SLE-15.*$)': {
|
|
|
|
'staging': 'SUSE:%(project)s:Staging',
|
|
|
|
'staging-group': 'sle-staging-managers', # '%(project.lower)s-staging',
|
|
|
|
'staging-archs': 'i586 x86_64',
|
2017-08-24 21:45:11 -05:00
|
|
|
'staging-dvd-archs': '',
|
2017-08-05 15:04:37 +02:00
|
|
|
'rings': 'SUSE:%(project)s:Rings',
|
|
|
|
'nonfree': None,
|
|
|
|
'rebuild': None,
|
|
|
|
'product': None,
|
|
|
|
'openqa': None,
|
|
|
|
'lock': 'SUSE:%(project)s:Staging',
|
|
|
|
'lock-ns': 'SUSE',
|
2017-10-02 20:14:31 +08:00
|
|
|
'delreq-review': None,
|
2017-10-02 20:49:41 +08:00
|
|
|
'main-repo': 'standard',
|
2017-10-11 22:19:24 -05:00
|
|
|
# check_source.py
|
|
|
|
'repo-checker': 'repo-checker',
|
2017-08-05 15:04:37 +02:00
|
|
|
},
|
2015-03-24 14:46:36 +01:00
|
|
|
r'SUSE:(?P<project>.*$)': {
|
2015-02-19 10:57:55 +01:00
|
|
|
'staging': 'SUSE:%(project)s:Staging',
|
2015-03-24 14:46:36 +01:00
|
|
|
'staging-group': 'sle-staging-managers', # '%(project.lower)s-staging',
|
2015-07-19 17:50:46 +02:00
|
|
|
'staging-archs': 'i586 x86_64',
|
2017-08-24 21:45:11 -05:00
|
|
|
'staging-dvd-archs': '',
|
2016-06-02 14:55:02 +02:00
|
|
|
'nocleanup-packages': 'Test-DVD-x86_64 sles-release',
|
2015-02-19 10:57:55 +01:00
|
|
|
'rings': None,
|
|
|
|
'nonfree': None,
|
|
|
|
'rebuild': None,
|
|
|
|
'product': None,
|
|
|
|
'openqa': None,
|
2016-02-01 16:35:59 +01:00
|
|
|
'lock': 'SUSE:%(project)s:Staging',
|
|
|
|
'lock-ns': 'SUSE',
|
2017-05-03 19:12:09 -05:00
|
|
|
'remote-config': False,
|
2017-10-02 20:14:31 +08:00
|
|
|
'delreq-review': None,
|
2017-10-02 20:49:41 +08:00
|
|
|
'main-repo': 'standard',
|
2015-02-26 15:19:29 +01:00
|
|
|
},
|
2015-02-17 17:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# You can overwrite the DEFAULT in the configuration file (~/.oscrc).
|
|
|
|
# For example, to change the Factory layout you need to add a new
|
|
|
|
# section like this:
|
|
|
|
#
|
|
|
|
# [openSUSE:Factory]
|
|
|
|
#
|
|
|
|
# staging = openSUSE:Factory:Staging
|
2015-02-19 10:57:55 +01:00
|
|
|
# rings = openSUSE:Factory:Rings
|
2015-02-17 17:50:20 +01:00
|
|
|
# lock = openSUSE:Factory:Staging
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
class Config(object):
|
|
|
|
"""Helper class to configuration file."""
|
|
|
|
|
|
|
|
def __init__(self, project):
|
|
|
|
self.project = project
|
|
|
|
|
2017-10-23 23:02:21 -05:00
|
|
|
conf_file = conf.config.get('conffile', os.environ.get('OSC_CONFIG', '~/.oscrc'))
|
2015-02-17 17:50:20 +01:00
|
|
|
self.conf_file = os.path.expanduser(conf_file)
|
2017-04-28 22:12:32 -05:00
|
|
|
self.remote_values = None
|
2015-02-17 17:50:20 +01:00
|
|
|
|
|
|
|
# Populate the configuration dictionary
|
|
|
|
self.populate_conf()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def conf(self):
|
|
|
|
return conf
|
|
|
|
|
|
|
|
def populate_conf(self):
|
|
|
|
"""Add sane default into the configuration."""
|
|
|
|
defaults = {}
|
|
|
|
for prj_pattern in DEFAULT:
|
|
|
|
match = re.match(prj_pattern, self.project)
|
|
|
|
if match:
|
|
|
|
project = match.group('project')
|
2015-02-19 10:57:55 +01:00
|
|
|
for k, v in DEFAULT[prj_pattern].items():
|
|
|
|
if isinstance(v, basestring) and '%(project)s' in v:
|
|
|
|
defaults[k] = v % {'project': project}
|
|
|
|
elif isinstance(v, basestring) and '%(project.lower)s' in v:
|
|
|
|
defaults[k] = v % {'project.lower': project.lower()}
|
|
|
|
else:
|
|
|
|
defaults[k] = v
|
2015-02-17 17:50:20 +01:00
|
|
|
break
|
|
|
|
|
2017-04-28 22:12:32 -05:00
|
|
|
if self.remote_values:
|
|
|
|
defaults.update(self.remote_values)
|
|
|
|
|
2015-02-17 17:50:20 +01:00
|
|
|
# Update the configuration, only when it is necessary
|
|
|
|
conf.config[self.project] = self.read_section(self.project, defaults)
|
|
|
|
|
|
|
|
# Take the common parameters and check that are there
|
|
|
|
params = [set(d) for d in DEFAULT.values()]
|
|
|
|
params = reduce(operator.__and__, params)
|
|
|
|
if not all(p in conf.config[self.project] for p in params):
|
2016-05-02 10:50:02 +02:00
|
|
|
msg = 'Please, add [%s] section in %s, see %s for details' % (self.project, self.conf_file, __file__)
|
2015-02-17 17:50:20 +01:00
|
|
|
raise Exception(msg)
|
|
|
|
|
|
|
|
def read_section(self, section, defaults):
|
|
|
|
"""OSC parser is a bit buggy. Re-read the configuration file to find
|
|
|
|
extra sections.
|
|
|
|
|
|
|
|
"""
|
|
|
|
cp = ConfigParser(defaults=defaults)
|
|
|
|
cp.read(self.conf_file)
|
|
|
|
if cp.has_section(section):
|
|
|
|
return dict(cp.items(section))
|
|
|
|
else:
|
|
|
|
return defaults
|
2017-04-28 22:12:32 -05:00
|
|
|
|
|
|
|
def apply_remote(self, api):
|
|
|
|
"""Fetch remote config and re-process (defaults, remote, .oscrc)."""
|
2017-05-03 19:12:09 -05:00
|
|
|
if not conf.config[self.project].get('remote-config', True):
|
|
|
|
return
|
|
|
|
|
2017-07-27 23:30:53 -05:00
|
|
|
config = api.dashboard_content_load('config')
|
2017-04-28 22:12:32 -05:00
|
|
|
if config:
|
|
|
|
cp = ConfigParser()
|
|
|
|
config = '[remote]\n' + config
|
|
|
|
cp.readfp(io.BytesIO(config))
|
|
|
|
self.remote_values = dict(cp.items('remote'))
|
|
|
|
self.populate_conf()
|
2017-05-01 22:12:56 -05:00
|
|
|
elif config is None:
|
2017-04-28 22:12:32 -05:00
|
|
|
# Write empty config to allow for caching.
|
2017-07-27 23:30:53 -05:00
|
|
|
api.dashboard_content_save('config', '')
|