Mercurial > code > home > repos > light9
annotate bin/attic/webcontrol @ 2450:a4052905ca7d default tip
notes about how rdfdb syncs, or should sync
author | drewp@bigasterisk.com |
---|---|
date | Mon, 03 Jun 2024 23:01:54 -0700 |
parents | 4556eebe5d73 |
children |
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 """ |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
9 import sys, xmlrpc.client, traceback |
514
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 |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
22 from urllib.parse import urlencode |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
23 |
1858 | 24 |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
25 # move to web lib |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
26 def post(url, **args): |
1858 | 27 return getPage(url, method='POST', postdata=urlencode(args)) |
514
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): |
1858 | 31 |
514
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): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
34 s = xmlrpc.client.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): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
42 s = xmlrpc.client.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'), |
1858 | 48 subname='scoop', |
49 level=.5, | |
50 secs=.5) | |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
51 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
52 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
53 def worklightsOff(graph): |
623
46d319974176
move networking settings to config.n3
drewp@bigasterisk.com
parents:
532
diff
changeset
|
54 return post(networking.keyboardComposer.path('fadesub'), |
1858 | 55 subname='scoop', |
56 level=0, | |
57 secs=.5) | |
514
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 @staticmethod |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
60 def dimmerSet(graph, dimmer, value): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
61 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
|
62 |
1858 | 63 |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
64 class Main(rend.Page): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
65 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
|
66 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
67 def __init__(self, graph): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
68 self.graph = graph |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
69 rend.Page.__init__(self) |
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_status(self, ctx, data): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
72 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
|
73 if ctx.arg('error'): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
74 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
|
75 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
|
76 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
77 def render_songButtons(self, ctx, data): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
78 playList = graph.value(show, L9['playList']) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
79 songs = list(graph.items(playList)) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
80 out = [] |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
81 for song in songs: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
82 out.append( |
1858 | 83 T.form(method="post", action="playSong") |
84 [T.input(type='hidden', name='songUri', value=song), | |
85 T.button(type='submit')[graph.label(song)]]) | |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
86 return out |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
87 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
88 @inlineCallbacks |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
89 def locateChild(self, ctx, segments): |
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 func = getattr(Commands, segments[0]) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
92 req = inevow.IRequest(ctx) |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
93 simpleArgDict = dict((k, v[0]) for k, v in list(req.args.items())) |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
94 try: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
95 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
|
96 **simpleArgDict) |
1858 | 97 except KeyboardInterrupt: |
98 raise | |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
99 except Exception as e: |
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
100 print("Error on command %s" % segments[0]) |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
101 traceback.print_exc() |
1858 | 102 returnValue((url.here.up().add('status', |
103 str(e)).add('error', | |
104 1), segments[1:])) | |
105 | |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
106 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
|
107 #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
|
108 except AttributeError: |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
109 pass |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
110 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
|
111 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
112 def child_icon(self, ctx): |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
113 return static.File("/usr/share/pyshared/elisa/plugins/poblesec/tango") |
1858 | 114 |
115 | |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
116 graph = showconfig.getGraph() |
649
84c0a3bf07ed
webcontrol remove hardcoded show
Drew Perttula <drewp@bigasterisk.com>
parents:
623
diff
changeset
|
117 show = showconfig.showUri() |
514
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
118 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
119 log.startLogging(sys.stdout) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
120 |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
121 reactor.listenTCP(9000, NevowSite(Main(graph))) |
a33519c49871
new bin/webcontrol web client for playing songs and adjusting lights
drewp@bigasterisk.com
parents:
diff
changeset
|
122 reactor.run() |