From 19d4f68a8a080646460430253434fc513aea3ebd Mon Sep 17 00:00:00 2001 From: Calvin Ng Date: Tue, 9 Feb 2021 19:23:43 -0800 Subject: [PATCH] Make it a bit easier to debug when airlines= is malformed --- final/AS/HKG/source/VHHH_PC.txt | 1 + tools/expand.py | 45 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/final/AS/HKG/source/VHHH_PC.txt b/final/AS/HKG/source/VHHH_PC.txt index 2cf37af..7d1483f 100644 --- a/final/AS/HKG/source/VHHH_PC.txt +++ b/final/AS/HKG/source/VHHH_PC.txt @@ -1,6 +1,7 @@ [meta] header = VHHH TMA 1.0.0 See VHHH_PC_readme.md +callsigns = True [airspace] radius = 100 diff --git a/tools/expand.py b/tools/expand.py index 6fd604a..88a7134 100644 --- a/tools/expand.py +++ b/tools/expand.py @@ -63,28 +63,31 @@ class Airline: self.frequency = int(frequency.strip()) self.types = types.strip() self.callsign = callsign.strip() - if Airline.callsigns is not None and Airline.use_callsigns: - if '-' not in callsign: - self.pronunciation = Airline.callsigns[callsign] + try: + if Airline.callsigns is not None and Airline.use_callsigns: + if '-' not in callsign: + self.pronunciation = Airline.callsigns[callsign] + else: + # if length of key is more than 3, assume it is not registration + key = callsign[:callsign.index('-')] + self.callsign = callsign.strip('_') + # if key length is longer than 3 and key doesn't have match, + # we strip '_' to allow for mil callsigns with length <= 3 + self.pronunciation = Airline.callsigns.get(key, key.strip('_')) if len(key) > 3 \ + else Airline.callsigns.get(key, '0') else: - # if length of key is more than 3, assume it is not registration - key = callsign[:callsign.index('-')] - self.callsign = callsign.strip('_') - # if key length is longer than 3 and key doesn't have match, - # we strip '_' to allow for mil callsigns with length <= 3 - self.pronunciation = Airline.callsigns.get(key, key.strip('_')) if len(key) > 3 \ - else Airline.callsigns.get(key, '0') - else: - self.pronunciation = data[0].strip() - data = data[1:] - if gateways is not None: - directions = [] - arrival_gateways = {gateway.strip() for gateway in data[0].split("/")} - departure_gateways = {gateway.strip() for gateway in data[1].split("/")} - self.directions = "".join(sorted( - {gateways[gateway] for gateway in arrival_gateways | departure_gateways})) - else: - self.directions = data[0].strip() + self.pronunciation = data[0].strip() + data = data[1:] + if gateways is not None: + arrival_gateways = {gateway.strip() for gateway in data[0].split("/")} + departure_gateways = {gateway.strip() for gateway in data[1].split("/")} + self.directions = "".join(sorted( + {gateways[gateway] for gateway in arrival_gateways | departure_gateways})) + else: + self.directions = data[0].strip() + except Exception as e: + raise ValueError(f"Could not create airline from ({callsign}, {frequency}, {types}, {str(data)})" + + f"\nCallsign pronunciation lookup = {Airline.use_callsigns}") from e def process_fix_list(fix_list, fixes):