Last change
on this file since 86:f7714df5165f was 84:d1b002aca97a, checked in by István Váradi <ivaradi@…>, 12 years ago |
Added a script to save the situation at certain intervals
|
|
File size:
1.5 KB
|
Rev | Line | |
---|
[84] | 1 | #!/usr/bin/env python
|
---|
| 2 | #
|
---|
| 3 | # Program to automatically save the situation at certain intervals
|
---|
| 4 |
|
---|
| 5 | from xplra import XPlane, ProtocolException
|
---|
| 6 |
|
---|
| 7 | import sys
|
---|
| 8 | import os
|
---|
| 9 | import time
|
---|
| 10 |
|
---|
| 11 | if __name__ == "__main__":
|
---|
| 12 | interval = float(sys.argv[1])
|
---|
| 13 | xplanePath = sys.argv[2]
|
---|
| 14 | name = sys.argv[3]
|
---|
| 15 |
|
---|
| 16 | newName = name + ".new.sit"
|
---|
| 17 | savePath = "output/situations/" + newName
|
---|
| 18 |
|
---|
| 19 | basePath = os.path.join(xplanePath, "Output", "situations", name)
|
---|
| 20 | path = basePath + ".sit"
|
---|
| 21 | newPath = basePath + ".new.sit"
|
---|
| 22 | oldPath = basePath + ".old.sit"
|
---|
| 23 |
|
---|
| 24 | xplane = XPlane()
|
---|
| 25 |
|
---|
| 26 | while True:
|
---|
| 27 | print "Connecting to X-Plane..."
|
---|
| 28 |
|
---|
| 29 | while not xplane.isConnected:
|
---|
| 30 | try:
|
---|
| 31 | xplane.connect()
|
---|
| 32 | except:
|
---|
| 33 | print "Connection failed, sleeping..."
|
---|
| 34 | time.sleep(0.5)
|
---|
| 35 |
|
---|
| 36 | print "Connected to X-Plane"
|
---|
| 37 |
|
---|
| 38 | try:
|
---|
| 39 | while True:
|
---|
| 40 | try:
|
---|
| 41 | xplane.saveSituation(savePath)
|
---|
| 42 | try:
|
---|
| 43 | if os.path.exists(path):
|
---|
| 44 | os.rename(path, oldPath)
|
---|
| 45 | os.rename(newPath, path)
|
---|
| 46 |
|
---|
| 47 | print "Situation saved at " + time.strftime("%H:%M:%S")
|
---|
| 48 | except OSError, e:
|
---|
| 49 | print "I/O error occured: " + str(e)
|
---|
| 50 | except ProtocolException, e:
|
---|
| 51 | print "Protocol error occured: " + str(e)
|
---|
| 52 | time.sleep(interval)
|
---|
| 53 | except Exception, e:
|
---|
| 54 | print "Connection failed: " + str(e)
|
---|
| 55 | xplane.disconnect()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.