]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/python/osrf/set.py
implemented the majority of server-side python. still need to add settings server...
[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, osrf.net_obj, osrf.ses
18
19 # global settings config object
20 __config = None
21
22 def get(path, idx=0):
23     global __config
24     val = osrf.net_obj.find_object_path(__config, path, idx)
25     if not val:
26         raise osrf.ex.OSRFConfigException("Config value not found: " + path)
27     return val
28
29
30 def load(hostname):
31     global __config
32
33     ses = osrf.ses.ClientSession(OSRF_APP_SETTINGS)
34     req = ses.request(OSRF_METHOD_GET_HOST_CONFIG, hostname)
35     resp = req.recv(timeout=30)
36     __config = resp.content()
37     req.cleanup()
38     ses.cleanup()
39