-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (30 loc) · 909 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import web
from routes.index import Index
from routes.settings import Settings
import time
import controller.settings as settings
PossibleUrls = (
'/api/settings', 'Settings',
'/api/settings/(.*)/(.*)', 'Settings',
'/api/settings/(.*)', 'Settings',
'/favicon.ico', 'Favicon',
'/(.*)', 'Index',
'/', 'Index'
)
port_num = settings.configuration['Server']['Port']
def cleanup():
print ('cleaning up before exit..')
try:
import RPi.GPIO as GPIO
GPIO.cleanup()
except:
print('nothing')
if __name__ == "__main__":
Server = web.application(PossibleUrls,globals())
try:
web.httpserver.runsimple(Server.wsgifunc(), ("0.0.0.0", port_num))
except Exception as e:
print('An Error occurred:\n' + str(e))
time.sleep(5)
finally:
cleanup()