source: xplra/misc/autosavesit.py@ 114:0e60b2a26b42

Last change on this file since 114:0e60b2a26b42 was 97:28052c8e62c9, checked in by István Váradi <ivaradi@…>, 5 years ago

Some helper scripts are ported to Python 3

  • Property exe set to *
File size: 1.5 KB
Line 
1#!/usr/bin/env python3
2#
3# Program to automatically save the situation at certain intervals
4
5from xplra import XPlane, ProtocolException
6
7import sys
8import os
9import time
10
11if __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 as e:
48 print("I/O error occured: " + str(e))
49 except ProtocolException as e:
50 print("Protocol error occured: " + str(e))
51 time.sleep(interval)
52 except Exception as 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.