Support for koji profiles.
This patch is dmach's patch [1] refactored according to mikem's comments [2]. [1] https://lists.fedoraproject.org/pipermail/buildsys/2015-August/004857.html [2] https://lists.fedoraproject.org/pipermail/buildsys/2015-October/004900.html Signed-off-by: Tomas Mlcoch <tmlcoch@redhat.com>
This commit is contained in:
parent
d20e62b76e
commit
86876a1bc9
2 changed files with 120 additions and 0 deletions
74
docs/profiles.rst
Normal file
74
docs/profiles.rst
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
=============
|
||||
Koji Profiles
|
||||
=============
|
||||
This document describes how to work with koji profiles.
|
||||
|
||||
|
||||
Command Line Interface
|
||||
======================
|
||||
Koji client allows connecting to multiple koji instances from CLI
|
||||
by using profiles. The default profile is given by executable file name,
|
||||
which is 'koji'.
|
||||
|
||||
To change koji profile, you can:
|
||||
|
||||
* run koji with --profile=$profile_name argument
|
||||
* change executable file name by symlinking $profile_name -> koji
|
||||
|
||||
|
||||
Configuration Files
|
||||
===================
|
||||
Configuration files are located in following locations:
|
||||
|
||||
* /etc/koji.conf
|
||||
* /etc/koji.conf.d/\*.conf
|
||||
* ~/.koji/config.d/\*.conf
|
||||
* user-specified config
|
||||
|
||||
Koji reads them, looking for [$profile_name] sections.
|
||||
|
||||
|
||||
Using Koji Profiles in Python
|
||||
=============================
|
||||
Instead of using koji module directly,
|
||||
get profile specific module by calling::
|
||||
|
||||
>>> mod = koji.get_profile_module($profile_name)
|
||||
|
||||
This module is clone of koji module with additional
|
||||
profile specific tweaks.
|
||||
|
||||
Profile configuration is available via::
|
||||
|
||||
>>> mod.config
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
Print configuration::
|
||||
|
||||
import koji
|
||||
|
||||
fedora_koji = koji.get_profile_module("koji")
|
||||
ppc_koji = koji.get_profile_module("ppc-koji")
|
||||
|
||||
for i in (fedora_koji, ppc_koji):
|
||||
print "PROFILE: %s" % i.config.profile
|
||||
for key, value in sorted(i.config.__dict__.items()):
|
||||
print " %s = %s" % (key, value)
|
||||
print
|
||||
|
||||
|
||||
Use ClientSession::
|
||||
|
||||
import koji
|
||||
|
||||
koji_module = koji.get_profile_module("koji")
|
||||
client = koji_module.ClientSession(koji_module.config.server)
|
||||
print client.listTags()
|
||||
|
||||
|
||||
TODO
|
||||
====
|
||||
* consider using pyxdg for user config locations
|
||||
|
|
@ -34,6 +34,7 @@ import errno
|
|||
import exceptions
|
||||
from fnmatch import fnmatch
|
||||
import httplib
|
||||
import imp
|
||||
import logging
|
||||
import logging.handlers
|
||||
from koji.util import md5_constructor
|
||||
|
|
@ -63,6 +64,8 @@ import xml.sax.handler
|
|||
from xmlrpclib import loads, dumps, Fault
|
||||
import zipfile
|
||||
|
||||
PROFILE_MODULES = {} # {module_name: module_instance}
|
||||
|
||||
def _(args):
|
||||
"""Stub function for translation"""
|
||||
return args # pragma: no cover
|
||||
|
|
@ -1551,6 +1554,49 @@ def read_config(profile_name, user_config=None):
|
|||
return result
|
||||
|
||||
|
||||
def get_profile_module(profile_name, config=None):
|
||||
"""
|
||||
Create module for a koji instance.
|
||||
Override profile specific module attributes:
|
||||
* BASEDIR
|
||||
* config
|
||||
* pathinfo
|
||||
|
||||
profile_name is str with name of the profile
|
||||
config is instance of optparse.Values()
|
||||
"""
|
||||
global PROFILE_MODULES # Dict with loaded modules
|
||||
|
||||
# If config is passed use it and don't load koji config files by yourself
|
||||
if config is None:
|
||||
result = read_config(profile_name)
|
||||
config = optparse.Values(result)
|
||||
|
||||
# Prepare module name
|
||||
mod_name = "__%s__%s" % (__name__, profile_name)
|
||||
|
||||
# Check if profile module exists and if so return it
|
||||
if mod_name in PROFILE_MODULES:
|
||||
return PROFILE_MODULES[mod_name]
|
||||
|
||||
# Load current module under a new name
|
||||
koji_module_loc = imp.find_module(__name__)
|
||||
mod = imp.load_module(mod_name,
|
||||
None,
|
||||
koji_module_loc[1],
|
||||
koji_module_loc[2])
|
||||
|
||||
# Tweak config of the new module
|
||||
mod.config = config
|
||||
mod.BASEDIR = config.topdir
|
||||
mod.pathinfo.topdir = config.topdir
|
||||
|
||||
# Be sure that get_profile_module is only called from main module
|
||||
mod.get_profile_module = get_profile_module
|
||||
|
||||
return mod
|
||||
|
||||
|
||||
class PathInfo(object):
|
||||
# ASCII numbers and upper- and lower-case letter for use in tmpdir()
|
||||
ASCII_CHARS = [chr(i) for i in range(48, 58) + range(65, 91) + range(97, 123)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue