Skip to content

Commit

Permalink
[BUGFIX] Do not use geofabrik .json file before geofabrik .json file …
Browse files Browse the repository at this point in the history
…has been downloaded (treee111#192)

* remove non-instance o_geofabrik_json objects

* dl geofabrik independent of Downloader object

- handle geofabrik file firstly as tooling, later on with -md

* unify constructors
  • Loading branch information
treee111 authored and alfh committed Nov 4, 2023
1 parent a06b9dc commit 3e15c0d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
18 changes: 15 additions & 3 deletions wahoomc/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 = []
Expand Down
10 changes: 7 additions & 3 deletions wahoomc/geofabrik.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions wahoomc/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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("<<ComboboxSelected>>", self.callback_continent)

Expand Down
5 changes: 4 additions & 1 deletion wahoomc/setup_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down

0 comments on commit 3e15c0d

Please sign in to comment.