changeset 1521:15f296550447

start paintServer Ignore-this: 1cae4bcb98aed1c2c494adb92fbed2e5
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 15 Apr 2017 04:03:28 +0000
parents e77b063c0bde
children 69088fe2865e
files bin/homepage bin/homepageConfig bin/paintserver light9/networking.py light9/paint/__init__.py light9/paint/solve.py show/dance2016/networking.n3 show/dance2017/URI show/dance2017/networking.n3
diffstat 8 files changed, 130 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/bin/homepage	Wed Apr 12 09:12:56 2017 +0000
+++ b/bin/homepage	Sat Apr 15 04:03:28 2017 +0000
@@ -4,8 +4,7 @@
 ROOT=`dirname $0`/..
 ROOT=${ROOT:a}
 
-bin/homepageConfig > /tmp/light9_nginx_routes.conf
-
+bin/homepageConfig > /tmp/light9_nginx_routes.conf && \
 cat > $CONF <<EOF
 worker_processes 1;
 
--- a/bin/homepageConfig	Wed Apr 12 09:12:56 2017 +0000
+++ b/bin/homepageConfig	Sat Apr 15 04:03:28 2017 +0000
@@ -12,7 +12,10 @@
 graph = showconfig.getGraph()
 
 netHome = graph.value(showconfig.showUri(), L9['networking'])
