]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/python/osrf/conf.py
adding python libs
[OpenSRF.git] / src / python / osrf / conf.py
1 # -----------------------------------------------------------------------
2 # Copyright (C) 2007  Georgia Public Library Service
3 # Bill Erickson <billserickson@gmail.com>
4
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.
9
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 # -----------------------------------------------------------------------
15
16
17 from osrf.utils import *
18 from osrf.ex import *
19
20 class osrfConfig(object):
21         """Loads and parses the bootstrap config file"""
22
23         config = None
24
25         def __init__(self, file=None):
26                 self.file = file        
27                 self.data = {}
28
29         def parseConfig(self,file=None):
30                 self.data = osrfXMLFileToObject(file or self.file)
31                 osrfConfig.config = self
32         
33         def getValue(self, key, idx=None):
34                 val = osrfObjectFindPath(self.data, key, idx)
35                 if not val:
36                         raise osrfConfigException("Config value not found: " + key)
37                 return val
38
39
40 def osrfConfigValue(key, idx=None):
41         """Returns a bootstrap config value.
42
43         key -- A string representing the path to the value in the config object
44                 e.g.  "domains.domain", "username"
45         idx -- Optional array index if the searched value is an array member
46         """
47         return osrfConfig.config.getValue(key, idx)
48