Skip to content

Commit

Permalink
[FEAT] Make logging uniformly and include variables into the message …
Browse files Browse the repository at this point in the history
…correctly (#154)

* uniform logging during map-processing

- todo: make helper function to have that central?!

* correct message text to include the variable

* changes during PR testing
  • Loading branch information
treee111 authored Oct 4, 2022
1 parent 60c1c6c commit f59c138
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions wahoomc/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def download_file(target_filepath, url, is_zip):
"""
logging_filename = target_filepath.split(os.sep)[-1]
log.info('-' * 80)
log.info('+ Downloading %s file', logging_filename)
log.info('# Downloading %s file', logging_filename)
if is_zip:
# build target-filepath based on last element of URL
last_part = url.rsplit('/', 1)[-1]
Expand Down Expand Up @@ -124,7 +124,7 @@ def check_land_polygons_file(self):

if self.check_file(LAND_POLYGONS_PATH) is True or \
self.force_download is True:
log.info('# Need to download land polygons file')
log.info('+ Need to download land polygons file')
self.need_to_dl.append('land_polygons')

def download_files_if_needed(self):
Expand Down
33 changes: 16 additions & 17 deletions wahoomc/osm_maps_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def filter_tags_from_country_osm_pbf_files(self): # pylint: disable=too-many-st
cmd.append('-o='+out_file_o5m)

run_subprocess_and_log_output(
cmd, '! Error in OSMConvert with country: {key}')
cmd, f'! Error in OSMConvert with country: {key}')
else:
log.info('+ Map of %s already in o5m format', key)

Expand All @@ -354,7 +354,7 @@ def filter_tags_from_country_osm_pbf_files(self): # pylint: disable=too-many-st
cmd.append('-o=' + out_file_o5m_filtered_win)

run_subprocess_and_log_output(
cmd, '! Error in OSMFilter with country: {key}')
cmd, f'! Error in OSMFilter with country: {key}')

cmd = [get_tooling_win_path(['osmfilter'])]
cmd.append(out_file_o5m)
Expand All @@ -367,7 +367,7 @@ def filter_tags_from_country_osm_pbf_files(self): # pylint: disable=too-many-st
cmd.append('-o=' + out_file_o5m_filtered_names_win)

run_subprocess_and_log_output(
cmd, '! Error in OSMFilter with country: {key}')
cmd, f'! Error in OSMFilter with country: {key}')

val['filtered_file'] = out_file_o5m_filtered_win
val['filtered_file_names'] = out_file_o5m_filtered_names_win
Expand All @@ -389,7 +389,7 @@ def filter_tags_from_country_osm_pbf_files(self): # pylint: disable=too-many-st
cmd.append('--overwrite')

run_subprocess_and_log_output(
cmd, '! Error in Osmium with country: {key}')
cmd, f'! Error in Osmium with country: {key}')

cmd = ['osmium', 'tags-filter', '--remove-tags']
cmd.append(val['map_file'])
Expand All @@ -399,7 +399,7 @@ def filter_tags_from_country_osm_pbf_files(self): # pylint: disable=too-many-st
cmd.append('--overwrite')

run_subprocess_and_log_output(
cmd, '! Error in Osmium with country: {key}')
cmd, f'! Error in Osmium with country: {key}')

val['filtered_file'] = out_file_pbf_filtered_mac
val['filtered_file_names'] = out_file_pbf_filtered_names_mac
Expand All @@ -412,7 +412,7 @@ def generate_land(self):
"""

log.info('-' * 80)
log.info('# Generate land')
log.info('# Generate land for each coordinate')

tile_count = 1
for tile in self.o_osm_data.tiles:
Expand All @@ -424,7 +424,7 @@ def generate_land(self):
# create land.dbf, land.prj, land.shp, land.shx
if not os.path.isfile(land_file) or self.o_osm_data.force_processing is True:
log.info(
'+ Generate land %s of %s for Coordinates: %s,%s', tile_count, len(self.o_osm_data.tiles), tile["x"], tile["y"])
'+ Coordinates: %s,%s. (%s of %s)', tile["x"], tile["y"], tile_count, len(self.o_osm_data.tiles))
cmd = ['ogr2ogr', '-overwrite', '-skipfailures']
# Try to prevent getting outside of the +/-180 and +/- 90 degrees borders. Normally the +/- 0.1 are there to prevent white lines at border borders.
if tile["x"] == 255 or tile["y"] == 255 or tile["x"] == 0 or tile["y"] == 0:
Expand Down Expand Up @@ -459,23 +459,23 @@ def generate_land(self):
cmd, f'! Error creating land.osm for tile: {tile["x"]},{tile["y"]}')
tile_count += 1

