Line | |
---|
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 | print "Connecting to X-Plane..."
|
---|
27 |
|
---|
28 | while not xplane.isConnected:
|
---|
29 | try:
|
---|
30 | xplane.connect()
|
---|
31 | except:
|
---|
32 | print "Connection failed, sleeping..."
|
---|
33 | time.sleep(0.5)
|
---|
34 |
|
---|
35 | print "Connected to X-Plane"
|
---|
36 |
|
---|
37 | try:
|
---|
38 | while True:
|
---|
39 | try:
|
---|
40 | xplane.saveSituation(savePath)
|
---|
41 | try:
|
---|
42 | if os.path.exists(path):
|
---|
43 | os.rename(path, oldPath)
|
---|
44 | os.rename(newPath, path)
|
---|
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)
|
---|
51 | time.sleep(interval)
|
---|
52 | except Exception, e:
|
---|
53 | print "Connection failed: " + str(e)
|
---|
54 | try:
|
---|
55 | xplane.disconnect()
|
---|
56 | except:
|
---|
57 | pass
|
---|
Note:
See
TracBrowser
for help on using the repository browser.