---
cli/koji | 4 +++
docs/profiles.rst | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
koji/__init__.py | 23 +++++++++++++++++
3 files changed, 101 insertions(+)
create mode 100644 docs/profiles.rst
diff --git a/cli/koji b/cli/koji
index 66f4d99..6663111 100755
--- a/cli/koji
+++ b/cli/koji
@@ -6626,6 +6626,10 @@ if __name__ == "__main__":
global options
options, command, args = get_options()
+ # override koji module with profile specific koji module
+ global koji
+ koji = koji.get_profile_module(options.profile)
+
logger = logging.getLogger("koji")
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(name)s:
%(message)s'))
diff --git a/docs/profiles.rst b/docs/profiles.rst
new file mode 100644
index 0000000..b9b5ee6
--- /dev/null
+++ b/docs/profiles.rst
@@ -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 all, 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
diff --git a/koji/__init__.py b/koji/__init__.py
index 9951a28..6cd8495 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -33,6 +33,7 @@ import datetime
import errno
from fnmatch import fnmatch
import httplib
+import imp
import logging
import logging.handlers
from koji.util import md5_constructor
@@ -1563,6 +1564,28 @@ def read_config(profile_name, user_config=None):
return options
+# default config for "koji" profile
+config = read_config("koji")
+
+
+def get_profile_module(profile_name, config=None):
+ """
+ Create module for a koji instance.
+ Override profile specific module attributes:
+ * BASEDIR
+ * config
+ * pathinfo
+ """
+ if config is None:
+ config = read_config(profile_name)
+ mod = imp.new_module("_koji__%s" % profile_name)
+ mod.__dict__.update(globals())
+ mod.config = config
+ mod.BASEDIR = config.topdir
+ mod.pathinfo = PathInfo(topdir=config.topdir)
+ 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)]
--
2.5.0