changeset 623:46d319974176

move networking settings to config.n3 Ignore-this: 42a6390f9354a171c4d43e1c65a551ca
author drewp@bigasterisk.com
date Wed, 15 Jun 2011 05:30:19 +0000
parents 9d5867bb16c4
children 9071cd1bb29c
files bin/ascoltami2 bin/curvecalc bin/dmxserver bin/kcclient bin/keyboardcomposer bin/lightsim bin/musicPad bin/musictime bin/wavecurve bin/webcontrol light9/dmxclient.py light9/networking.py light9/vidref/main.py
diffstat 13 files changed, 50 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/bin/ascoltami2	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/ascoltami2	Wed Jun 15 05:30:19 2011 +0000
@@ -42,7 +42,7 @@
 
     parser = optparse.OptionParser()
     parser.add_option('--show',
-        help='show URI, like http://light9.bigasterisk.com/show/dance2008')
+        help='show URI, like http://light9.bigasterisk.com/show/dance2008', default=showconfig.showUri())
     parser.add_option("-v", "--verbose", action="store_true",
                       help="logging.DEBUG")
     (options, args) = parser.parse_args()
@@ -54,5 +54,4 @@
             
     graph = showconfig.getGraph()
     app = App(graph, URIRef(options.show))
-    musicPort = networking.musicPort()
-    app.run(musicPort)
+    app.run(networking.musicPlayer.port)
--- a/bin/curvecalc	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/curvecalc	Wed Jun 15 05:30:19 2011 +0000
@@ -80,7 +80,7 @@
         
     def current_time(self):
         """return deferred which gets called with the current time"""
-        d = self.player.request("GET", networking.musicUrl() + "time")
+        d = self.player.request("GET", networking.musicPlayer.path("time"))
         d.addCallback(self._timeReturned)
         return d
 
@@ -96,7 +96,8 @@
     
     def seekplay_or_pause(self,t):
         d = self.player.request("POST",
-                                networking.musicUrl() + "seekPlayOrPause", bodyProducer=StringProducer(jsonlib.write({"t" : t})))
+                                networking.musicPlayer.path("seekPlayOrPause"),
+                                bodyProducer=StringProducer(jsonlib.write({"t" : t})))
 
 class Expr(object):
     """singleton, provides functions for use in subterm expressions,
--- a/bin/dmxserver	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/dmxserver	Wed Jun 15 05:30:19 2011 +0000
@@ -213,7 +213,7 @@
 if options.dummy:
     os.environ['DMXDUMMY'] = "1"
 
-port = networking.dmxServerPort()
+port = networking.dmxServer.port
 print "starting xmlrpc server on port %s" % port
 reactor.listenTCP(port,server.Site(XMLRPCServe(options)))
 reactor.run()
--- a/bin/kcclient	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/kcclient	Wed Jun 15 05:30:19 2011 +0000
@@ -13,7 +13,7 @@
 if len(sys.argv)>3:
     fadesecs = sys.argv[3]
 
-levelServer = Resource(networking.keyboardComposerUrl())
+levelServer = Resource(networking.keyboardComposer.url)
 levelServer.post('fadesub', subname=subname, level=level, secs=fadesecs)
 
 
--- a/bin/keyboardcomposer	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/keyboardcomposer	Wed Jun 15 05:30:19 2011 +0000
@@ -470,7 +470,7 @@
 
     import twisted.internet
     try:
-        reactor.listenTCP(networking.kcPort(),
+        reactor.listenTCP(networking.keyboardComposer.port,
                           server.Site(LevelServerHttp(kc.name_to_subtk)))
     except twisted.internet.error.CannotListenError, e:
         print "Can't (and won't!) start level server:"
--- a/bin/lightsim	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/lightsim	Wed Jun 15 05:30:19 2011 +0000
@@ -118,7 +118,7 @@
     window = Window(requiredImages(graph))
     window.show()
 
-    serv = Proxy(networking.dmxServerUrl())
+    serv = Proxy(networking.dmxServer.url)
     pollFreq = updatefreq.Updatefreq()
     LoopingCall(poll, graph, serv, pollFreq, window.glWidget).start(.05)
 
--- a/bin/musicPad	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/musicPad	Wed Jun 15 05:30:19 2011 +0000
@@ -4,7 +4,7 @@
 """
 import sys, wave, logging, os
 sys.path.append(".")
-from light9 import networking, showconfig
+from light9 import showconfig
 from light9.namespaces import L9
 from light9.ascoltami.playlist import Playlist
 logging.basicConfig(level=logging.INFO)
--- a/bin/musictime	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/musictime	Wed Jun 15 05:30:19 2011 +0000
@@ -42,7 +42,7 @@
 if __name__ == "__main__":
     from optparse import OptionParser
     parser = OptionParser()
-    parser.add_option("-u", "--url", default=light9.networking.musicUrl())
+    parser.add_option("-u", "--url", default=light9.networking.musicPlayer.url)
     options, args = parser.parse_args()
     
     root = tk.Tk()
