New, updated version of web. Might contain customizations
This commit is contained in:
@@ -1,59 +1,65 @@
|
||||
#!/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 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__))
|
||||
import index
|
||||
from modules import voltage
|
||||
from modules import weather
|
||||
from modules import dynamic
|
||||
from modules import status
|
||||
from modules import temphumi
|
||||
import config
|
||||
|
||||
# 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)
|
||||
def main_server_loop():
|
||||
''' Master http server - the main executable / daemon
|
||||
|
||||
Contains basic server settings and how the sub-modules
|
||||
are called and mounted to their respective paths
|
||||
|
||||
# basic config for the server, the SSL part is questionable...
|
||||
server_config = {
|
||||
'server.socket_host': '0.0.0.0',
|
||||
'server.socket_port': 80
|
||||
}
|
||||
# commit the config settings
|
||||
cherrypy.config.update(server_config)
|
||||
Args:
|
||||
*None*
|
||||
|
||||
# If launched directly, let's go
|
||||
if __name__ == '__main__':
|
||||
Sets:
|
||||
*server_config:* dict(), updates cherrypy.config
|
||||
*conf:* dict(), see Cherrypy docs for more
|
||||
*cherrypy.config:* dict(), see Cherrypy docs for more
|
||||
|
||||
Returns:
|
||||
*N/A*
|
||||
|
||||
Raises:
|
||||
*Exception* If server is unable to start
|
||||
|
||||
'''
|
||||
server_config={
|
||||
'server.socket_host': config.Conf.val['_server_bind_ip'],
|
||||
'server.socket_port': config.Conf.val['_server_port']
|
||||
}
|
||||
cherrypy.config.update(server_config)
|
||||
conf = {
|
||||
'/': {
|
||||
'tools.sessions.on': True,
|
||||
'tools.staticdir.root': os.path.abspath(_SCRIPT_PATH + '/')
|
||||
'tools.staticdir.root': os.path.abspath(config.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')
|
||||
'tools.staticdir.dir': './static'
|
||||
}
|
||||
}
|
||||
|
||||
# Here are the different served mounts
|
||||
cherrypy.tree.mount(weather.WeatherInfo(), "/", conf)
|
||||
cherrypy.tree.mount(voltage.EnergyInfo(), "/", conf)
|
||||
cherrypy.tree.mount(voltage.EnergyInfo(), "/energy", conf)
|
||||
cherrypy.tree.mount(weather.WeatherInfo(), "/weather", conf)
|
||||
cherrypy.tree.mount(status.StatusInfo(), "/status", conf)
|
||||
cherrypy.tree.mount(dynamic.DynamicData(), "/data", conf)
|
||||
|
||||
# Run the server, lock it in place.
|
||||
cherrypy.tree.mount(dynamic.Expose(), "/data", conf)
|
||||
cherrypy.tree.mount(temphumi.PuerhInfo(), "/temphumi", conf)
|
||||
cherrypy.engine.start()
|
||||
cherrypy.engine.block()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main_server_loop()
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
Reference in New Issue
Block a user