diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-07 16:48:07 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-07 16:48:07 -0600 |
commit | 439d9c305b7a2353ecb9373cf14c4e926522aaa3 (patch) | |
tree | 137683bdd0534b5b84578ade3669873f1c70f0b1 /ipalib/config.py | |
parent | 33aa9de1b59ccd6cfaaf3fab435bf6bf101897f2 (diff) | |
parent | 732785b997bfe109b6cfc5695408a64580f7c85f (diff) | |
download | freeipa.git-439d9c305b7a2353ecb9373cf14c4e926522aaa3.tar.gz freeipa.git-439d9c305b7a2353ecb9373cf14c4e926522aaa3.tar.xz freeipa.git-439d9c305b7a2353ecb9373cf14c4e926522aaa3.zip |
Merge branch 'master' of git://git.engineering.redhat.com/users/mnagy/freeipa2
Diffstat (limited to 'ipalib/config.py')
-rw-r--r-- | ipalib/config.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/ipalib/config.py b/ipalib/config.py index f327cab7..a0a33b40 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -17,7 +17,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +from ConfigParser import SafeConfigParser, ParsingError import types +import os DEFAULT_CONF='/etc/ipa/ipa.conf' @@ -26,7 +28,8 @@ def generate_env(d={}): server_context = False, query_dns = True, verbose = False, - servers = LazyIter(get_servers), + interactive = True, + server = LazyIter(get_servers), realm = LazyProp(get_realm), domain = LazyProp(get_domain), ) @@ -68,11 +71,33 @@ class LazyIter(LazyProp): yield item -def read_config(file=DEFAULT_CONF): - assert isinstance(file, basestring) - # open the file and read configuration, return a dict - # for now, these are here just for testing purposes - return dict(servers="server.ipatest.com", realm="IPATEST.COM") +def read_config(config_file=None): + assert config_file == None or isinstance(config_file, (basestring, file)) + + parser = SafeConfigParser() + if config_file == None: + files = [DEFAULT_CONF, os.path.expanduser('~/.ipa.conf')] + else: + files = [config_file] + + for f in files: + try: + if isinstance(f, file): + parser.readfp(f) + else: + parser.read(f) + except ParsingError: + print "Can't read %s" % f + + ret = {} + if parser.has_section('defaults'): + for name, value in parser.items('defaults'): + value = tuple(elem.strip() for elem in value.split(',')) + if len(value) == 1: + value = value[0] + ret[name] = value + + return ret # these functions are here just to "emulate" dns resolving for now |