Mercurial > code > home > repos > light9
annotate bin/webcontrol @ 1407:f766f82b8513
checkpoint show data
Ignore-this: 55fda887863be2f89db5a7db88404f41
author | drewp@bigasterisk.com |
---|---|
date | Mon, 15 Jun 2015 22:34:59 +0000 |
parents | b5efddd80dad |
children | 7772cc48e016 |
rev | line source |
---|---|
729
b5efddd80dad
update more shbang lines
Drew Perttula <drewp@bigasterisk.com>
parents:
649
diff
changeset
|
1 #!bin/python |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
2 """ |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
3 web UI for various commands that we might want to run from remote |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
4 computers and phones |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
5 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
6 todo: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
7 disable buttons that don't make sense |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
8 """ |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
9 import sys, xmlrpclib, traceback |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
10 from twisted.internet import reactor |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
11 from twisted.python import log |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
12 from twisted.python.util import sibpath |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
13 from twisted.internet.defer import inlineCallbacks, returnValue |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
14 from twisted.web.client import getPage |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
15 from nevow.appserver import NevowSite |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
16 from nevow import rend, static, loaders, inevow, url, tags as T |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
17 from rdflib import URIRef |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
18 from louie.robustapply import robust_apply |
532
8d6f6d8a4719
clean up music client calls from curvecalc and musictime
drewp@bigasterisk.com
parents:
514
diff
changeset
|
19 sys.path.append(".") |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
20 from light9 import showconfig, networking |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
21 from light9.namespaces import L9 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
22 from urllib import urlencode |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
23 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
24 # move to web lib |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
25 def post(url, **args): |
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
26 return getPage(url, |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
27 method='POST', |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
28 postdata=urlencode(args)) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
29 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
30 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
31 class Commands(object): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
32 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
33 def playSong(graph, songUri): |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
34 s = xmlrpclib.ServerProxy(networking.musicPlayer.url) |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
35 songPath = graph.value(URIRef(songUri), L9.showPath) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
36 if songPath is None: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
37 raise ValueError("unknown song %s" % songUri) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
38 return s.playfile(songPath.encode('ascii')) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
39 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
40 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
41 def stopMusic(graph): |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
42 s = xmlrpclib.ServerProxy(networking.musicPlayer.url) |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
43 return s.stop() |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
44 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
45 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
46 def worklightsOn(graph): |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
47 return post(networking.keyboardComposer.path('fadesub'), |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
48 subname='scoop', level=.5, secs=.5) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
49 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
50 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
51 def worklightsOff(graph): |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
52 return post(networking.keyboardComposer.path('fadesub'), |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
53 subname='scoop', level=0, secs=.5) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
54 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
55 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
56 def dimmerSet(graph, dimmer, value): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
57 raise NotImplementedError("subcomposer doesnt have an http port yet") |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
58 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
59 class Main(rend.Page): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
60 docFactory = loaders.xmlfile(sibpath(__file__, "../light9/webcontrol.html")) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
61 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
62 def __init__(self, graph): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
63 self.graph = graph |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
64 rend.Page.__init__(self) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
65 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
66 def render_status(self, ctx, data): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
67 pic = T.img(src="icon/enabled.png") |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
68 if ctx.arg('error'): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
69 pic = T.img(src="icon/warning.png") |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
70 return [pic, ctx.arg('status') or 'ready'] |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
71 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
72 def render_songButtons(self, ctx, data): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
73 playList = graph.value(show, L9['playList']) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
74 songs = list(graph.items(playList)) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
75 out = [] |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
76 for song in songs: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
77 out.append( |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
78 T.form(method="post", action="playSong")[ |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
79 T.input(type='hidden', name='songUri', value=song), |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
80 T.button(type='submit')[graph.label(song)]]) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
81 return out |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
82 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
83 @inlineCallbacks |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
84 def locateChild(self, ctx, segments): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
85 try: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
86 func = getattr(Commands, segments[0]) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
87 req = inevow.IRequest(ctx) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
88 simpleArgDict = dict((k, v[0]) for k,v in req.args.items()) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
89 try: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
90 ret = yield robust_apply(func, func, self.graph, |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
91 **simpleArgDict) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
92 except KeyboardInterrupt: raise |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
93 except Exception, e: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
94 print "Error on command %s" % segments[0] |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
95 traceback.print_exc() |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
96 returnValue((url.here.up(). |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
97 add('status', str(e)). |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
98 add('error', 1), segments[1:])) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
99 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
100 returnValue((url.here.up().add('status', ret), segments[1:])) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
101 #actually return the orig page, with a status message from the func |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
102 except AttributeError: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
103 pass |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
104 returnValue(rend.Page.locateChild(self, ctx, segments)) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
105 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
106 def child_icon(self, ctx): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
107 return static.File("/usr/share/pyshared/elisa/plugins/poblesec/tango") |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
108 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
109 graph = showconfig.getGraph() |
649
84c0a3bf07ed
webcontrol remove hardcoded show
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
110 show = showconfig.showUri() |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
111 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
112 log.startLogging(sys.stdout) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
113 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
114 reactor.listenTCP(9000, NevowSite(Main(graph))) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
115 reactor.run() |