From 6431847809f13a4c4142dee7cd4792870b862a3a Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Thu, 23 May 2019 17:24:25 +0300 Subject: [PATCH] [python] Added stage_external_resources. --- tools/python/maps_generator/generator/env.py | 4 +++ tools/python/maps_generator/maps_generator.py | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/python/maps_generator/generator/env.py b/tools/python/maps_generator/generator/env.py index d5b91297b4..cf2b0cf1d1 100644 --- a/tools/python/maps_generator/generator/env.py +++ b/tools/python/maps_generator/generator/env.py @@ -141,6 +141,10 @@ class Env: def is_accepted_stage(self, stage_name): return stage_name not in self._skipped_stages + @property + def external_resources_path(self): + return os.path.join(self.mwm_path, "external_resources.txt") + @property def id_to_wikidata_path(self): return os.path.join(self.intermediate_path, "id_to_wikidata.csv") diff --git a/tools/python/maps_generator/maps_generator.py b/tools/python/maps_generator/maps_generator.py index 82a923a48b..fd3f7574c2 100644 --- a/tools/python/maps_generator/maps_generator.py +++ b/tools/python/maps_generator/maps_generator.py @@ -227,6 +227,28 @@ def stage_countries_txt(env): f.write(countries) +@stage +def stage_external_resources(env): + resources = [os.path.join(file, env.user_resource_path) + for file in os.listdir(env.user_resource_path) + if file.endswith(".ttf")] + for ttf_file in resources: + shutil.copy2(ttf_file, env.intermediate_path) + + shutil.copy2(os.path.join(env.user_resource_path, "WorldCoasts_obsolete.mwm"), + env.mwm_path) + + for file in os.listdir(env.mwm_path): + if file.startswith(WORLD_NAME) and file.endswith(".mwm"): + resources.append(os.path.join(env.mwm_path, file)) + + resources.sort() + with open(env.external_resources_path, "w") as f: + for resource in resources: + fd = os.open(resource, os.O_RDONLY) + f.write(f"{os.path.basename(resource)} {os.fstat(fd).st_size}") + + @stage def stage_cleanup(env): osm2ft_path = os.path.join(env.out_path, "osm2ft") @@ -250,7 +272,8 @@ STAGES = [s.__name__ for s in (stage_download_external, stage_download_production_external, stage_download_and_convert_planet, stage_update_planet, stage_coastline, stage_preprocess, stage_features, stage_mwm, - stage_descriptions, stage_countries_txt, stage_cleanup)] + stage_descriptions, stage_countries_txt, stage_external_resources, + stage_cleanup)] ALL_STAGES = STAGES + COUNTRIES_STAGES @@ -308,6 +331,7 @@ def generate_maps(env): stage_mwm(env) stage_descriptions(env) stage_countries_txt(env) + stage_external_resources(env) stage_cleanup(env)