diff options
-rw-r--r-- | ipalib/cli.py | 3 | ||||
-rw-r--r-- | ipalib/config.py | 33 | ||||
-rw-r--r-- | ipalib/plugins/f_user.py | 4 |
3 files changed, 31 insertions, 9 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index d66e1e2eb..fc85dcb02 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -256,7 +256,8 @@ class CLI(object): self.print_commands() print 'Usage: ipa COMMAND' sys.exit(2) - self.api.env.update(config.generate_env()) + env_dict = config.read_config() + self.api.env.update(config.generate_env(env_dict)) key = sys.argv[1] if key not in self: self.print_commands() 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 diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py index 29f0f8a07..150d48ead 100644 --- a/ipalib/plugins/f_user.py +++ b/ipalib/plugins/f_user.py @@ -35,10 +35,10 @@ class envtest(frontend.Command): print "Environment variables:" for var in api.env: val = api.env[var] - if var is 'servers': + if var is 'server': print "" print " Servers:" - for item in api.env.servers: + for item in api.env.server: print " %s" % item print "" else: |