comparison mcserver/mcserver.py @ 33:fe04ff3547c7

added more sophisticated testing
author gyorgyf
date Tue, 09 Jul 2013 16:30:47 +0100
parents cb57e554ae80
children 4455a77435b0 c0b34039917a
comparison
equal deleted inserted replaced
32:cb57e554ae80 33:fe04ff3547c7
65 65
66 # def index(self): 66 # def index(self):
67 # return str() 67 # return str()
68 68
69 @cp.expose 69 @cp.expose
70 def test(self):
71 print "Server test function accessed."
72 cp.log.error("Server test function accessed.")
73 return "Server: Test passed."
74
75 @cp.expose
70 def mood(self,x,y): 76 def mood(self,x,y):
71 print "Received coordinates", x,y, "\n" 77 print "Received coordinates", x,y
72 i = Input(x,y,self.age,self.dist) 78 i = Input(x,y,self.age,self.dist)
73 if i in self.inputs : 79 if i in self.inputs :
74 self.inputs[self.inputs.index(i)].inc() 80 self.inputs[self.inputs.index(i)].inc()
75 else : 81 else :
76 self.inputs.insert(0,i) 82 self.inputs.insert(0,i)
112 w = spopen(command,stdout=sp.PIPE,stderr=sp.PIPE,shell=True) 118 w = spopen(command,stdout=sp.PIPE,stderr=sp.PIPE,shell=True)
113 se = w.stderr.readlines() 119 se = w.stderr.readlines()
114 result = w.stdout.readlines() 120 result = w.stdout.readlines()
115 exitcode = w.wait() 121 exitcode = w.wait()
116 if not result : 122 if not result :
117 print "getProcessPid:: Unable to obtain process pid. (lsof returned nothing. exitcode: %s)" %str(exitcode) 123 print "getProcessPid:: Unable to obtain process pid. (lsof returned nothing. exitcode: %s) This is fine in most cases..." %str(exitcode)
118 return False 124 return False
119 import pprint 125 import pprint
120 pprint.pprint(result) 126 pprint.pprint(result)
121 127
122 # get heading: 128 # get heading:
170 cp.tree.mount(MoodConductor(),script_name="/moodconductor",config=CONFIG_FILE) 176 cp.tree.mount(MoodConductor(),script_name="/moodconductor",config=CONFIG_FILE)
171 port = int(cp.server.socket_port) 177 port = int(cp.server.socket_port)
172 ip = cp.server.socket_host 178 ip = cp.server.socket_host
173 print "Trying to bind: %(ip)s:%(port)s" %locals() 179 print "Trying to bind: %(ip)s:%(port)s" %locals()
174 getProcessPids(port,kill=True) 180 getProcessPids(port,kill=True)
181 print "Starting..."
175 cp.quickstart() 182 cp.quickstart()
176 183
177 if __name__ == "__main__": 184 if __name__ == "__main__":
178 main() 185 main()