Skip to content

Commit

Permalink
[FIX] cut down folder_name to 50 to not crash when creating output fo…
Browse files Browse the repository at this point in the history
…lder (#228)

* cut down folder_name to 50 to not crash when creating output folder

fixes #227

* Bump to version 4.1.1a0

* add "_and_more" if folder name is cutted

* Bump to version 4.1.1a1
  • Loading branch information
treee111 committed Nov 17, 2023
1 parent cedcd30 commit 866bbaa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion conda_env/gdal-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ dependencies:
- matplotlib=3.4.3
- pip
- pip:
- wahoomc==4.1.0
- wahoomc==4.1.1a1
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = wahoomc
version = 4.1.0
version = 4.1.1a1
author = Benjamin Kreuscher
author_email = benni.kreuscher@gmail.com
description = Create maps for your Wahoo bike computer based on latest OSM maps
Expand Down
31 changes: 25 additions & 6 deletions tests/test_osm_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,23 @@ def test_input_country_malta(self):
Test "malta" as input to the wahooMapsCreator
check, if the given input-parameter is saved to the OsmMaps instance
"""
o_osm_data = self.get_osm_data_instance('malta')

o_input_data = InputData()
o_input_data.country = 'malta'
self.assertEqual(o_osm_data.country_name, 'malta')

o_osm_data = CountryOsmData(o_input_data)
o_osm_data.process_input_of_the_tool()
def test_folder_name_many_countries(self):
"""
Test a very long list of countries as input to the wahooMapsCreator
check, if the list of countries is cutted down to 100 chars and that is saved to the OsmMaps instance
"""
o_osm_data = self.get_osm_data_instance('albania,alps,andorra,austria,azores,belarus,belgium,bosnia-herzegovina,britain-and-ireland,bulgaria,croatia,cyprus,czech-republic,dach,denmark,estonia,faroe-islands,finland,france,georgia,germany,great-britain,greece,guernsey-jersey,hungary,iceland,ireland-and-northern-ireland,isle-of-man,italy,kosovo,latvia,liechtenstein,lithuania,luxembourg,macedonia,malta,moldova,monaco,montenegro,netherlands,norway,poland,portugal,romania,serbia,slovakia,slovenia,spain,sweden,switzerland,turkey,ukraine')

o_osm_maps = OsmMaps(o_osm_data)
folder_name = o_osm_maps.calculate_folder_name('.map.lzma')
folder_name_maps = o_osm_maps.calculate_folder_name('.map')

result = o_osm_data.country_name
self.assertEqual(result, 'malta')
self.assertEqual(folder_name, 'albania_alps_andorra_austria_azores_belar_and_more')
self.assertEqual(folder_name_maps, 'albania_alps_andorra_austria_azores_belar_and_more-maps')

def test_encoding_open_sea_osm(self):
"""
Expand All @@ -172,6 +180,17 @@ def test_encoding_open_sea_osm(self):

self.assertEqual(sea_data_no_encoding, sea_data_utf8)

def get_osm_data_instance(self, country_input):
"""
takes given input creates OsmData instance
"""
o_input_data = InputData()
o_input_data.country = country_input

o_osm_data = CountryOsmData(o_input_data)
o_osm_data.process_input_of_the_tool()

return o_osm_data

class TestConfigFile(unittest.TestCase):
"""
Expand Down
2 changes: 1 addition & 1 deletion wahoomc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
TOOLING_WIN_DIR = os.path.join(WAHOO_MC_DIR, 'tooling_win')
# location of repo / python installation - not used
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
VERSION = '4.1.0'
VERSION = '4.1.1a1'


block_download = ['dach', 'alps', 'britain-and-ireland', 'south-africa-and-lesotho',
Expand Down
26 changes: 21 additions & 5 deletions wahoomc/osm_maps_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,9 @@ def make_and_zip_files(self, extension, zip_folder):
extension: '.map.lzma' for Wahoo tiles
extension: '.map' for Cruiser map files
"""

if extension == '.map.lzma':
folder_name = self.o_osm_data.country_name
else:
folder_name = self.o_osm_data.country_name + '-maps'
# if country_name is longer than 50 characters, cut down to 50 for the folder name
# that preserves crashing later on when creating the output folder
folder_name = self.calculate_folder_name(extension)

log.info('-' * 80)
log.info('# Create: %s files', extension)
Expand Down Expand Up @@ -887,6 +885,24 @@ def make_and_zip_files(self, extension, zip_folder):

log.info('+ Create %s files: OK', extension)

def calculate_folder_name(self, extension):
"""
if country_name is longer than 50 characters, cut down to 50 for the folder name
that preserves crashing later on when creating the output folder
"""
# cut down to 100 (relevant if country_name is longer than 100 characters)
if len(self.o_osm_data.country_name) > 50:
country_name_50_chars = self.o_osm_data.country_name[:41] + '_and_more'
else:
country_name_50_chars = self.o_osm_data.country_name

if extension == '.map.lzma':
folder_name = country_name_50_chars
else:
folder_name = country_name_50_chars + '-maps'

return folder_name

def copy_to_dst(self, extension, src, dst):
"""
Zip .map or .map.lzma files
Expand Down

0 comments on commit 866bbaa

Please sign in to comment.