]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/python/osrf/system.py
Continue the march towards a pedantic 1.0 python API.
[OpenSRF.git] / src / python / osrf / system.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.conf import Config, get, get_no_ex
17 from osrf.net import Network, set_network_handle, get_network_handle
18 import osrf.stack
19 import osrf.log
20 import osrf.set
21 import sys
22
23
24 def connect(configFile, configContext):
25     """ Connects to the opensrf network """
26
27     if get_network_handle():
28         ''' This thread already has a handle '''
29         return
30
31     # parse the config file
32     configParser = Config(configFile, configContext)
33     configParser.parseConfig()
34     
35     # set up logging
36     osrf.log.initialize(
37         osrf.conf.get('loglevel'), 
38         osrf.conf.get_no_ex('syslog'),
39         osrf.conf.get_no_ex('logfile'))
40
41     # connect to the opensrf network
42     network = Network(
43         host = osrf.conf.get('domains.domain'),
44         port = osrf.conf.get('port'),
45         username = osrf.conf.get('username'), 
46         password = osrf.conf.get('passwd'))
47     network.set_receive_callback(osrf.stack.push)
48     osrf.net.set_network_handle(network)
49     network.connect()
50
51     # load the domain-wide settings file
52     osrf.set.load(osrf.conf.get('domains.domain'))
53