#!/usr/bin/python3 """Our cherrypy server, it all starts here """ import os import cherrypy import OpenSSL import sys PATH = os.path.abspath(os.path.dirname(__file__)) # Where are we? _SCRIPT_PATH = os.path.dirname(sys.argv[0]) # So we can load static libraries sys.path.append(_SCRIPT_PATH) # Certificates reside here _CERT_PATH = _SCRIPT_PATH + '/.cert' """Let's look at the statically linked stuff (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 """ # 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 #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': './static' }, '/data': { 'tools.staticdir.on': False, 'tools.staticdir.dir': './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()