Changeset 97:28052c8e62c9 in xplra for misc
- Timestamp:
- 06/10/19 08:37:18 (5 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- misc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/autosavesit.py
r88 r97 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 # 3 3 # Program to automatically save the situation at certain intervals … … 24 24 xplane = XPlane() 25 25 26 print "Connecting to X-Plane..."26 print("Connecting to X-Plane...") 27 27 28 28 while not xplane.isConnected: … … 30 30 xplane.connect() 31 31 except: 32 print "Connection failed, sleeping..."32 print("Connection failed, sleeping...") 33 33 time.sleep(0.5) 34 34 35 print "Connected to X-Plane"35 print("Connected to X-Plane") 36 36 37 37 try: … … 44 44 os.rename(newPath, path) 45 45 46 print "Situation saved at " + time.strftime("%H:%M:%S")47 except OSError ,e:48 print "I/O error occured: " + str(e)49 except ProtocolException ,e:50 print "Protocol error occured: " + str(e)46 print("Situation saved at " + time.strftime("%H:%M:%S")) 47 except OSError as e: 48 print("I/O error occured: " + str(e)) 49 except ProtocolException as e: 50 print("Protocol error occured: " + str(e)) 51 51 time.sleep(interval) 52 except Exception ,e:53 print "Connection failed: " + str(e)52 except Exception as e: 53 print("Connection failed: " + str(e)) 54 54 try: 55 55 xplane.disconnect() -
misc/client.py
r45 r97 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 3 3 import sys … … 54 54 - the remainder of the argument list.""" 55 55 if len(words)<2: 56 print >> sys.stderr, "Missing parameters"56 print("Missing parameters", file=sys.stderr) 57 57 return None 58 58 … … 62 62 type = words[1] 63 63 if type not in CLI._types: 64 print >> sys.stderr, "Invalid type"64 print("Invalid type", file=sys.stderr) 65 65 return None 66 66 … … 69 69 if type in ["ia", "fa", "ba", "s"]: 70 70 if len(words)<4: 71 print >> sys.stderr, "Missing parameters"71 print("Missing parameters", file=sys.stderr) 72 72 return None 73 73 length = int(words[2]) … … 80 80 def _packLength(x): 81 81 """Pack the given integer as a variable-length value.""" 82 s = ""82 s = bytes() 83 83 while True: 84 84 y = x&0x7f … … 92 92 def _packString(s): 93 93 """Pack the given string.""" 94 return CLI._packLength(len(s)) + s94 return CLI._packLength(len(s)) + bytes(s, "utf-8") 95 95 96 96 def __init__(self, stream): … … 111 111 """Handle uhandled commands""" 112 112 if line=="EOF": 113 print 113 print() 114 114 return True 115 115 else: … … 135 135 result = self._readU8() 136 136 if result==0: 137 print self._readValue(type)137 print(self._readValue(type)) 138 138 else: 139 print >> sys.stderr, "Error code:", result139 print("Error code:", result, file=sys.stderr) 140 140 141 141 def do_set(self, args): … … 143 143 words = self._splitArgs(args) 144 144 if len(words)<3: 145 print >> sys.stderr, "Missing parameters"145 print("Missing parameters", file=sys.stderr) 146 146 return False 147 147 … … 150 150 type = words[1] 151 151 if type not in self._types: 152 print >> sys.stderr, "Invalid type"152 print("Invalid type", file=sys.stderr) 153 153 return False 154 154 … … 173 173 result = self._readU8() 174 174 if result!=0: 175 print >> sys.stderr, "Error code:", result175 print("Error code:", result, file=sys.stderr) 176 176 177 177 def do_multiget(self, args): … … 204 204 for (_, type, _, _) in specs: 205 205 value = self._readValue(type) 206 print value206 print(value) 207 207 elif result==0x02: 208 208 index = self._readU32() 209 print >> sys.stderr, "Invalid dataref at #%d" % (index,)209 print("Invalid dataref at #%d" % (index,), file=sys.stderr) 210 210 else: 211 print >> sys.stderr, "Error code:", result211 print("Error code:", result, file=sys.stderr) 212 212 213 213 def do_multiset(self, args): … … 223 223 words = result[1] 224 224 if not words: 225 print >> sys.stderr, "Missing argument"225 print("Missing argument", file=sys.stderr) 226 226 return False 227 227 specs.append(result[0]) … … 246 246 if result==0x02: 247 247 index = self._readU32() 248 print >> sys.stderr, "Invalid dataref at #%d" % (index,)248 print("Invalid dataref at #%d" % (index,), file=sys.stderr) 249 249 elif result!=0: 250 print >> sys.stderr, "Error code:", result250 print("Error code:", result, file=sys.stderr) 251 251 252 252 def do_reg_multiget(self, args): … … 280 280 self._multiGets[id] = \ 281 281 [type for (name, type, length, offset) in specs] 282 print "ID:", id282 print("ID:", id) 283 283 else: 284 print >> sys.stderr, "Error code:", result284 print("Error code:", result, file=sys.stderr) 285 285 286 286 def do_unreg_multiget(self, args): … … 288 288 words = self._splitArgs(args) 289 289 if len(words)<1: 290 print >> sys.stderr, "Missing parameter"290 print("Missing parameter", file=sys.stderr) 291 291 return False 292 292 … … 299 299 result = self._readU8() 300 300 if result!=0: 301 print >> sys.stderr, "Error code:", result301 print("Error code:", result, file=sys.stderr) 302 302 303 303 if id in self._multiGets: … … 308 308 words = self._splitArgs(args) 309 309 if len(words)<1: 310 print >> sys.stderr, "Missing parameter"310 print("Missing parameter", file=sys.stderr) 311 311 return False 312 312 313 313 id = int(words[0]) 314 314 if id not in self._multiGets: 315 print >> sys.stderr, "Invalid ID"315 print("Invalid ID", file=sys.stderr) 316 316 return False 317 317 … … 324 324 for type in self._multiGets[id]: 325 325 value = self._readValue(type) 326 print value326 print(value) 327 327 elif result==0x02: 328 328 index = self._readU32() 329 print >> sys.stderr, "Invalid dataref at #%d" % (index,)329 print("Invalid dataref at #%d" % (index,), file=sys.stderr) 330 330 else: 331 print >> sys.stderr, "Error code:", result331 print("Error code:", result, file=sys.stderr) 332 332 333 333 def do_reg_multiset(self, args): … … 361 361 self._multiSets[id] = \ 362 362 [(type, length) for (name, type, length, offset) in specs] 363 print "ID:", id363 print("ID:", id) 364 364 else: 365 print >> sys.stderr, "Error code:", result365 print("Error code:", result, file=sys.stderr) 366 366 367 367 def do_unreg_multiset(self, args): … … 369 369 words = self._splitArgs(args) 370 370 if len(words)<1: 371 print >> sys.stderr, "Missing parameter"371 print("Missing parameter", file=sys.stderr) 372 372 return False 373 373 … … 380 380 result = self._readU8() 381 381 if result!=0: 382 print >> sys.stderr, "Error code:", result382 print("Error code:", result, file=sys.stderr) 383 383 384 384 if id in self._multiSets: … … 389 389 words = self._splitArgs(args) 390 390 if len(words)<1: 391 print >> sys.stderr, "Missing parameter"391 print("Missing parameter", file=sys.stderr) 392 392 return False 393 393 394 394 id = int(words[0]) 395 395 if id not in self._multiSets: 396 print >> sys.stderr, "Invalid ID"396 print("Invalid ID", file=sys.stderr) 397 397 return False 398 398 … … 400 400 types = self._multiSets[id] 401 401 if len(words)<len(types): 402 print >> sys.stderr, "Missing parameter"402 print("Missing parameter", file=sys.stderr) 403 403 return False 404 404 … … 413 413 if result==0x02: 414 414 index = self._readU32() 415 print >> sys.stderr, "Invalid dataref at #%d" % (index,)415 print("Invalid dataref at #%d" % (index,), file=sys.stderr) 416 416 elif result!=0: 417 print >> sys.stderr, "Error code:", result417 print("Error code:", result, file=sys.stderr) 418 418 419 419 def do_show_message(self, args): 420 420 words = self._splitArgs(args) 421 421 if len(words)<2: 422 print >> sys.stderr, "Missing parameters"422 print("Missing parameters", file=sys.stderr) 423 423 return False 424 424 … … 433 433 result = self._readU8() 434 434 if result!=0: 435 print >> sys.stderr, "Error code:", result435 print("Error code:", result, file=sys.stderr) 436 436 437 437 def do_reload(self, args): … … 441 441 result = self._readU8() 442 442 if result!=0: 443 print >> sys.stderr, "Error code:", result443 print("Error code:", result, file=sys.stderr) 444 444 445 445 def do_register_hotkeys(self, args): 446 446 words = self._splitArgs(args) 447 447 if not words: 448 print >> sys.stderr, "Missing parameters"448 print("Missing parameters", file=sys.stderr) 449 449 return False 450 450 … … 457 457 result = self._readU8() 458 458 if result!=0: 459 print >> sys.stderr, "Error code:", result459 print("Error code:", result, file=sys.stderr) 460 460 461 461 def do_query_hotkeys(self, args): … … 469 469 for i in range(0, length): 470 470 values.append(self._readU8()) 471 print values471 print(values) 472 472 else: 473 print >> sys.stderr, "Error code:", result473 print("Error code:", result, file=sys.stderr) 474 474 475 475 def do_unregister_hotkeys(self, args): … … 479 479 result = self._readU8() 480 480 if result!=0: 481 print >> sys.stderr, "Error code:", result481 print("Error code:", result, file=sys.stderr) 482 482 483 483 def _writeU8(self, x): … … 568 568 length = self._readS32() 569 569 if length>8192: 570 print "Very big length:", length570 print("Very big length:", length) 571 571 return None 572 572 elif length>0: … … 622 622 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 623 623 s.connect("/tmp/xplra-" + os.environ["LOGNAME"]) 624 CLI(s.makefile( )).cmdloop()624 CLI(s.makefile("rwb")).cmdloop()
Note:
See TracChangeset
for help on using the changeset viewer.