summaryrefslogtreecommitdiffstats
path: root/ipalib/config.py
diff options
context:
space:
mode:
authorMartin Nagy <mnagy@redhat.com>2008-10-03 17:08:37 +0200
committerMartin Nagy <mnagy@redhat.com>2008-10-08 00:07:44 +0200
commit4a68c719f03c176bc63a96007c089d0ac7ae5fc1 (patch)
treef2b73f804934d4076543945ad0e68601ba5b9353 /ipalib/config.py
parent0606226b1478a0abf7ff20d53cd47ea1efa43b5e (diff)
downloadfreeipa-4a68c719f03c176bc63a96007c089d0ac7ae5fc1.tar.gz
freeipa-4a68c719f03c176bc63a96007c089d0ac7ae5fc1.tar.xz
freeipa-4a68c719f03c176bc63a96007c089d0ac7ae5fc1.zip
Implement config file reading
Diffstat (limited to 'ipalib/config.py')
-rw-r--r--ipalib/config.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/ipalib/config.py b/ipalib/config.py
index f327cab74..16bc13714 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,7 @@ def generate_env(d={}):
server_context = False,
query_dns = True,
verbose = False,
- servers = LazyIter(get_servers),
+ server = LazyIter(get_servers),
realm = LazyProp(get_realm),
domain = LazyProp(get_domain),
)
@@ -68,11 +70,30 @@ 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=DEFAULT_CONF):
+ assert isinstance(config_file, (basestring, file))
+
+ parser = SafeConfigParser()
+ files = [config_file, os.path.expanduser('~/.ipa.conf')]
+
+ 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