Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Do not use geofabrik .json file before geofabrik .json file has been downloaded #192

Merged
merged 3 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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