changeset 53:0141467893bf

new xidle service Ignore-this: 25b08dbb9d16d98ddc53dc079e030248
author drewp@bigasterisk.com
date Wed, 09 Jan 2013 20:22:51 -0800
parents 875a37be1228
children 42411726a7ca
files service/xidle/pydeps service/xidle/xidle.py
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/xidle/pydeps	Wed Jan 09 20:22:51 2013 -0800
@@ -0,0 +1,5 @@
+PyXSS==2.1
+bottle==0.11.4
+gunicorn==0.17.2
+python-dateutil==2.1
+rdflib==3.2.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/xidle/xidle.py	Wed Jan 09 20:22:51 2013 -0800
@@ -0,0 +1,45 @@
+#!bin/python
+
+"""
+X server idle time is now available over http!
+"""
+
+from bottle import run, get, put, request, response
+import subprocess, sys, socket
+from rdflib import Namespace, URIRef, Literal
+
+# from http://bebop.bigasterisk.com/python/
+import xss
+# another option: http://thp.io/2007/09/x11-idle-time-and-focused-window-in.html
+
+DEV = Namespace("http://projects.bigasterisk.com/device/")
+ROOM = Namespace("http://projects.bigasterisk.com/room/")
+
+sys.path.append("/my/site/magma")
+from stategraph import StateGraph
+
+host = socket.gethostname()
+
+@get("/")
+def index():
+    xss.get_info() # fail if we can't get the display or something
+    return '''
+      Get the <a href="idle">X idle time</a> on %s.
+      <a href="graph">rdf graph</a> available.''' % host
+
+@get("/idle")
+def monitor():
+    return {"idleMs" : xss.get_info().idle}
+
+@get("/graph")
+def graph():
+    g = StateGraph(ctx=DEV['xidle/%s' % host])
+    g.add((URIRef("http://bigasterisk.com/host/%s/xidle" % host),
+           ROOM['idleTimeMs'],
+           Literal(xss.get_info().idle)))
+
+    response.set_header('Content-type', 'application/x-trig')
+    return g.asTrig()
+
+run(host="0.0.0.0", server='gunicorn', port=9107, quiet=True)
+