source: xplra/misc/autosavesit.py@ 97:28052c8e62c9

Last change on this file since 97:28052c8e62c9 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
RevLine 
[97]1#!/usr/bin/env python3
[84]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
[97]26 print("Connecting to X-Plane...")
[84]27
[88]28 while not xplane.isConnected:
29 try:
30 xplane.connect()
31 except:
[97]32 print("Connection failed, sleeping...")
[88]33 time.sleep(0.5)
34
[97]35 print("Connected to X-Plane")
[88]36
37 try:
38 while True:
[84]39 try:
[88]40 xplane.saveSituation(savePath)
[84]41 try:
[88]42 if os.path.exists(path):
43 os.rename(path, oldPath)
44 os.rename(newPath, path)
[84]45
[97]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))
[88]51 time.sleep(interval)
[97]52 except Exception as e:
53 print("Connection failed: " + str(e))
[88]54 try:
[84]55 xplane.disconnect()
[88]56 except:
57 pass
Note: See TracBrowser for help on using the repository browser.