Airport.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. import configparser
  3. import glob
  4. import os
  5. import sys
  6. from formats.SctEseFormat import SctEseFormat
  7. class Airport:
  8. def findGngData(data, path):
  9. if None == data.get('gngwildcard'):
  10. return None, None
  11. # find the newest ESE file
  12. files = glob.glob(os.path.join(path, data['gngwildcard'] + '.ese'))
  13. latestEse = max(files, key=os.path.getctime)
  14. # search for the corresponding SCT file
  15. latestSct = os.path.splitext(latestEse)[0] + '.sct'
  16. # check if the files exist
  17. if False == os.path.isfile(latestEse) or False == os.path.isfile(latestSct):
  18. return None, None
  19. return latestSct, latestEse
  20. def parsePlanning(self, planning):
  21. if None == planning.get('routes'):
  22. return []
  23. return planning['routes'].split(':')
  24. def __init__(self, filepath : str, icao : str):
  25. self.arrivalRoutes = {}
  26. config = configparser.ConfigParser()
  27. config.read(filepath)
  28. dataConfig = None
  29. planningConfig = None
  30. # search the required sections
  31. for key in config:
  32. if 'DATA' == key:
  33. dataConfig = config['DATA']
  34. elif 'PLANNING' == key:
  35. planningConfig = config['PLANNING']
  36. # find the GNG-file data
  37. sctFile, eseFile = Airport.findGngData(dataConfig, os.path.dirname(filepath))
  38. if None == sctFile or None == eseFile:
  39. sys.stderr.write('No GNG-files found')
  40. sys.exit(-1)
  41. # parse the planning information
  42. if None == planningConfig or False == self.parsePlanning(planningConfig):
  43. sys.stderr.write('No planning configuration found')
  44. sys.exit(-1)
  45. requiredArrivalRoutes = self.parsePlanning(planningConfig)
  46. if 0 == len(requiredArrivalRoutes):
  47. sys.stderr.write('No valid planning configuration found')
  48. sys.exit(-1)
  49. # parse the GNG data
  50. print('Used GNG-Data: ' + eseFile)
  51. self.gngData = SctEseFormat(sctFile, eseFile, icao, requiredArrivalRoutes)