mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Implement config file reading
This commit is contained in:
parent
0606226b14
commit
4a68c719f0
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user