source: ceda_http_fileserver/trunk/ceda_http_fileserver/ceda/server/wsgi/fileserver/test/__init__.py @ 6999

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ceda_http_fileserver/trunk/ceda_http_fileserver/ceda/server/wsgi/fileserver/test/__init__.py@6999
Revision 6999, 2.0 KB checked in by pjkersha, 10 years ago (diff)

Incomplete - task 9: Data Browser Replacement

  • fixes to do_get
  • Property svn:keywords set to Id
Line 
1"""CEDA (Centre for Environmental Data Archival) unit test package
2
3CEDA HTTP File Server WSGI Application
4"""
5__author__ = "P J Kershaw"
6__date__ = "11/06/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__license__ = """http://www.apache.org/licenses/LICENSE-2.0"""
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = '$Id$'
11import logging
12logging.basicConfig(level=logging.DEBUG)
13
14import paste.httpserver
15from threading import Thread
16from paste.deploy import loadapp
17from paste.script.util.logging_config import fileConfig
18
19
20class PasteDeployAppServer(object):
21    """Wrapper to paste.httpserver to enable background threading"""
22   
23    def __init__(self, app=None, cfgFilePath=None, port=7443, host='0.0.0.0',
24                 ssl_context=None, withLoggingConfig=True):
25        """Load an application configuration from cfgFilePath ini file and
26        instantiate Paste server object
27        """       
28        self.__thread = None
29       
30        if cfgFilePath:
31            if withLoggingConfig:
32                fileConfig(cfgFilePath)
33            app = loadapp('config:%s' % cfgFilePath)
34           
35        elif app is None:
36            raise KeyError('Either the "cfgFilePath" or "app" keyword must be '
37                           'set')
38                       
39        self.__pasteServer = paste.httpserver.serve(app, host=host, port=port, 
40                                                    start_loop=False, 
41                                                    ssl_context=ssl_context)
42   
43    @property
44    def pasteServer(self):
45        return self.__pasteServer
46   
47    @property
48    def thread(self):
49        return self.__thread
50   
51    def start(self):
52        """Start server"""
53        self.pasteServer.serve_forever()
54       
55    def startThread(self):
56        """Start server in a separate thread"""
57        self.__thread = Thread(target=PasteDeployAppServer.start, args=(self,))
58        self.thread.start()
59       
60    def terminateThread(self):
61        self.pasteServer.server_close()
Note: See TracBrowser for help on using the repository browser.