|
@@ -0,0 +1,98 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+
|
|
|
+import configparser
|
|
|
+import glob
|
|
|
+import os
|
|
|
+import sys
|
|
|
+
|
|
|
+from formats.SctEseFormat import SctEseFormat
|
|
|
+
|
|
|
+class Airport:
|
|
|
+ def parseAirport(self, airport):
|
|
|
+ if None == airport.get('runways'):
|
|
|
+ return False
|
|
|
+ self.runways = airport['runways'].split(':')
|
|
|
+ return True
|
|
|
+
|
|
|
+ def findGngData(data, path):
|
|
|
+ if None == data.get('gngwildcard'):
|
|
|
+ return None, None
|
|
|
+
|
|
|
+ # find the newest ESE file
|
|
|
+ files = glob.glob(os.path.join(path, data['gngwildcard'] + '.ese'))
|
|
|
+ latestEse = max(files, key=os.path.getctime)
|
|
|
+
|
|
|
+ # search for the corresponding SCT file
|
|
|
+ latestSct = os.path.splitext(latestEse)[0] + '.sct'
|
|
|
+
|
|
|
+ # check if the files exist
|
|
|
+ if False == os.path.isfile(latestEse) or False == os.path.isfile(latestSct):
|
|
|
+ return None, None
|
|
|
+
|
|
|
+ return latestSct, latestEse
|
|
|
+
|
|
|
+ def parsePlanning(self, planning):
|
|
|
+ for key in planning:
|
|
|
+ # check if the runways match
|
|
|
+ rwy = key.upper()
|
|
|
+ if rwy not in self.runways:
|
|
|
+ sys.stderr.write('Unable to find ' + rwy + ' in defined runways')
|
|
|
+ return False
|
|
|
+
|
|
|
+ # check if arrivals are defined
|
|
|
+ arrivals = planning[key].split(':')
|
|
|
+ if 0 == len(arrivals):
|
|
|
+ sys.stderr.write('No arrival routes for ' + rwy)
|
|
|
+ return False
|
|
|
+
|
|
|
+ # assign the arrival routes to the runways
|
|
|
+ self.arrivalRoutes[rwy] = arrivals
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
+ def __init__(self, filepath : str, icao : str):
|
|
|
+ self.runways = []
|
|
|
+ self.arrivalRoutes = {}
|
|
|
+
|
|
|
+ config = configparser.ConfigParser()
|
|
|
+ config.read(filepath)
|
|
|
+
|
|
|
+ dataConfig = None
|
|
|
+ airportConfig = None
|
|
|
+ planningConfig = None
|
|
|
+
|
|
|
+ # search the required sections
|
|
|
+ for key in config:
|
|
|
+ if 'DATA' == key:
|
|
|
+ dataConfig = config['DATA']
|
|
|
+ elif 'AIRPORT' == key:
|
|
|
+ airportConfig = config['AIRPORT']
|
|
|
+ elif 'PLANNING' == key:
|
|
|
+ planningConfig = config['PLANNING']
|
|
|
+
|
|
|
+ # find the GNG-file data
|
|
|
+ sctFile, eseFile = Airport.findGngData(dataConfig, os.path.dirname(filepath))
|
|
|
+ if None == sctFile or None == eseFile:
|
|
|
+ sys.stderr.write('No GNG-files found')
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ # parse the airport information
|
|
|
+ if None == airportConfig or False == self.parseAirport(airportConfig):
|
|
|
+ sys.stderr.write('No or no valid airport configuration found')
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ # parse the planning information
|
|
|
+ if None == planningConfig or False == self.parsePlanning(planningConfig):
|
|
|
+ sys.stderr.write('No or no valid planning configuration found')
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ # get all required arrival routes and avoid duplicates
|
|
|
+ requiredArrivalRoutes = []
|
|
|
+ for rwy in self.arrivalRoutes:
|
|
|
+ for arrival in self.arrivalRoutes[rwy]:
|
|
|
+ if arrival not in requiredArrivalRoutes:
|
|
|
+ requiredArrivalRoutes.append(arrival)
|
|
|
+
|
|
|
+ # parse the GNG data
|
|
|
+ print('Used GNG-Data: ' + eseFile)
|
|
|
+ self.gngData = SctEseFormat(sctFile, eseFile, icao, requiredArrivalRoutes)
|