Skip to content

Commit 866bbaa

Browse files
authored
[FIX] cut down folder_name to 50 to not crash when creating output folder (#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
1 parent cedcd30 commit 866bbaa

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

conda_env/gdal-user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ dependencies:
1010
- matplotlib=3.4.3
1111
- pip
1212
- pip:
13-
- wahoomc==4.1.0
13+
- wahoomc==4.1.1a1

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = wahoomc
3-
version = 4.1.0
3+
version = 4.1.1a1
44
author = Benjamin Kreuscher
55
author_email = [email protected]
66
description = Create maps for your Wahoo bike computer based on latest OSM maps

tests/test_osm_maps.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,23 @@ def test_input_country_malta(self):
150150
Test "malta" as input to the wahooMapsCreator
151151
check, if the given input-parameter is saved to the OsmMaps instance
152152
"""
153+
o_osm_data = self.get_osm_data_instance('malta')
153154

154-
o_input_data = InputData()
155-
o_input_data.country = 'malta'
155+
self.assertEqual(o_osm_data.country_name, 'malta')
156156

157-
o_osm_data = CountryOsmData(o_input_data)
158-
o_osm_data.process_input_of_the_tool()
157+
def test_folder_name_many_countries(self):
158+
"""
159+
Test a very long list of countries as input to the wahooMapsCreator
160+
check, if the list of countries is cutted down to 100 chars and that is saved to the OsmMaps instance
161+
"""
162+
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')
163+
164+
o_osm_maps = OsmMaps(o_osm_data)
165+
folder_name = o_osm_maps.calculate_folder_name('.map.lzma')
166+
folder_name_maps = o_osm_maps.calculate_folder_name('.map')
159167

160-
result = o_osm_data.country_name
161-
self.assertEqual(result, 'malta')
168+
self.assertEqual(folder_name, 'albania_alps_andorra_austria_azores_belar_and_more')
169+
self.assertEqual(folder_name_maps, 'albania_alps_andorra_austria_azores_belar_and_more-maps')
162170

163171
def test_encoding_open_sea_osm(self):
164172
"""
@@ -172,6 +180,17 @@ def test_encoding_open_sea_osm(self):
172180

173181
self.assertEqual(sea_data_no_encoding, sea_data_utf8)
174182

183+
def get_osm_data_instance(self, country_input):
184+
"""
185+
takes given input creates OsmData instance
186+
"""
187+
o_input_data = InputData()
188+
o_input_data.country = country_input
189+
190+
o_osm_data = CountryOsmData(o_input_data)
191+
o_osm_data.process_input_of_the_tool()
192+
193+
return o_osm_data
175194

176195
class TestConfigFile(unittest.TestCase):
177196
"""

wahoomc/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
TOOLING_WIN_DIR = os.path.join(WAHOO_MC_DIR, 'tooling_win')
2727
# location of repo / python installation - not used
2828
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
29-
VERSION = '4.1.0'
29+
VERSION = '4.1.1a1'
3030

3131

3232
block_download = ['dach', 'alps', 'britain-and-ireland', 'south-africa-and-lesotho',

wahoomc/osm_maps_functions.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,9 @@ def make_and_zip_files(self, extension, zip_folder):
826826
extension: '.map.lzma' for Wahoo tiles
827827
extension: '.map' for Cruiser map files
828828
"""
829-
830-
if extension == '.map.lzma':
831-
folder_name = self.o_osm_data.country_name
832-
else:
833-
folder_name = self.o_osm_data.country_name + '-maps'
829+
# if country_name is longer than 50 characters, cut down to 50 for the folder name
830+
# that preserves crashing later on when creating the output folder
831+
folder_name = self.calculate_folder_name(extension)
834832

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

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

888+
def calculate_folder_name(self, extension):
889+
"""
890+
if country_name is longer than 50 characters, cut down to 50 for the folder name
891+
that preserves crashing later on when creating the output folder
892+
"""
893+
# cut down to 100 (relevant if country_name is longer than 100 characters)
894+
if len(self.o_osm_data.country_name) > 50:
895+
country_name_50_chars = self.o_osm_data.country_name[:41] + '_and_more'
896+
else:
897+
country_name_50_chars = self.o_osm_data.country_name
898+
899+
if extension == '.map.lzma':
900+
folder_name = country_name_50_chars
901+
else:
902+
folder_name = country_name_50_chars + '-maps'
903+
904+
return folder_name
905+
890906
def copy_to_dst(self, extension, src, dst):
891907
"""
892908
Zip .map or .map.lzma files

0 commit comments

Comments
 (0)