/
pizzadaemon.py
executable file
·52 lines (35 loc) · 1.01 KB
/
pizzadaemon.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
#coding: utf-8
import pnmp
import sys
import time
import random
import urllib2
import re
import string
#CONFIG
COM_PORT = '/dev/tty.usbmodemfa131'
URL = "http://www.komsys.org/pizza-netmap/src/pizza-netmap2/nms-simulator/switchlist.txt"
POLL_INTERVAL = 5 #Seconds between update
# END CONFIG
################################
# MONITORING
################################
def list_com_ports():
from serial.tools import list_ports
return "Choose serial device / COM port: \n %s" % '\n'.join(list("\t[%u] : %s" % (i, u[0]) for i,u in enumerate( list_ports.comports() )))
if __name__ == '__main__':
print ("Init")
#print ( list_com_ports())
api = pnmp.api(COM_PORT)
try:
while 1:
statusmap = [ re.split("\s", string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ]
print ("Pushing state")
print (statusmap)
api.pushState(statusmap)
time.sleep(POLL_INTERVAL)
except KeyboardInterrupt:
api.clean_the_mess_up_after_you()
finally:
print ( "No more pizza!")