]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/python/osrf/set.py
added an xml flattener similar to the java xml flattener
[OpenSRF.git] / src / python / osrf / set.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 from osrf.const import OSRF_APP_SETTINGS, OSRF_METHOD_GET_HOST_CONFIG
17 import osrf.ex
18 import osrf.net_obj
19
20 # global settings config object
21 __config = None
22
23 def get(path, idx=0):
24     global __config
25     val = osrf.net_obj.find_object_path(__config, path, idx)
26     if not val:
27         raise osrf.ex.OSRFConfigException("Config value not found: " + path)
28     return val
29
30
31 def load(hostname):
32     global __config
33
34     from osrf.system import connect
35     from osrf.ses import ClientSession
36
37     ses = ClientSession(OSRF_APP_SETTINGS)
38     req = ses.request(OSRF_METHOD_GET_HOST_CONFIG, hostname)
39     resp = req.recv(timeout=30)
40     __config = resp.content()
41     req.cleanup()
42     ses.cleanup()
43