Files
@ 38c1e8c18215
Branch filter:
Location: light9/bin/webcontrol
38c1e8c18215
3.9 KiB
text/plain
rdfdb 0.20.0
Ignore-this: be378ce908baa1fcb0f8bfd9ea400114
Ignore-this: be378ce908baa1fcb0f8bfd9ea400114
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #!bin/python
"""
web UI for various commands that we might want to run from remote
computers and phones
todo:
disable buttons that don't make sense
"""
import sys, xmlrpc.client, traceback
from twisted.internet import reactor
from twisted.python import log
from twisted.python.util import sibpath
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web.client import getPage
from nevow.appserver import NevowSite
from nevow import rend, static, loaders, inevow, url, tags as T
from rdflib import URIRef
from louie.robustapply import robust_apply
sys.path.append(".")
from light9 import showconfig, networking
from light9.namespaces import L9
from urllib.parse import urlencode
# move to web lib
def post(url, **args):
return getPage(url, method='POST', postdata=urlencode(args))
class Commands(object):
@staticmethod
def playSong(graph, songUri):
s = xmlrpc.client.ServerProxy(networking.musicPlayer.url)
songPath = graph.value(URIRef(songUri), L9.showPath)
if songPath is None:
raise ValueError("unknown song %s" % songUri)
return s.playfile(songPath.encode('ascii'))
@staticmethod
def stopMusic(graph):
s = xmlrpc.client.ServerProxy(networking.musicPlayer.url)
return s.stop()
@staticmethod
def worklightsOn(graph):
return post(networking.keyboardComposer.path('fadesub'),
subname='scoop',
level=.5,
secs=.5)
@staticmethod
def worklightsOff(graph):
return post(networking.keyboardComposer.path('fadesub'),
subname='scoop',
level=0,
secs=.5)
@staticmethod
def dimmerSet(graph, dimmer, value):
raise NotImplementedError("subcomposer doesnt have an http port yet")
class Main(rend.Page):
docFactory = loaders.xmlfile(sibpath(__file__, "../light9/webcontrol.html"))
def __init__(self, graph):
self.graph = graph
rend.Page.__init__(self)
def render_status(self, ctx, data):
pic = T.img(src="icon/enabled.png")
if ctx.arg('error'):
pic = T.img(src="icon/warning.png")
return [pic, ctx.arg('status') or 'ready']
def render_songButtons(self, ctx, data):
playList = graph.value(show, L9['playList'])
songs = list(graph.items(playList))
out = []
for song in songs:
out.append(
T.form(method="post", action="playSong")
[T.input(type='hidden', name='songUri', value=song),
T.button(type='submit')[graph.label(song)]])
return out
@inlineCallbacks
def locateChild(self, ctx, segments):
try:
func = getattr(Commands, segments[0])
req = inevow.IRequest(ctx)
simpleArgDict = dict((k, v[0]) for k, v in list(req.args.items()))
try:
ret = yield robust_apply(func, func, self.graph,
**simpleArgDict)
except KeyboardInterrupt:
raise
except Exception as e:
print("Error on command %s" % segments[0])
traceback.print_exc()
returnValue((url.here.up().add('status',
str(e)).add('error',
1), segments[1:]))
returnValue((url.here.up().add('status', ret), segments[1:]))
#actually return the orig page, with a status message from the func
except AttributeError:
pass
returnValue(rend.Page.locateChild(self, ctx, segments))
def child_icon(self, ctx):
return static.File("/usr/share/pyshared/elisa/plugins/poblesec/tango")
graph = showconfig.getGraph()
show = showconfig.showUri()
log.startLogging(sys.stdout)
reactor.listenTCP(9000, NevowSite(Main(graph)))
reactor.run()
|