extract read_config_files util for config parsing
This commit is contained in:
parent
d5f67d648a
commit
4c1928f377
18 changed files with 300 additions and 251 deletions
|
|
@ -49,8 +49,7 @@ class RunRootTask(koji.tasks.BaseTaskHandler):
|
|||
return res
|
||||
|
||||
def _read_config(self):
|
||||
cp = six.moves.configparser.SafeConfigParser()
|
||||
cp.read(CONFIG_FILE)
|
||||
cp = koji.read_config_files(CONFIG_FILE)
|
||||
self.config = {
|
||||
'default_mounts': [],
|
||||
'safe_roots': [],
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import fnmatch
|
|||
import os
|
||||
import sys
|
||||
import tarfile
|
||||
import six.moves.configparser
|
||||
|
||||
import koji
|
||||
import koji.tasks as tasks
|
||||
|
|
@ -28,8 +27,7 @@ def omit_paths3(tarinfo):
|
|||
|
||||
def read_config():
|
||||
global config
|
||||
cp = six.moves.configparser.SafeConfigParser()
|
||||
cp.read(CONFIG_FILE)
|
||||
cp = koji.read_config_files(CONFIG_FILE)
|
||||
config = {
|
||||
'path_filters': [],
|
||||
'volume': None,
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ def send_queued_msgs(cbtype, *args, **kws):
|
|||
log = logging.getLogger('koji.plugin.protonmsg')
|
||||
global CONFIG
|
||||
if not CONFIG:
|
||||
CONFIG = koji.read_config_files(CONFIG_FILE)
|
||||
CONFIG = koji.read_config_files(CONFIG_FILE, strict=True)
|
||||
urls = CONFIG.get('broker', 'urls').split()
|
||||
test_mode = False
|
||||
if CONFIG.has_option('broker', 'test_mode'):
|
||||
|
|
|
|||
|
|
@ -11,16 +11,15 @@ from koji.context import context
|
|||
from koji.plugin import callback
|
||||
from koji.util import joinpath
|
||||
from koji.util import rmtree
|
||||
import six.moves.configparser
|
||||
import fnmatch
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
CONFIG_FILE = '/etc/koji-hub/plugins/rpm2maven.conf'
|
||||
|
||||
config = None
|
||||
|
||||
|
||||
@callback('postImport')
|
||||
def maven_import(cbtype, *args, **kws):
|
||||
global config
|
||||
|
|
@ -33,8 +32,7 @@ def maven_import(cbtype, *args, **kws):
|
|||
filepath = kws['filepath']
|
||||
|
||||
if not config:
|
||||
config = six.moves.configparser.SafeConfigParser()
|
||||
config.read(CONFIG_FILE)
|
||||
config = koji.read_config_files(CONFIG_FILE, strict=True)
|
||||
name_patterns = config.get('patterns', 'rpm_names').split()
|
||||
for pattern in name_patterns:
|
||||
if fnmatch.fnmatch(rpminfo['name'], pattern):
|
||||
|
|
@ -53,6 +51,7 @@ def maven_import(cbtype, *args, **kws):
|
|||
if os.path.exists(tmpdir):
|
||||
rmtree(tmpdir)
|
||||
|
||||
|
||||
def expand_rpm(filepath, tmpdir):
|
||||
devnull = open('/dev/null', 'r+')
|
||||
rpm2cpio = subprocess.Popen(['/usr/bin/rpm2cpio', filepath],
|
||||
|
|
@ -70,6 +69,7 @@ def expand_rpm(filepath, tmpdir):
|
|||
(filepath, rpm2cpio.wait(), cpio.wait()))
|
||||
devnull.close()
|
||||
|
||||
|
||||
def scan_and_import(buildinfo, rpminfo, tmpdir):
|
||||
global config
|
||||
path_patterns = config.get('patterns', 'artifact_paths').split()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
import sys
|
||||
import six.moves.configparser
|
||||
import koji
|
||||
from koji.context import context
|
||||
from koji.plugin import export
|
||||
|
|
@ -29,8 +28,7 @@ def saveFailedTree(buildrootID, full=False, **opts):
|
|||
|
||||
# read configuration only once
|
||||
if config is None:
|
||||
config = six.moves.configparser.SafeConfigParser()
|
||||
config.read(CONFIG_FILE)
|
||||
config = koji.read_config_files(CONFIG_FILE, strict=True)
|
||||
allowed_methods = config.get('permissions', 'allowed_methods').split()
|
||||
if len(allowed_methods) == 1 and allowed_methods[0] == '*':
|
||||
allowed_methods = '*'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue