#!/usr/bin/python3 """Our cherrypy server, it all starts here Let's look at the statically linked stuff as well (i.e. the files that will serve us data). These imports are static files in the same directory. Each a spearate application with it's own face and behavior """ import os import cherrypy import OpenSSL import sys # UI for weather ./weather.py import weather # CSV "API" for graphs, or individual pulling ./dynamic.py import dynamic # UI for RasPi / davis status ./status.py import status PATH = os.path.abspath(os.path.dirname(__file__)) # Where are we? _SCRIPT_PATH = os.path.dirname(sys.argv[0]) # Certificates fro SSL reside here _CERT_PATH = _SCRIPT_PATH + '/.cert' # So we can load static libraries # sys.path.append(_SCRIPT_PATH) # basic config for the server, the SSL part is questionable... server_config = { 'server.socket_host': '0.0.0.0', 'server.socket_port': 443, 'server.ssl_module': 'builtin', 'server.ssl_certificate': _CERT_PATH + '/fullchain1.pem', 'server.ssl_private_key': _CERT_PATH + '/privkey1.pem' } # commit the config settings cherrypy.config.update(server_config) # If launched directly, let's go if __name__ == '__main__': conf = { '/': { 'tools.sessions.on': True, 'tools.staticdir.root': os.path.abspath(_SCRIPT_PATH + '/') }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.abspath(_SCRIPT_PATH + '/static') }, '/data': { 'tools.staticdir.on': False, 'tools.staticdir.dir': os.path.abspath(_SCRIPT_PATH + '/dynamic') } } # Here are the different served mounts cherrypy.tree.mount(weather.WeatherInfo(), "/", conf) cherrypy.tree.mount(status.StatusInfo(), "/status", conf) cherrypy.tree.mount(dynamic.DynamicData(), "/data", conf) # Run the server, lock it in place. cherrypy.engine.start() cherrypy.engine.block()