Mercurial > code > home > repos > light9
annotate bin/webcontrol @ 568:aad3b84d8f33
checkpoint (patch and networking config)
Ignore-this: 7e3b8e6ad901ffb59fd657a53730ba9a
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Sat, 19 Jun 2010 21:47:30 +0000 |
parents | 8d6f6d8a4719 |
children | 46d319974176 |
rev | line source |
---|---|
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
1 #!/usr/bin/python |
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 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
25 def post(root, path, **args): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
26 return getPage(root.rstrip('/') + '/' + path.lstrip('/'), |
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): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
34 s = xmlrpclib.ServerProxy(networking.musicUrl()) |
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): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
42 s = xmlrpclib.ServerProxy(networking.musicUrl()) |
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): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
47 return post(networking.keyboardComposerUrl(), 'fadesub', |
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): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
52 return post(networking.keyboardComposerUrl(), 'fadesub', |
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 show = URIRef("http://light9.bigasterisk.com/show/dance2009") # ? |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
74 playList = graph.value(show, L9['playList']) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
75 songs = list(graph.items(playList)) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
76 out = [] |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
77 for song in songs: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
78 out.append( |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
79 T.form(method="post", action="playSong")[ |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
80 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
|
81 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
|
82 return out |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
83 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
84 @inlineCallbacks |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
85 def locateChild(self, ctx, segments): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
86 try: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
87 func = getattr(Commands, segments[0]) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
88 req = inevow.IRequest(ctx) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
89 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
|
90 try: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
91 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
|
92 **simpleArgDict) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
93 except KeyboardInterrupt: raise |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
94 except Exception, e: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
95 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
|
96 traceback.print_exc() |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
97 returnValue((url.here.up(). |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
98 add('status', str(e)). |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
99 add('error', 1), segments[1:])) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
100 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
101 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
|
102 #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
|
103 except AttributeError: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
104 pass |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
105 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
|
106 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
107 def child_icon(self, ctx): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
108 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
|
109 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
110 graph = showconfig.getGraph() |
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() |