annotate light8/dmxclient.py @ 206:851cf44cea40

rename clientid and allow it as an argument
author drewp
date Sun, 10 Apr 2005 15:13:48 +0000
parents 238eede02bf9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 """ module for clients to use for easy talking to the dmx
45b12307c695 Initial revision
drewp
parents:
diff changeset
2 server. sending levels is now a simple call to
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 dmxclient.outputlevels(..)
45b12307c695 Initial revision
drewp
parents:
diff changeset
4
45b12307c695 Initial revision
drewp
parents:
diff changeset
5 client id is formed from sys.argv[0] and the PID. """
45b12307c695 Initial revision
drewp
parents:
diff changeset
6
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 import xmlrpclib,os,sys,socket,time
198
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
8 from twisted.web.xmlrpc import Proxy
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
9 _dmx=None
45b12307c695 Initial revision
drewp
parents:
diff changeset
10
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 _id="%s-%s" % (sys.argv[0].replace('.py','').replace('./',''),os.getpid())
45b12307c695 Initial revision
drewp
parents:
diff changeset
12
206
851cf44cea40 rename clientid and allow it as an argument
drewp
parents: 198
diff changeset
13 def outputlevels(levellist,twisted=0,clientid=_id):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 """present a list of dmx channel levels, each scaled from
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 0..1. list can be any length- it will apply to the first len() dmx
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 channels.
45b12307c695 Initial revision
drewp
parents:
diff changeset
17
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 if the server is not found, outputlevels will block for a
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 second."""
45b12307c695 Initial revision
drewp
parents:
diff changeset
20
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 global _dmx,_id
45b12307c695 Initial revision
drewp
parents:
diff changeset
22
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 if _dmx is None:
167
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
24 host = os.getenv('DMXHOST', 'localhost')
198
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
25 url = "http://%s:8030" % host
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
26 if not twisted:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
27 _dmx=xmlrpclib.Server(url)
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
28 else:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
29 _dmx = Proxy(url)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
30
198
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
31 if not twisted:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
32 try:
206
851cf44cea40 rename clientid and allow it as an argument
drewp
parents: 198
diff changeset
33 _dmx.outputlevels(clientid,levellist)
198
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
34 except socket.error,e:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
35 print "dmx server error %s, waiting"%e
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
36 time.sleep(1)
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
37 except xmlrpclib.Fault,e:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
38 print "outputlevels had xml fault: %s" % e
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
39 time.sleep(1)
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
40 else:
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
41 def err(error):
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
42 print "dmx server error",error
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
43 time.sleep(1)
206
851cf44cea40 rename clientid and allow it as an argument
drewp
parents: 198
diff changeset
44 d = _dmx.callRemote('outputlevels',clientid,levellist)
198
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
45 d.addErrback(err)
238eede02bf9 supports using twisted/deferreds for the xmlrpc connection
drewp
parents: 167
diff changeset
46
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
47
167
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
48 dummy = os.getenv('DMXDUMMY')
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
49 if dummy:
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
50 print "dmxclient: DMX is in dummy mode."
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
51 def bogus(*args):
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
52 pass
79bc84310e80 changes from tonight's rehearsal:
dmcc
parents: 141
diff changeset
53 outputlevels = bogus