diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-31 18:17:08 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-31 18:17:08 -0600 |
commit | a23d41a57f43c3a0f298d3918ae1712181fa544e (patch) | |
tree | bc8fdc606887d39a0847d9f78e212d4771a1150f /ipalib/plugable.py | |
parent | cdfb7bfd5ebc1f5e44f4ee60cec14354040a0a72 (diff) | |
download | freeipa-a23d41a57f43c3a0f298d3918ae1712181fa544e.tar.gz freeipa-a23d41a57f43c3a0f298d3918ae1712181fa544e.tar.xz freeipa-a23d41a57f43c3a0f298d3918ae1712181fa544e.zip |
Reoganized global option functionality to it is easy for any script to use the environment-related global options; lite-xmlrpc.py now uses same global options
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r-- | ipalib/plugable.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 9e612d68d..f552b61f6 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -26,6 +26,7 @@ http://docs.python.org/ref/sequence-types.html """ import re +import sys import inspect import threading import logging @@ -38,6 +39,7 @@ from constants import LOGGING_FILE_FORMAT, LOGGING_CONSOLE_FORMAT, DEFAULT_CONFI import util + class ReadOnly(object): """ Base class for classes with read-only attributes. @@ -812,6 +814,31 @@ class API(DictProxy): handler.setLevel(level) log.addHandler(handler) + def bootstrap_from_options(self, options=None, context=None): + if options is None: + parser = util.add_global_options() + (options, args) = parser.parse_args( + list(s.decode('utf-8') for s in sys.argv[1:]) + ) + overrides = {} + if options.env is not None: + assert type(options.env) is list + for item in options.env: + try: + (key, value) = item.split('=', 1) + except ValueError: + # FIXME: this should raise an IPA exception with an + # error code. + # --Jason, 2008-10-31 + pass + overrides[str(key.strip())] = value.strip() + for key in ('conf', 'debug', 'verbose'): + value = getattr(options, key, None) + if value is not None: + overrides[key] = value + if context is not None: + overrides['context'] = context + self.bootstrap(**overrides) def load_plugins(self): """ |