Mercurial > code > home > repos > homeauto
changeset 1682:d6996175ea78
checkpoint service/dpms
author | drewp@bigasterisk.com |
---|---|
date | Mon, 27 Sep 2021 23:05:30 -0700 |
parents | 9d074317e16a |
children | 437d7263b515 |
files | service/dpms/Dockerfile.pi service/dpms/dpms_service.py |
diffstat | 2 files changed, 68 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/service/dpms/Dockerfile.pi Mon Sep 27 23:04:36 2021 -0700 +++ b/service/dpms/Dockerfile.pi Mon Sep 27 23:05:30 2021 -0700 @@ -2,13 +2,12 @@ RUN apt-get install -y x11-xserver-utils COPY requirements.txt ./ -RUN pip install -r requirements.txt - -ADD https://projects.bigasterisk.com/rdfdb/more.tgz ./ -RUN tar xvzf more.tgz +RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt +# not sure why this doesn't work from inside requirements.txt +RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' COPY *.py ./ EXPOSE 9095 -CMD [ "python", "./dpms_service.py" ] +CMD [ "python3", "./dpms_service.py" ]
--- a/service/dpms/dpms_service.py Mon Sep 27 23:04:36 2021 -0700 +++ b/service/dpms/dpms_service.py Mon Sep 27 23:05:30 2021 -0700 @@ -1,19 +1,6 @@ #!bin/python """ -sample supervisord block - -[program:dpms_9095] -directory=/my/proj/homeauto/service/dpms -command=/my/proj/homeauto/service/dpms/bin/python dpms.py -user=drewp - -On one box, this goes super slow when avahi daemon is running. Maybe -it's for an attempted dns lookup of the requesting IP address, which I -wish I could switch off. - --- - may need this: ps axf | grep /run/gdm 18339 tty7 Ss+ 0:00 \_ /usr/bin/X :0 -background none -verbose -auth /run/gdm/auth-for-gdm-iQoCDZ/database -nolisten tcp vt7 @@ -26,47 +13,89 @@ from influxdb import InfluxDBClient import subprocess, sys, socket, time, os from rdflib import Namespace, URIRef -from logsetup import log, enableTwistedLog +from standardservice.logsetup import log, verboseLogging +from cycloneerr import PrettyErrorHandler +import dpms -from dpms import DPMS, DPMSModeOn DEV = Namespace("http://projects.bigasterisk.com/device/") ROOM = Namespace("http://projects.bigasterisk.com/room/") -sys.path.append("/my/site/magma") from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler -#sys.path.append("../../lib") -#from localdisplay import setDisplayToLocalX influx = InfluxDBClient('bang6', 9060, 'root', 'root', 'main') -os.environ['DISPLAY'] = ':0.0' +host = socket.gethostname() -dpms = DPMS() -host = socket.gethostname() +os.environ['DISPLAY'] = ':0.0' +d = dpms.DPMS() + def getMonitorState(): - level, enabled = dpms.Info() - return 'on' if level == DPMSModeOn else 'off' + return 'on' if d.Info()[0] == dpms.DPMSModeOn else 'off' -class Root(cyclone.web.RequestHandler): +class Root(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): getMonitorState() # to make it fail if xset isn't working + self.set_header('content-type', 'text/html') self.write(''' - Get and put the <a href="monitor">monitor power</a> with dpms. - <a href="graph">rdf graph</a> available.''') - -class Monitor(cyclone.web.RequestHandler): + <!doctype html> +<html> + <head> + <title>dpms</title> + <meta charset="utf-8" /> + <script src="/lib/polymer/1.0.9/webcomponentsjs/webcomponents.min.js"></script> + <script src="/lib/require/require-2.3.3.js"></script> + <script src="/rdf/common_paths_and_ns.js"></script> + + <link rel="import" href="/rdf/streamed-graph.html"> + <link rel="import" href="/lib/polymer/1.0.9/polymer/polymer.html"> + + <meta name="mobile-web-app-capable" content="yes"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + </head> + <body> + <template id="t" is="dom-bind"> + + Get and put the <a href="monitor">monitor power</a> with dpms. + + <streamed-graph url="graph/dpms/events" graph="{{graph}}"></streamed-graph> + <div id="out"></div> + <script type="module" src="/rdf/streamed_graph_view.js"></script> + </template> + <style> + .served-resources { + margin-top: 4em; + border-top: 1px solid gray; + padding-top: 1em; + } + .served-resources a { + padding-right: 2em; + } + </style> + + <div class="served-resources"> + <a href="stats/">/stats/</a> + <a href="graph/dpms">/graph/dpms</a> + <a href="graph/dpms/events">/graph/dpms/events</a> + <a href="monitor">/monitor (put)</a> + </div> + + </body> +</html> +''') + + +class Monitor(PrettyErrorHandler, cyclone.web.RequestHandler): def get(self): self.set_header('content-type', 'text/plain') self.write(getMonitorState()) def put(self): - body = self.request.body.strip() - if body in ['on', 'off']: - subprocess.check_call(['xset', 'dpms', 'force', body]) - self.set_status(204) - else: + body = self.request.body.decode('ascii').strip() + if body not in ['on', 'off']: raise NotImplementedError("body must be 'on' or 'off'") + d.ForceLevel(dpms.DPMSModeOff if body == 'off' else dpms.DPMSModeOn) + self.set_status(204) class Poller(object): def __init__(self): @@ -96,6 +125,8 @@ self.lastSent = state self.lastSentTime = now +verboseLogging(False) + masterGraph = PatchableGraph() poller = Poller()