-print "listen %s;" % splitport(urlparse(graph.value(netHome, L9['webServer'])).netloc)[1]
+webServer = graph.value(netHome, L9['webServer'])
+if not webServer:
+    raise ValueError('no %r :webServer' % netHome)
+print "listen %s;" % splitport(urlparse(webServer).netloc)[1]
 
 def location(path, server):
     print """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/paintserver	Sat Apr 15 04:03:28 2017 +0000
@@ -0,0 +1,71 @@
+#!bin/python
+
+from __future__ import division
+from run_local import log
+import json
+from twisted.internet import reactor
+from light9.greplin_cyclone import StatsForCyclone
+from light9.rdfdb.syncedgraph import SyncedGraph
+from light9 import networking, showconfig
+from greplin import scales
+import optparse, sys, logging
+import cyclone.web
+from rdflib import URIRef
+from light9.rdfdb import clientsession
+import light9.paint.solve
+from lib.cycloneerr import PrettyErrorHandler
+
+class Solve(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def post(self):
+        painting = json.loads(self.request.body)
+        reload(light9.paint.solve)
+        with self.settings.stats.solve.time():
+            out = light9.paint.solve.solve(painting)
+        self.write(json.dumps(out))
+
+class App(object):
+    def __init__(self, show, session):
+        self.show = show
+        self.session = session
+
+        self.graph = SyncedGraph(networking.rdfdb.url, "paintServer")
+        self.graph.initiallySynced.addCallback(self.launch)
+
+        self.stats = scales.collection('/',
+                                       scales.PmfStat('solve'),
+                                       )
+    def launch(self, *args):
+        self.cycloneApp = cyclone.web.Application(handlers=[
+            (r'/stats', StatsForCyclone),
+            (r'/solve', Solve),
+        ],
+                                                  debug=True,
+                                                  graph=self.graph,
+                                                  stats=self.stats)
+        reactor.listenTCP(networking.paintServer.port, self.cycloneApp)
+        log.info("listening on %s" % networking.paintServer.port)
+
+
+if __name__ == "__main__":
+    parser = optparse.OptionParser()
+    parser.add_option('--show',
+        help='show URI, like http://light9.bigasterisk.com/show/dance2008',
+                      default=showconfig.showUri())
+    parser.add_option("-v", "--verbose", action="store_true",
+                      help="logging.DEBUG")
+    parser.add_option("--twistedlog", action="store_true",
+                      help="twisted logging")
+    clientsession.add_option(parser)
+    (options, args) = parser.parse_args()
+    log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
+
+    if not options.show:
+        raise ValueError("missing --show http://...")
+        
+    session = clientsession.getUri('paint', options)
+
+    app = App(URIRef(options.show), session)
+    if options.twistedlog:
+        from twisted.python import log as twlog
+        twlog.startLogging(sys.stderr)
+    reactor.run()
--- a/light9/networking.py	Wed Apr 12 09:12:56 2017 +0000
+++ b/light9/networking.py	Sat Apr 15 04:03:28 2017 +0000
@@ -45,6 +45,7 @@
 keyboardComposer = ServiceAddress(L9['keyboardComposer'])
 musicPlayer = ServiceAddress(L9['musicPlayer'])
 oscDmxServer = ServiceAddress(L9['oscDmxServer'])
+paintServer = ServiceAddress(L9['paintServer'])
 picamserve = ServiceAddress(L9['picamserve'])
 rdfdb = ServiceAddress(L9['rdfdb'])
 subComposer = ServiceAddress(L9['subComposer'])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/paint/solve.py	Sat Apr 15 04:03:28 2017 +0000
@@ -0,0 +1,2 @@
+def solve(painting):
+    return 0
--- a/show/dance2016/networking.n3	Wed Apr 12 09:12:56 2017 +0000
+++ b/show/dance2016/networking.n3	Sat Apr 15 04:03:28 2017 +0000
@@ -4,21 +4,21 @@
 
 show:dance2016 :networking sh:netHome .
 sh:netHome
-  :webServer        <http://plus:8200/>;
-  :patchReceiverUpdateHost "plus";
-  :curveCalc        <http://plus:8201/>;
-  :collector        <http://plus:8202/>;
-  :collectorZmq     <http://plus:8203/>;
-  :effectEval       <http://plus:8204/>;
-  :effectSequencer  <http://plus:8213/>;
-  :keyboardComposer <http://plus:8205/>;
-  :musicPlayer      <http://plus:8206/>;
-  :oscDmxServer     <udp://plus:8207/>;
+  :webServer        <http://dash:8200/>;
+  :patchReceiverUpdateHost "dash";
+  :curveCalc        <http://dash:8201/>;
+  :collector        <http://dash:8202/>;
+  :collectorZmq     <http://dash:8203/>;
+  :effectEval       <http://dash:8204/>;
+  :effectSequencer  <http://dash:8213/>;
+  :keyboardComposer <http://dash:8205/>;
+  :musicPlayer      <http://dash:8206/>;
+  :oscDmxServer     <udp://dash:8207/>;
   :picamserve       <http://10.2.0.5:8208/>;
-  :rdfdb            <http://plus:8209/>;
-  :subComposer      <http://plus:8210/>;
-  :subServer        <http://plus:8211/>;
-  :vidref           <http://plus:8212/> .
+  :rdfdb            <http://dash:8209/>;
+  :subComposer      <http://dash:8210/>;
+  :subServer        <http://dash:8211/>;
+  :vidref           <http://dash:8212/> .
 
 :curveCalc        :urlPath "curveCalc" .
 :dmxServer        :urlPath "dmxServer" .
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/show/dance2017/URI	Sat Apr 15 04:03:28 2017 +0000
@@ -0,0 +1,1 @@
+http://light9.bigasterisk.com/show/dance2017
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/show/dance2017/networking.n3	Sat Apr 15 04:03:28 2017 +0000
@@ -0,0 +1,36 @@
+@prefix : <http://light9.bigasterisk.com/> .
+@prefix show: <http://light9.bigasterisk.com/show/> .
+@prefix sh: <http://light9.bigasterisk.com/show/dance2017/> .
+
+show:dance2017 :networking sh:netHome .
+sh:netHome
+  :webServer        <http://dash:8200/>;
+  :patchReceiverUpdateHost "dash";
+  :curveCalc        <http://dash:8201/>;
+  :collector        <http://dash:8202/>;
+  :collectorZmq     <http://dash:8203/>;
+  :effectEval       <http://dash:8204/>;
+  :effectSequencer  <http://dash:8213/>;
+  :keyboardComposer <http://dash:8205/>;
+  :musicPlayer      <http://dash:8206/>;
+  :oscDmxServer     <udp://dash:8207/>;
+  :paintServer      <http://dash:8213/>;
+  :picamserve       <http://10.2.0.5:8208/>;
+  :rdfdb            <http://dash:8209/>;
+  :subComposer      <http://dash:8210/>;
+  :subServer        <http://dash:8211/>;
+  :vidref           <http://dash:8212/> .
+
+:curveCalc        :urlPath "curveCalc" .
+:dmxServer        :urlPath "dmxServer" .
+:effectEval       :urlPath "effectEval" .
+:keyboardComposer :urlPath "keyboardComposer" .
+:musicPlayer      :urlPath "ascoltami" .
+:picamserve       :urlPath "picamserve" .
+:paintServer      :urlPath "paintServer" .
+:rdfdb            :urlPath "rdfdb" .
+:subComposer      :urlPath "subComposer" .
+:subServer        :urlPath "subServer" .
+:vidref           :urlPath "vidref" .
+:collector        :urlPath "collector" .
+:effectSequencer  :urlPath "effectSequencer" .
\ No newline at end of file