diff --git a/sigrefdataproviders/arlhs.py b/sigrefdataproviders/arlhs.py index 2b23b88..50bd9a4 100644 --- a/sigrefdataproviders/arlhs.py +++ b/sigrefdataproviders/arlhs.py @@ -27,4 +27,9 @@ class ARLHS(FileDownloadSIGRefDataProvider): "Longitude"] != "" else None, grid=row["Maidenhead Locator"])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/dme.py b/sigrefdataproviders/dme.py index 492fc29..32d1e99 100644 --- a/sigrefdataproviders/dme.py +++ b/sigrefdataproviders/dme.py @@ -32,4 +32,10 @@ class DME(LocalFileSIGRefDataProvider): if latitude and longitude: ref.grid = latlong_to_locator(latitude, longitude, 6) new_data.append(ref) + + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop: + break + return new_data diff --git a/sigrefdataproviders/gma.py b/sigrefdataproviders/gma.py index f8753b6..6a5edd0 100644 --- a/sigrefdataproviders/gma.py +++ b/sigrefdataproviders/gma.py @@ -26,4 +26,9 @@ class GMA(FileDownloadSIGRefDataProvider): "Longitude"] != "" else None, grid=row["Maidenhead Locator"])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/illw.py b/sigrefdataproviders/illw.py index 9e2f7b8..dee9aac 100644 --- a/sigrefdataproviders/illw.py +++ b/sigrefdataproviders/illw.py @@ -27,4 +27,9 @@ class ILLW(FileDownloadSIGRefDataProvider): "Longitude"] != "" else None, grid=row["Maidenhead Locator"])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/iota.py b/sigrefdataproviders/iota.py index 1925967..623f8a9 100644 --- a/sigrefdataproviders/iota.py +++ b/sigrefdataproviders/iota.py @@ -33,4 +33,9 @@ class IOTA(FileDownloadSIGRefDataProvider): new_data.append(SIGRef(sig=self.SIG, id=ref_id, name=ref["name"], grid=grid, latitude=latitude, longitude=longitude)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/llota.py b/sigrefdataproviders/llota.py index 6faa48f..d8ab125 100644 --- a/sigrefdataproviders/llota.py +++ b/sigrefdataproviders/llota.py @@ -29,4 +29,9 @@ class LLOTA(FileDownloadSIGRefDataProvider): latitude=ll[0], longitude=ll[1])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/local_file_sig_ref_data_provider.py b/sigrefdataproviders/local_file_sig_ref_data_provider.py index aacadd9..1a7b09b 100644 --- a/sigrefdataproviders/local_file_sig_ref_data_provider.py +++ b/sigrefdataproviders/local_file_sig_ref_data_provider.py @@ -12,6 +12,7 @@ class LocalFileSIGRefDataProvider(SIGRefDataProvider): def __init__(self, sig, provider_config, path): super().__init__(sig, provider_config) self._path = path + self._stop = False def start(self): logging.debug("Loading " + self.sig_name + " SIG ref data from file.") @@ -29,7 +30,7 @@ class LocalFileSIGRefDataProvider(SIGRefDataProvider): logging.error("Exception in local file SIG Ref Data Provider (" + self.sig_name + ")", e, exc_info=True) def stop(self): - pass + self._stop = True def _file_to_data(self, path): """Load a file on the given path and turn it into SIG Ref data.""" diff --git a/sigrefdataproviders/mota.py b/sigrefdataproviders/mota.py index 1fac35a..3fd86b2 100644 --- a/sigrefdataproviders/mota.py +++ b/sigrefdataproviders/mota.py @@ -26,4 +26,9 @@ class MOTA(FileDownloadSIGRefDataProvider): "Longitude"] != "" else None, grid=row["Maidenhead Locator"])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/pota.py b/sigrefdataproviders/pota.py index a0a549f..886e08e 100644 --- a/sigrefdataproviders/pota.py +++ b/sigrefdataproviders/pota.py @@ -26,4 +26,9 @@ class POTA(FileDownloadSIGRefDataProvider): longitude=float(row["longitude"]) if "longitude" in row and row[ "longitude"] != "" else None)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/siota.py b/sigrefdataproviders/siota.py index f763cfd..56aba0e 100644 --- a/sigrefdataproviders/siota.py +++ b/sigrefdataproviders/siota.py @@ -23,4 +23,9 @@ class SIOTA(FileDownloadSIGRefDataProvider): latitude=float(row["LAT"]) if "LAT" in row else None, longitude=float(row["LNG"]) if "LNG" in row else None)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/sota.py b/sigrefdataproviders/sota.py index fbfbb36..c8b86a2 100644 --- a/sigrefdataproviders/sota.py +++ b/sigrefdataproviders/sota.py @@ -31,4 +31,9 @@ class SOTA(FileDownloadSIGRefDataProvider): ref.grid = latlong_to_locator(latitude, longitude, 6) new_data.append(ref) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/toilets.py b/sigrefdataproviders/toilets.py index defdc37..84e8a44 100644 --- a/sigrefdataproviders/toilets.py +++ b/sigrefdataproviders/toilets.py @@ -15,10 +15,16 @@ class Toilets(LocalFileSIGRefDataProvider): def _file_to_data(self, path): new_data = [] - f = open(path) - csv_data = f.read() - dr = csv.DictReader(csv_data.splitlines()) - for row in dr: - new_data.append(SIGRef(sig=self.SIG, id=row["ref"], name=row["ref"], latitude=float(row["lat"]), - longitude=float(row["lon"]))) + with open(path) as _f: + csv_data = _f.read() + dr = csv.DictReader(csv_data.splitlines()) + for row in dr: + new_data.append(SIGRef(sig=self.SIG, id=row["ref"], name=row["ref"], latitude=float(row["lat"]), + longitude=float(row["lon"]))) + + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop: + break + return new_data diff --git a/sigrefdataproviders/towers.py b/sigrefdataproviders/towers.py index 80e3be7..f4e9d4a 100644 --- a/sigrefdataproviders/towers.py +++ b/sigrefdataproviders/towers.py @@ -24,4 +24,9 @@ class Towers(FileDownloadSIGRefDataProvider): latitude=float(row["Lat"]) if "Lat" in row and row["Lat"] != "" else None, longitude=float(row["Lon"]) if "Lon" in row and row["Lon"] != "" else None)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/wca.py b/sigrefdataproviders/wca.py index bb874cf..10f8e3f 100644 --- a/sigrefdataproviders/wca.py +++ b/sigrefdataproviders/wca.py @@ -41,4 +41,9 @@ class WCA(FileDownloadSIGRefDataProvider): longitude=longitude, grid=grid)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/wota.py b/sigrefdataproviders/wota.py index 1e8c1f3..07e167c 100644 --- a/sigrefdataproviders/wota.py +++ b/sigrefdataproviders/wota.py @@ -28,4 +28,9 @@ class WOTA(FileDownloadSIGRefDataProvider): latitude=feature["geometry"]["coordinates"][1], longitude=feature["geometry"]["coordinates"][0])) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/wwbota.py b/sigrefdataproviders/wwbota.py index 11f77d9..08d1ae9 100644 --- a/sigrefdataproviders/wwbota.py +++ b/sigrefdataproviders/wwbota.py @@ -24,4 +24,9 @@ class WWBOTA(FileDownloadSIGRefDataProvider): latitude=float(row["Lat"]) if "Lat" in row and row["Lat"] != "" else None, longitude=float(row["Long"]) if "Long" in row and row["Long"] != "" else None)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/wwff.py b/sigrefdataproviders/wwff.py index c840f23..ac5778c 100644 --- a/sigrefdataproviders/wwff.py +++ b/sigrefdataproviders/wwff.py @@ -27,4 +27,9 @@ class WWFF(FileDownloadSIGRefDataProvider): longitude=float(row["longitude"]) if "longitude" in row and row[ "longitude"] != "" and row["longitude"] != "-" else None)) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest of + # the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/sigrefdataproviders/zlota.py b/sigrefdataproviders/zlota.py index 876e48d..9043ead 100644 --- a/sigrefdataproviders/zlota.py +++ b/sigrefdataproviders/zlota.py @@ -31,4 +31,9 @@ class ZLOTA(FileDownloadSIGRefDataProvider): ref.grid = latlong_to_locator(latitude, longitude, 6) new_data.append(ref) + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop_event.is_set(): + break + return new_data diff --git a/staticdataproviders/cqzonedata.py b/staticdataproviders/cqzonedata.py index ba46865..3bc9942 100644 --- a/staticdataproviders/cqzonedata.py +++ b/staticdataproviders/cqzonedata.py @@ -22,6 +22,12 @@ class CQZoneData(LocalFileStaticDataProvider): cq_zone_data = geopandas.GeoDataFrame.from_features(json.load(f)["features"]) for idx in cq_zone_data.index: prepare(cq_zone_data.at[idx, 'geometry']) + + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to prepare the rest + # of the data in this case + if self.stop: + break + DATA_STORE.cq_zone_data = cq_zone_data return True diff --git a/staticdataproviders/ituzonedata.py b/staticdataproviders/ituzonedata.py index 67e0049..88cfb20 100644 --- a/staticdataproviders/ituzonedata.py +++ b/staticdataproviders/ituzonedata.py @@ -22,6 +22,12 @@ class ITUZoneData(LocalFileStaticDataProvider): itu_zone_data = geopandas.GeoDataFrame.from_features(json.load(f)["features"]) for idx in itu_zone_data.index: prepare(itu_zone_data.at[idx, 'geometry']) + + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to prepare the rest + # of the data in this case + if self.stop: + break + DATA_STORE.itu_zone_data = itu_zone_data return True diff --git a/staticdataproviders/k0swe.py b/staticdataproviders/k0swe.py index 30c31ff..37f23af 100644 --- a/staticdataproviders/k0swe.py +++ b/staticdataproviders/k0swe.py @@ -23,10 +23,18 @@ class K0SWE(FileDownloadStaticDataProvider): for dxcc in dxcc_list: dxcc_map[dxcc["entityCode"]] = dxcc + # Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest + # of the data in this case + if self._stop_event.is_set(): + break + # Add to data store for k, v in dxcc_map.items(): DATA_STORE.dxcc_data[k] = v + if self._stop_event.is_set(): + break + # Regenerate in-memory regex-to-DXCC-entity-code map. DATA_STORE.regenerateCallRegexToDXCCEntityMap() diff --git a/staticdataproviders/local_file_static_data_provider.py b/staticdataproviders/local_file_static_data_provider.py index 7ab9a89..46e8b68 100644 --- a/staticdataproviders/local_file_static_data_provider.py +++ b/staticdataproviders/local_file_static_data_provider.py @@ -12,6 +12,7 @@ class LocalFileStaticDataProvider(StaticDataProvider): def __init__(self, name, provider_config, path): super().__init__(name, provider_config) self._path = path + self._stop = False def start(self): logging.debug("Loading " + self.name + " static reference data from file.") @@ -29,7 +30,7 @@ class LocalFileStaticDataProvider(StaticDataProvider): logging.error("Exception in local file Static Data Provider (" + self.name + ")", e, exc_info=True) def stop(self): - pass + self._stop = True def _load_data(self, path): """Load data from the given file path. Return true if successful, false otherwise."""