--- a/bin/wavecurve	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/wavecurve	Wed Jun 15 05:30:19 2011 +0000
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import os, sys, optparse
+import optparse
 import run_local
 from light9.wavepoints import simp
 
--- a/bin/webcontrol	Wed Jun 15 05:30:00 2011 +0000
+++ b/bin/webcontrol	Wed Jun 15 05:30:19 2011 +0000
@@ -22,8 +22,8 @@
 from urllib import urlencode
 
 # move to web lib
-def post(root, path, **args):
-    return getPage(root.rstrip('/') + '/' + path.lstrip('/'),
+def post(url, **args):
+    return getPage(url,
                    method='POST',
                    postdata=urlencode(args))
 
@@ -31,7 +31,7 @@
 class Commands(object):
     @staticmethod
     def playSong(graph, songUri):
-        s = xmlrpclib.ServerProxy(networking.musicUrl())
+        s = xmlrpclib.ServerProxy(networking.musicPlayer.url)
         songPath = graph.value(URIRef(songUri), L9.showPath)
         if songPath is None:
             raise ValueError("unknown song %s" % songUri)
@@ -39,17 +39,17 @@
 
     @staticmethod
     def stopMusic(graph):
-        s = xmlrpclib.ServerProxy(networking.musicUrl())
+        s = xmlrpclib.ServerProxy(networking.musicPlayer.url)
         return s.stop()
 
     @staticmethod
     def worklightsOn(graph):
-        return post(networking.keyboardComposerUrl(), 'fadesub',
+        return post(networking.keyboardComposer.path('fadesub'),
                     subname='scoop', level=.5, secs=.5)
 
     @staticmethod
     def worklightsOff(graph):
-        return post(networking.keyboardComposerUrl(), 'fadesub',
+        return post(networking.keyboardComposer.path('fadesub'),
                     subname='scoop', level=0, secs=.5)
 
     @staticmethod
--- a/light9/dmxclient.py	Wed Jun 15 05:30:00 2011 +0000
+++ b/light9/dmxclient.py	Wed Jun 15 05:30:19 2011 +0000
@@ -23,7 +23,7 @@
     global _dmx, _id
 
     if _dmx is None:
-        url = networking.dmxServerUrl()
+        url = networking.dmxServer.url
         if not twisted:
             _dmx = xmlrpclib.Server(url)
         else:
--- a/light9/networking.py	Wed Jun 15 05:30:00 2011 +0000
+++ b/light9/networking.py	Wed Jun 15 05:30:19 2011 +0000
@@ -1,32 +1,37 @@
-import os
-from ConfigParser import SafeConfigParser
-# my intent was to pull these from a file in the LIGHT9_SHOW/ directory
-
+from urlparse import urlparse
+from urllib import splitport
+from showconfig import getGraph, showUri
+from namespaces import L9
 
-def dmxServerUrl():
-    #host = os.getenv('DMXHOST', 'localhost')
-    #url = "http://%s:8030" % host
-    return "http://plus:%s" % dmxServerPort()
+class ServiceAddress(object):
+    def __init__(self, service):
+        self.service = service
+
+    def _url(self):
+        graph = getGraph()
+        net = graph.value(showUri(), L9['networking'])
+        return graph.value(net, self.service)
 
-def dmxServerPort():
-    return 8030
-    
-def musicUrl():
-    # must have trailing slash!
-    return "http://django:%s/" % musicPort()
+    @property
+    def port(self):
+        _, netloc, _, _, _, _ = urlparse(self._url())
+        host, port = splitport(netloc)
+        return int(port)
 
-def musicPort():
-    return 8040
+    @property
+    def host(self):
+        _, netloc, _, _, _, _ = urlparse(self._url())
+        host, port = splitport(netloc)
+        return host
 
-def mpdServer():
-    """servername, port"""
-    return os.getenv('LIGHT9_MPD_SERVER', 'django'),6600
+    @property
+    def url(self):
+        return self._url()
 
-def kcPort():
-    return 8050
+    def path(self, more):
+        return self.url + more
 
-def kcServer():
-    return 'plus'
+dmxServer = ServiceAddress(L9['dmxServer'])
+musicPlayer = ServiceAddress(L9['musicPlayer'])
+keyboardComposer = ServiceAddress(L9['keyboardComposer'])
 
-def keyboardComposerUrl():
-    return "http://%s:%s" % (kcServer(), kcPort())
--- a/light9/vidref/main.py	Wed Jun 15 05:30:00 2011 +0000
+++ b/light9/vidref/main.py	Wed Jun 15 05:30:19 2011 +0000
@@ -33,7 +33,7 @@
         end of a song)
         """
         self.period = period
-        self.musicResource = restkit.Resource(networking.musicUrl())
+        self.musicResource = restkit.Resource(networking.musicPlayer.url)
         t = Thread(target=self._timeUpdate)
         t.setDaemon(True)
         t.start()