log.info('+ Generate land: OK')
log.info('+ Generate land for each coordinate: OK')

def generate_sea(self):
"""
Generate sea for all tiles
"""

log.info('-' * 80)
log.info('# Generate sea')
log.info('# Generate sea for each coordinate')

tile_count = 1
for tile in self.o_osm_data.tiles:
out_file_sea = os.path.join(USER_OUTPUT_DIR,
f'{tile["x"]}', f'{tile["y"]}', 'sea.osm')
if not os.path.isfile(out_file_sea) or self.o_osm_data.force_processing is True:
log.info(
'+ Generate sea %s of %s for Coordinates: %s,%s', tile_count, len(self.o_osm_data.tiles), tile["x"], tile["y"])
'+ Coordinates: %s,%s. (%s of %s)', tile["x"], tile["y"], tile_count, len(self.o_osm_data.tiles))
with open(os.path.join(RESOURCES_DIR, 'sea.osm'), encoding="utf-8") as sea_file:
sea_data = sea_file.read()

Expand Down Expand Up @@ -503,7 +503,7 @@ def generate_sea(self):
output_file.write(sea_data)
tile_count += 1

log.info('+ Generate sea: OK')
log.info('+ Generate sea for each coordinate: OK')

def split_filtered_country_files_to_tiles(self):
"""
Expand All @@ -519,7 +519,7 @@ def split_filtered_country_files_to_tiles(self):
if country not in tile['countries']:
continue
log.info(
'+ Splitting tile %s of %s for Coordinates: %s,%s from map of %s', tile_count, len(self.o_osm_data.tiles), tile["x"], tile["y"], country)
'+ Coordinates: %s,%s / %s (%s of %s)', tile["x"], tile["y"], country, tile_count, len(self.o_osm_data.tiles))
out_file = os.path.join(USER_OUTPUT_DIR,
f'{tile["x"]}', f'{tile["y"]}', f'split-{country}.osm.pbf')
out_file_names = os.path.join(USER_OUTPUT_DIR,
Expand Down Expand Up @@ -576,8 +576,6 @@ def split_filtered_country_files_to_tiles(self):
run_subprocess_and_log_output(
cmd, '! Error in Osmosis with country: {country}. macOS/out_file_names')

log.info(val['filtered_file'])

tile_count += 1

log.info('+ Split filtered country files to tiles: OK')
Expand Down Expand Up @@ -700,7 +698,7 @@ def create_map_files(self, save_cruiser, tag_wahoo_xml):
"""

log.info('-' * 80)
log.info('# Creating .map files')
log.info('# Creating .map files for tiles')

# Number of threads to use in the mapwriter plug-in
threads = multiprocessing.cpu_count() - 1
Expand All @@ -710,7 +708,8 @@ def create_map_files(self, save_cruiser, tag_wahoo_xml):
tile_count = 1
for tile in self.o_osm_data.tiles:
log.info(
'+ Creating map file for tile %s of %s for Coordinates: %s,%s', tile_count, len(self.o_osm_data.tiles), tile["x"], tile["y"])
'+ Coordinates: %s,%s (%s of %s)', tile["x"], tile["y"], tile_count, len(self.o_osm_data.tiles))

out_file_map = os.path.join(USER_OUTPUT_DIR,
f'{tile["x"]}', f'{tile["y"]}.map')

Expand Down Expand Up @@ -765,7 +764,7 @@ def create_map_files(self, save_cruiser, tag_wahoo_xml):

tile_count += 1

log.info('+ Creating .map files: OK')
log.info('+ Creating .map files for tiles: OK')

def make_and_zip_files(self, extension, zip_folder):
"""
Expand Down

0 comments on commit f59c138

Please sign in to comment.