From bd7cbe91ed52fe97fe956cb57e303bc5bbbbd7e5 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Thu, 2 Sep 2021 19:43:34 +0200 Subject: [PATCH] add a configuration that parses all relevant airport data --- aman/config/Airport.py | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 aman/config/Airport.py diff --git a/aman/config/Airport.py b/aman/config/Airport.py new file mode 100644 index 0000000..21a9984 --- /dev/null +++ b/aman/config/Airport.py @@ -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)