diff --git a/wahoomc/downloader.py b/wahoomc/downloader.py index 3387ed1e..2a99b1f3 100644 --- a/wahoomc/downloader.py +++ b/wahoomc/downloader.py @@ -146,10 +146,18 @@ def download_tooling(): # download geofabrik json as this will be needed always # because of the .json file replacement by geofabrik - o_downloader = Downloader(24, False) + download_geofabrik_file_if_not_existing() - if o_downloader.should_geofabrik_file_be_downloaded(): - o_downloader.download_geofabrik_file() + +def download_geofabrik_file_if_not_existing(): + """ + check geofabrik file if not existing + if the file does not exist, download geofabrik file + """ + if not os.path.isfile(GEOFABRIK_PATH): + log.info('# Need to download geofabrik file') + download_file(GEOFABRIK_PATH, + 'https://download.geofabrik.de/index-v1.json') def get_latest_pypi_version(): @@ -191,6 +199,10 @@ def __init__(self, max_days_old, force_download, border_countries=None): self.force_download = force_download self.border_countries = border_countries + # safety net if geofabrik file is not there + # OsmData=>process_input_of_the_tool does it "correctly" + download_geofabrik_file_if_not_existing() + self.o_geofabrik_json = GeofabrikJson() self.need_to_dl = [] diff --git a/wahoomc/geofabrik.py b/wahoomc/geofabrik.py index 5bf2ea67..ea8e9696 100644 --- a/wahoomc/geofabrik.py +++ b/wahoomc/geofabrik.py @@ -25,7 +25,7 @@ class InformalGeofabrikInterface: border_countries = {} output = {} - o_geofabrik_json = GeofabrikJson() + o_geofabrik_json = None def get_tiles_of_wanted_map(self) -> str: """Get the relevant tiles for the wanted country or X/Y coordinate""" @@ -44,7 +44,9 @@ class CountryGeofabrik(InformalGeofabrikInterface): """Geofabrik processing for countries""" def __init__(self, input): - # input parameters + self.o_geofabrik_json = GeofabrikJson() + + # get geofabrik country self.wanted_map = self.o_geofabrik_json.translate_id_no_to_geofabrik( input) @@ -234,7 +236,9 @@ class XYGeofabrik(InformalGeofabrikInterface): """Geofabrik processing for X/Y coordinates""" def __init__(self, input): - # input parameters + self.o_geofabrik_json = GeofabrikJson() + + # already splitted pairs of xy-coordinates self.wanted_map = input def get_tiles_of_wanted_map(self) -> str: diff --git a/wahoomc/input.py b/wahoomc/input.py index cfe11512..02e19cac 100644 --- a/wahoomc/input.py +++ b/wahoomc/input.py @@ -16,8 +16,6 @@ from wahoomc.geofabrik_json import GeofabrikJson from wahoomc.geofabrik_json import CountyIsNoGeofabrikCountry -o_geofabrik_json = GeofabrikJson() - def process_call_of_the_tool(): """ @@ -156,7 +154,7 @@ def get_countries_of_continent_from_geofabrik(continent): returns all countries of a continent to be selected in UI """ countries = [] - for region, value in o_geofabrik_json.geofabrik_overview.items(): + for region, value in GeofabrikJson().geofabrik_overview.items(): try: if value['parent'] == continent: countries.append(region) @@ -206,7 +204,7 @@ def is_required_input_given_or_exit(self, issue_message): "Country and X/Y coordinates are given. Only one of both is allowed!") elif self.country: try: - self.country = o_geofabrik_json.translate_id_no_to_geofabrik( + self.country = GeofabrikJson().translate_id_no_to_geofabrik( self.country) return True except CountyIsNoGeofabrikCountry: @@ -333,7 +331,7 @@ def __init__(self, parent, oInputData): # Comboboxes self.cb_continent = ttk.Combobox( - self, values=o_geofabrik_json.geofabrik_regions, state="readonly") + self, values=GeofabrikJson().geofabrik_regions, state="readonly") self.cb_continent.current(0) # pre-select first entry in combobox self.cb_continent.bind("<>", self.callback_continent) diff --git a/wahoomc/setup_functions.py b/wahoomc/setup_functions.py index 584834d8..230f6c78 100644 --- a/wahoomc/setup_functions.py +++ b/wahoomc/setup_functions.py @@ -18,7 +18,7 @@ from wahoomc.constants_functions import get_tooling_win_path, get_absolute_dir_user_or_repo from wahoomc.downloader import get_latest_pypi_version -from wahoomc.constants import USER_WAHOO_MC +from wahoomc.constants import GEOFABRIK_PATH, USER_WAHOO_MC from wahoomc.constants import USER_DL_DIR from wahoomc.constants import USER_MAPS_DIR from wahoomc.constants import USER_OUTPUT_DIR @@ -91,6 +91,9 @@ def check_installation_of_required_programs(): sys.exit( f"Java is not installed. {text_to_docu}") + if not os.path.isfile(GEOFABRIK_PATH): + sys.exit('Geofabrik file is not downloaded. Please create an issue:\n- https://github.com/treee111/wahooMapsCreator/issues"') + if platform.system() == "Windows": if not os.path.exists(get_tooling_win_path( os.path.join('Osmosis', 'bin', 'osmosis.bat'), in_user_dir=True)):