1 # -----------------------------------------------------------------------
2 # Copyright (C) 2007 Georgia Public Library Service
3 # Bill Erickson <billserickson@gmail.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 # -----------------------------------------------------------------------
17 from osrf.utils import *
21 class osrfConfig(object):
22 """Loads and parses the bootstrap config file"""
26 def __init__(self, file, context=None):
28 self.context = context
31 #def parseConfig(self,file=None):
32 def parseConfig(self):
33 self.data = osrfXMLFileToObject(self.file)
34 osrfConfig.config = self
36 def getValue(self, key, idx=None):
38 if re.search('/', key):
39 key = "%s/%s" % (self.context, key)
41 key = "%s.%s" % (self.context, key)
43 val = osrfObjectFindPath(self.data, key, idx)
45 raise osrfConfigException("Config value not found: " + key)
49 def osrfConfigValue(key, idx=None):
50 """Returns a bootstrap config value.
52 key -- A string representing the path to the value in the config object
53 e.g. "domains.domain", "username"
54 idx -- Optional array index if the searched value is an array member
56 return osrfConfig.config.getValue(key, idx)
59 def osrfConfigValueNoEx(key, idx=None):
60 """ Returns a bootstrap config value without throwing an exception
61 if the item is not found.
63 key -- A string representing the path to the value in the config object
64 e.g. "domains.domain", "username"
65 idx -- Optional array index if the searched value is an array member
68 return osrfConfig.config.getValue(key, idx)