annotate bin/effecteval @ 1030:efcb41c585fe

update networking for testing Ignore-this: 6200fdf23cb8e1d7db2ed3e8633f6688
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 26 May 2014 20:52:25 +0000
parents a38414bd3929
children b5ee7aa9341a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
1 #!bin/python
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
2 from run_local import log
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
3 from twisted.internet import reactor
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
4 from twisted.internet.defer import inlineCallbacks
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
5 import cyclone.web, cyclone.websocket, cyclone.httpclient
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
6 import sys, optparse, logging, subprocess, json, re
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
7 from rdflib import URIRef, RDF
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
8
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
9 sys.path.append(".")
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
10 from light9 import networking, showconfig, Submaster
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
11 from light9.rdfdb.syncedgraph import SyncedGraph
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
12 from light9.curvecalc.curve import Curve
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
13 from light9.namespaces import L9, DCTERMS
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
14
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
15 sys.path.append("/my/proj/homeauto/lib")
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
16 sys.path.append("/home/drewp/projects/homeauto/lib")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
17 from cycloneerr import PrettyErrorHandler
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
18
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
19 class EffectEdit(cyclone.web.RequestHandler):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
20 def get(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
21 self.write(open("light9/effecteval/effect.html").read())
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
22
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
23 class EffectData(cyclone.websocket.WebSocketHandler):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
24 """
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
25 stays alive for the life of the effect page
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
26 """
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
27 def connectionMade(self, *args, **kwargs):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
28 log.info("websocket opened")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
29 self.uri = URIRef(self.get_argument('uri'))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
30 self.sendMessage({'hello': repr(self)})
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
31
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
32 self.graph = self.settings.graph
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
33 self.graph.addHandler(self.updateClient)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
34
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
35 def updateClient(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
36 # todo: if client has dropped, abort and don't get any more
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
37 # graph updates
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
38 self.sendMessage({'code': self.graph.value(self.uri, L9['code'])})
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
39
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
40 def connectionLost(self, reason):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
41 log.info("websocket closed")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
42
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
43 def messageReceived(self, message):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
44 log.info("got message %s" % message)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
45 # write a patch back to the graph
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
46
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
47 def uriFromCode(s):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
48 # i thought this was something a graph could do with its namespace manager
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
49 if s.startswith('sub:'):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
50 return URIRef('http://light9.bigasterisk.com/show/dance2014/sub/' + s[4:])
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
51 if s.startswith('song1:'):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
52 return URIRef('http://ex/effect/song1/' + s[6:])
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
53 raise NotImplementedError
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
54
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
55 class EffectNode(object):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
56 def __init__(self, graph, uri):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
57 self.graph, self.uri = graph, uri
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
58
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
59 def eval(self, songTime):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
60 with self.graph.currentState(tripleFilter=(self.uri, L9['code'], None)) as g:
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
61 code = g.value(self.uri, L9['code'])
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
62 # consider http://waxeye.org/ for a parser that can be used in py and js
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
63 m = re.match(r'^out = sub\((.*?), intensity=(.*?)\)', code)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
64 if not m:
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
65 raise NotImplementedError
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
66 sub = uriFromCurie(m.group(1))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
67 intensityCurve = uriFromCurie(m.group(2))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
68
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
69 print vars()
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
70
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
71 def effectDmxDict(graph, effect, songTime):
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
72 subs = Submaster.get_global_submasters(graph)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
73
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
74 curve = URIRef("http://ex/effect/song1/opening")
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
75 c = Curve()
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
76 with graph.currentState(tripleFilter=(curve, None, None)) as g:
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
77 c.set_from_string(g.value(curve, L9['points']))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
78
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
79 with graph.currentState(tripleFilter=(effect, None, None)) as g:
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
80 print 'got code', g.value(effect, L9['code'])
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
81 en = EffectNode(graph, effect)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
82
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
83 en.eval(songTime)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
84
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
85 sub = subs.get_sub_by_uri(URIRef("http://light9.bigasterisk.com/show/dance2014/sub/stageleft"))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
86 level = c.eval(songTime)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
87 scaledSubs = [sub * level]
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
88
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
89 out = Submaster.sub_maxes(*scaledSubs)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
90 levels_dict = out.get_levels()
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
91 dmx = out.get_dmx_list()
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
92 return json.dumps(dmx)
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
93
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
94
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
95 class EffectEval(PrettyErrorHandler, cyclone.web.RequestHandler):
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
96 @inlineCallbacks
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
97 def get(self):
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
98 # return dmx dict for that effect
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
99 uri = URIRef(self.get_argument('uri'))
1027
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
100 response = yield cyclone.httpclient.fetch(
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
101 networking.musicPlayer.path('time'))
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
102 songTime = json.loads(response.body)['t']
a38414bd3929 hacking on effecteval
Drew Perttula <drewp@bigasterisk.com>
parents: 1019
diff changeset
103 self.write(effectDmxDict(self.settings.graph, uri, songTime))
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
104
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
105 class SongEffectsEval(PrettyErrorHandler, cyclone.web.RequestHandler):
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
106 def get(self):
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
107 song = URIRef(self.get_argument('song'))
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
108 effects = effectsForSong(self.settings.graph, song)
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
109 self.write(maxDict(effectDmxDict(e) for e in effects))
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
110 # return dmx dict for all effects in the song, already combined
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
111
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
112 class App(object):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
113 def __init__(self, show):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
114 self.show = show
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
115 self.graph = SyncedGraph("effectEval")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
116 SFH = cyclone.web.StaticFileHandler
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
117 self.cycloneApp = cyclone.web.Application(handlers=[
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
118 (r'/()', SFH,
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
119 {'path': 'light9/effecteval', 'default_filename': 'index.html'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
120 (r'/effect', EffectEdit),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
121 (r'/(websocket\.js)', SFH, {'path': 'light9/rdfdb/web/'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
122 (r'/(knockout-2\.2\.1\.js)', SFH, {'path': 'light9/subserver/'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
123 (r'/effect\.js', StaticCoffee, {'src': 'light9/effecteval/effect.coffee'}),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
124 (r'/effectData', EffectData),
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
125 (r'/static/(.*)', SFH, {'path': 'static/'}),
1019
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
126 (r'/effect/eval', EffectEval),
5939fce98fad notes for next step
drewp@bigasterisk.com
parents: 1018
diff changeset
127 (r'/songEffects/eval', SongEffectsEval),
1018
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
128 ], debug=True, graph=self.graph)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
129 #graph.initiallySynced.addCallback(
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
130
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
131 # see bin/subserver
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
132
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
133 class StaticCoffee(PrettyErrorHandler, cyclone.web.RequestHandler):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
134 def initialize(self, src):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
135 super(StaticCoffee, self).initialize()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
136 self.src = src
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
137 def get(self):
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
138 self.set_header('Content-Type', 'application/javascript')
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
139 self.write(subprocess.check_output([
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
140 '/usr/bin/coffee', '--compile', '--print', self.src]))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
141
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
142
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
143 if __name__ == "__main__":
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
144 parser = optparse.OptionParser()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
145 parser.add_option('--show',
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
146 help='show URI, like http://light9.bigasterisk.com/show/dance2008',
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
147 default=showconfig.showUri())
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
148 parser.add_option("-v", "--verbose", action="store_true",
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
149 help="logging.DEBUG")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
150 parser.add_option("--twistedlog", action="store_true",
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
151 help="twisted logging")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
152 (options, args) = parser.parse_args()
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
153
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
154 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
155
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
156 if not options.show:
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
157 raise ValueError("missing --show http://...")
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
158
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
159 app = App(URIRef(options.show))
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
160 if options.twistedlog:
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
161 from twisted.python import log as twlog
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
162 twlog.startLogging(sys.stderr)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
163 reactor.listenTCP(networking.effectEval.port, app.cycloneApp)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
164 log.info("listening on %s" % networking.effectEval.port)
e28a443bd153 initial effecteval that can propagate changes from the graph to a web page
drewp@bigasterisk.com
parents:
diff changeset
165 reactor.run()