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.net import Network, set_network_handle, get_network_handle
18 import osrf.stack, osrf.log, osrf.set, osrf.cache
27 def net_connect(**kwargs):
28 if get_network_handle():
29 ''' This thread already has a handle '''
32 config_file = kwargs.get('config_file') or System.config_file
33 config_context = kwargs.get('config_context') or System.config_context
35 # store the last config file info for later
36 System.config_file = config_file
37 System.config_context = config_context
39 # parse the config file
40 config_parser = osrf.conf.Config(config_file, config_context)
41 config_parser.parse_config()
45 osrf.conf.get('loglevel'),
46 osrf.conf.get_no_ex('syslog'),
47 osrf.conf.get_no_ex('logfile'))
49 # connect to the opensrf network
51 host = osrf.conf.get('domain'),
52 port = osrf.conf.get('port'),
53 username = osrf.conf.get('username'),
54 password = osrf.conf.get('passwd'),
55 resource = kwargs.get('resource'))
57 network.set_receive_callback(osrf.stack.push)
58 osrf.net.set_network_handle(network)
65 def connect(**kwargs):
66 """ Connects to the opensrf network
74 network = System.net_connect(**kwargs)
76 # load the domain-wide settings file
77 osrf.set.load(osrf.conf.get('domain'))
79 if kwargs.get('connect_cache'):
80 System.connect_cache()
87 ''' Initializes the cache connections '''
88 cache_servers = osrf.set.get('cache.global.servers.server')
90 if not isinstance(cache_servers, list):
91 cache_servers = [cache_servers]
92 if not osrf.cache.CacheClient.get_client():
93 osrf.cache.CacheClient.connect(cache_servers)