Mercurial > code > home > repos > homeauto
comparison service/dpms/dpms.py @ 83:add8a36e54bd
dpms: more monitor states. separate powerState and powerStateMeasured
Ignore-this: d9f21d0921c3f72ab31ac2a4c1e073cf
author | drewp@bigasterisk.com |
---|---|
date | Fri, 02 Aug 2013 07:57:31 -0700 |
parents | a6d7c3a96684 |
children | 1e94d074f642 |
comparison
equal
deleted
inserted
replaced
82:d288bc1174d4 | 83:add8a36e54bd |
---|---|
4 sample supervisord block | 4 sample supervisord block |
5 | 5 |
6 [program:dpms_9095] | 6 [program:dpms_9095] |
7 directory=/my/proj/homeauto/service/dpms | 7 directory=/my/proj/homeauto/service/dpms |
8 command=/my/proj/homeauto/service/dpms/bin/python dpms.py | 8 command=/my/proj/homeauto/service/dpms/bin/python dpms.py |
9 environment=DISPLAY=:0.0 | |
10 user=drewp | 9 user=drewp |
11 | 10 |
12 On one box, this goes super slow when avahi daemon is running. Maybe | 11 On one box, this goes super slow when avahi daemon is running. Maybe |
13 it's for an attempted dns lookup of the requesting IP address, which I | 12 it's for an attempted dns lookup of the requesting IP address, which I |
14 wish I could switch off. | 13 wish I could switch off. |
14 | |
15 -- | |
16 | |
17 may need this: | |
18 ps axf | grep /run/gdm | |
19 18339 tty7 Ss+ 0:00 \_ /usr/bin/X :0 -background none -verbose -auth /run/gdm/auth-for-gdm-iQoCDZ/database -nolisten tcp vt7 | |
20 eval xauth add `sudo xauth -f /run/gdm/auth-for-gdm-iQoCDZ/database list :0` | |
15 | 21 |
16 """ | 22 """ |
17 | 23 |
18 from bottle import run, get, put, request, response | 24 from bottle import run, get, put, request, response |
19 import subprocess, sys, socket | 25 import subprocess, sys, socket |
21 DEV = Namespace("http://projects.bigasterisk.com/device/") | 27 DEV = Namespace("http://projects.bigasterisk.com/device/") |
22 ROOM = Namespace("http://projects.bigasterisk.com/room/") | 28 ROOM = Namespace("http://projects.bigasterisk.com/room/") |
23 | 29 |
24 sys.path.append("/my/site/magma") | 30 sys.path.append("/my/site/magma") |
25 from stategraph import StateGraph | 31 from stategraph import StateGraph |
32 sys.path.append("../../lib") | |
33 from localdisplay import setDisplayToLocalX | |
26 | 34 |
27 def getMonitorState(): | 35 def getMonitorState(): |
28 out = subprocess.check_output(['xset', 'q']) | 36 out = subprocess.check_output(['xset', 'q']) |
29 for line in out.splitlines(): | 37 for line in out.splitlines(): |
30 line = line.strip() | 38 line = line.strip() |
31 if line == 'Monitor is On': | 39 if line == 'Monitor is On': |
32 response.set_header('content-type', 'text/plain') | 40 response.set_header('content-type', 'text/plain') |
33 return 'on' | 41 return 'on' |
34 elif line == 'Monitor is Off': | 42 elif line in ['Monitor is Off', 'Monitor is in Suspend', 'Monitor is in Standby']: |
35 response.set_header('content-type', 'text/plain') | 43 response.set_header('content-type', 'text/plain') |
36 return 'off' | 44 return 'off' |
37 raise NotImplementedError("no matching monitor line in xset output") | 45 raise NotImplementedError("no matching monitor line in xset output") |
38 | 46 |
39 @get("/") | 47 @get("/") |
60 @get("/graph") | 68 @get("/graph") |
61 def graph(): | 69 def graph(): |
62 host = socket.gethostname() | 70 host = socket.gethostname() |
63 g = StateGraph(ctx=DEV['dpms/%s' % host]) | 71 g = StateGraph(ctx=DEV['dpms/%s' % host]) |
64 g.add((URIRef("http://bigasterisk.com/host/%s/monitor" % host), | 72 g.add((URIRef("http://bigasterisk.com/host/%s/monitor" % host), |
65 ROOM['powerState'], | 73 ROOM['powerStateMeasured'], |
66 ROOM[getMonitorState()])) | 74 ROOM[getMonitorState()])) |
67 | 75 |
68 response.set_header('Content-type', 'application/x-trig') | 76 response.set_header('Content-type', 'application/x-trig') |
69 return g.asTrig() | 77 return g.asTrig() |
70 | |
71 run(host="0.0.0.0", port=9095, quiet=True) | |
72 | 78 |
79 setDisplayToLocalX() | |
80 | |
81 run(host="0.0.0.0", server='gunicorn', port=9095, quiet=True) | |
82 |