# HG changeset patch # User drewp@bigasterisk.com # Date 2011-06-15 05:30:19 # Node ID 46d319974176dd61444a8288b3e41a755db07014 # Parent 9d5867bb16c438fe606c482748119874a04e172c move networking settings to config.n3 Ignore-this: 42a6390f9354a171c4d43e1c65a551ca diff --git a/bin/ascoltami2 b/bin/ascoltami2 --- a/bin/ascoltami2 +++ b/bin/ascoltami2 @@ -42,7 +42,7 @@ if __name__ == "__main__": 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 @@ if __name__ == "__main__": graph = showconfig.getGraph() app = App(graph, URIRef(options.show)) - musicPort = networking.musicPort() - app.run(musicPort) + app.run(networking.musicPlayer.port) diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -80,7 +80,7 @@ class Music: 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 @@ class Music: 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, diff --git a/bin/dmxserver b/bin/dmxserver --- a/bin/dmxserver +++ b/bin/dmxserver @@ -213,7 +213,7 @@ print options 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() diff --git a/bin/kcclient b/bin/kcclient --- a/bin/kcclient +++ b/bin/kcclient @@ -13,7 +13,7 @@ fadesecs = '0' 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) diff --git a/bin/keyboardcomposer b/bin/keyboardcomposer --- a/bin/keyboardcomposer +++ b/bin/keyboardcomposer @@ -470,7 +470,7 @@ if __name__ == "__main__": 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:" diff --git a/bin/lightsim b/bin/lightsim --- a/bin/lightsim +++ b/bin/lightsim @@ -118,7 +118,7 @@ if __name__ == '__main__': 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) diff --git a/bin/musicPad b/bin/musicPad --- a/bin/musicPad +++ b/bin/musicPad @@ -4,7 +4,7 @@ rewrite all the songs with silence at th """ 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) diff --git a/bin/musictime b/bin/musictime --- a/bin/musictime +++ b/bin/musictime @@ -42,7 +42,7 @@ class MusicTimeTk(tk.Frame, MusicTime): 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() diff --git a/bin/wavecurve b/bin/wavecurve --- a/bin/wavecurve +++ b/bin/wavecurve @@ -1,5 +1,5 @@ #!/usr/bin/env python -import os, sys, optparse +import optparse import run_local from light9.wavepoints import simp diff --git a/bin/webcontrol b/bin/webcontrol --- a/bin/webcontrol +++ b/bin/webcontrol @@ -22,8 +22,8 @@ from light9.namespaces import L9 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 @@ def post(root, path, **args): 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 @@ class Commands(object): @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 diff --git a/light9/dmxclient.py b/light9/dmxclient.py --- a/light9/dmxclient.py +++ b/light9/dmxclient.py @@ -23,7 +23,7 @@ def outputlevels(levellist,twisted=0,cli global _dmx, _id if _dmx is None: - url = networking.dmxServerUrl() + url = networking.dmxServer.url if not twisted: _dmx = xmlrpclib.Server(url) else: diff --git a/light9/networking.py b/light9/networking.py --- a/light9/networking.py +++ b/light9/networking.py @@ -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()) diff --git a/light9/vidref/main.py b/light9/vidref/main.py --- a/light9/vidref/main.py +++ b/light9/vidref/main.py @@ -33,7 +33,7 @@ class MusicTime(object): 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()