annotate bin/webcontrol @ 529:1156d3531327

new ascoltami2, using gstreamer Ignore-this: 77e59ba6ec17b86343c93c24ac38aa44
author drewp@bigasterisk.com
date Fri, 11 Jun 2010 07:14:18 +0000
parents a33519c49871
children 8d6f6d8a4719
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
19 from light9 import showconfig, networking
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
20 from light9.namespaces import L9
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
21 from urllib import urlencode
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
22
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
23 # move to web lib
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
24 def post(root, path, **args):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
25 return getPage(root.rstrip('/') + '/' + path.lstrip('/'),
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
26 method='POST',
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
27 postdata=urlencode(args))
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
28
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 class Commands(object):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
31 @staticmethod
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
32 def playSong(graph, songUri):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
33 s = xmlrpclib.ServerProxy(networking.musicUrl())
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
34 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
35 if songPath is None:
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
36 raise ValueError("unknown song %s" % songUri)
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
37 return s.playfile(songPath.encode('ascii'))
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
38
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
39 @staticmethod
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
40 def stopMusic(graph):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
41 s = xmlrpclib.ServerProxy(networking.musicUrl())
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
42 return s.stop()
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
43
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
44 @staticmethod
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
45 def worklightsOn(graph):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
46 return post(networking.keyboardComposerUrl(), 'fadesub',
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
47 subname='scoop', level=.5, secs=.5)
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
48
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
49 @staticmethod
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
50 def worklightsOff(graph):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
51 return post(networking.keyboardComposerUrl(), 'fadesub',
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
52 subname='scoop', level=0, secs=.5)
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
53
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
54 @staticmethod
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
55 def dimmerSet(graph, dimmer, value):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
56 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
57
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
58 class Main(rend.Page):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
59 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
60
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
61 def __init__(self, graph):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
62 self.graph = graph
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
63 rend.Page.__init__(self)
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
64
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
65 def render_status(self, ctx, data):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
66 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
67 if ctx.arg('error'):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
68 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
69 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
70
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
71 def render_songButtons(self, ctx, data):
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
72 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
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()
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
110
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
111 log.startLogging(sys.stdout)
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
112
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
113 reactor.listenTCP(9000, NevowSite(Main(graph)))
a33519c49871 new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff changeset
114 reactor.run()