From 1891c88e3849a01e9f1f56c82301f1bdc57db275 Mon Sep 17 00:00:00 2001 From: "Tobias Wellnitz, DH1TW" Date: Tue, 3 Mar 2020 17:22:23 +0100 Subject: [PATCH] delete download artifact after import --- pyhamtools/lookuplib.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pyhamtools/lookuplib.py b/pyhamtools/lookuplib.py index 400cf96..a02a2ae 100644 --- a/pyhamtools/lookuplib.py +++ b/pyhamtools/lookuplib.py @@ -996,6 +996,9 @@ class LookupLib(object): self._invalid_operations_index = cty_dict["invalid_operations_index"] self._zone_exceptions_index = cty_dict["zone_exceptions_index"] + if self._download: + self._cleanup_download_artifact(cty_file) + return True def _load_countryfile(self, @@ -1030,6 +1033,9 @@ class LookupLib(object): self._callsign_exceptions_index = cty_dict["exceptions_index"] self._prefixes_index = cty_dict["prefixes_index"] + if self._download: + self._cleanup_download_artifact(cty_file) + return True def _download_file(self, url, apikey=None): @@ -1091,6 +1097,19 @@ class LookupLib(object): return cty_file_path + def _cleanup_download_artifact(self, filename): + """ + Delete the downloaded files which are not necessary anymore + + Args: + filename (string): absolute path to the download artifact + """ + + try: + os.remove(filename) + except: + self._logger.warning("unable delete the download artifact: %s", _download_file) + def _extract_clublog_header(self, cty_xml_filename): """ Extract the header of the Clublog XML File