Package myproxy :: Package ws :: Package test :: Module server_utils
[hide private]

Source Code for Module myproxy.ws.test.server_utils

 1  """MyProxy Server Utilities module 
 2  """ 
 3  __author__ = "P J Kershaw" 
 4  __date__ = "28/05/12" 
 5  __copyright__ = "(C) 2012 Science and Technology Facilities Council" 
 6  __license__ = "BSD - see LICENSE file in top-level directory" 
 7  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
 8  __revision__ = '$Id$' 
 9  import logging 
10  logging.basicConfig(level=logging.DEBUG) 
11   
12  import paste.httpserver 
13  from threading import Thread 
14  from paste.deploy import loadapp 
15  from paste.script.util.logging_config import fileConfig 
16 17 18 -class PasteDeployAppServer(object):
19 """Wrapper to paste.httpserver to enable background threading""" 20
21 - def __init__(self, app=None, cfgFilePath=None, port=7443, host='0.0.0.0', 22 ssl_context=None, withLoggingConfig=True):
23 """Load an application configuration from cfgFilePath ini file and 24 instantiate Paste server object 25 """ 26 self.__thread = None 27 28 if cfgFilePath: 29 if withLoggingConfig: 30 fileConfig(cfgFilePath) 31 app = loadapp('config:%s' % cfgFilePath) 32 33 elif app is None: 34 raise KeyError('Either the "cfgFilePath" or "app" keyword must be ' 35 'set') 36 37 self.__pasteServer = paste.httpserver.serve(app, host=host, port=port, 38 start_loop=False, 39 ssl_context=ssl_context)
40 41 @property
42 - def pasteServer(self):
43 return self.__pasteServer
44 45 @property
46 - def thread(self):
47 return self.__thread
48
49 - def start(self):
50 """Start server""" 51 self.pasteServer.serve_forever()
52
53 - def startThread(self):
54 """Start server in a separate thread""" 55 self.__thread = Thread(target=PasteDeployAppServer.start, args=(self,)) 56 self.thread.start()
57
58 - def terminateThread(self):
59 self.pasteServer.server_close()
60