paulo@56: import os paulo@56: import sys paulo@56: import signal paulo@56: paulo@56: import cherrypy paulo@56: from cherrypy import wsgiserver paulo@52: paulo@52: import pics_app paulo@52: paulo@52: paulo@56: def sighandler(signum, frame): paulo@56: sys.stderr.write("Caught signal: %s \n" % signum) paulo@56: server.stop() paulo@56: paulo@56: paulo@57: MIMETYPE = { paulo@57: ".webm": "video/webm", paulo@57: } paulo@57: paulo@57: paulo@56: class FileServerRoot: paulo@56: def default(self, *args): paulo@56: if len(args) == 0: paulo@56: raise cherrypy.HTTPError(404) paulo@56: paulo@56: filepath = os.path.abspath(os.path.join(*args)) paulo@57: ext = os.path.splitext(filepath)[1] paulo@57: return cherrypy.lib.static.serve_file(filepath, content_type=MIMETYPE.get(ext)) paulo@56: paulo@56: default.exposed = True paulo@52: paulo@52: paulo@52: if __name__ == "__main__": paulo@56: fileServerApp = cherrypy.Application(FileServerRoot()) paulo@56: dispatcher = wsgiserver.WSGIPathInfoDispatcher({ paulo@56: "/pics.fcgi": pics_app.app, paulo@56: "": fileServerApp, paulo@56: }) paulo@56: server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher) paulo@56: paulo@56: signal.signal(signal.SIGINT, sighandler) paulo@56: signal.signal(signal.SIGTERM, sighandler) paulo@56: paulo@56: server.start()