From 08d3fe39d901972e13cc80927b7a2048c51486a7 Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Wed, 26 Jun 2019 13:21:42 +0300 Subject: [PATCH] [generator][python] Supported maps generation without coastlines. --- tools/python/maps_generator/__main__.py | 10 ++++++++-- tools/python/maps_generator/generator/decorators.py | 4 ++-- tools/python/maps_generator/generator/env.py | 4 ++-- tools/python/maps_generator/generator/stages.py | 1 - tools/python/maps_generator/maps_generator.py | 8 +++++--- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/python/maps_generator/__main__.py b/tools/python/maps_generator/__main__.py index 767592bf8b..1ec39dc31b 100644 --- a/tools/python/maps_generator/__main__.py +++ b/tools/python/maps_generator/__main__.py @@ -9,7 +9,7 @@ from .maps_generator import (generate_maps, generate_coasts, reset_to_stage, ALL_STAGES, stage_download_production_external, stage_descriptions, stage_ugc, stage_popularity, stage_localads, stage_statistics, stage_srtm, - stages_as_string) + stages_as_string, stage_coastline) from .utils.collections import unique logger = logging.getLogger("maps_generator") @@ -85,7 +85,7 @@ def parse_options(): "--coasts", default=False, action="store_true", - help="Build WorldCoasts.raw and WorldCoasts.rawgeom files") + help="Build only WorldCoasts.raw and WorldCoasts.rawgeom files") parser.add_argument( "--production", default=False, @@ -199,6 +199,12 @@ def main(): raise SkipError(f"Stages {set(options['skip']) - set(ALL_STAGES)} " f"not found.") + if not (set(stages_as_string(stage_coastline)) - set(options["skip"])): + countries = [x for x in options["countries"] if x in WORLDS_NAMES] + if countries: + raise SkipError(f"Skipped stage {stages_as_string(stage_coastline)}" + f" and countries {countries} are not compatible.") + env = Env(options) if env.from_stage: reset_to_stage(env.from_stage, env) diff --git a/tools/python/maps_generator/generator/decorators.py b/tools/python/maps_generator/generator/decorators.py index e465b686b5..4ee315630e 100644 --- a/tools/python/maps_generator/generator/decorators.py +++ b/tools/python/maps_generator/generator/decorators.py @@ -18,7 +18,7 @@ def stage(func): stage_formatted = " ".join(func_name.split("_")).capitalize() logfile = os.path.join(env.log_path, f"{func_name}.log") log_handler = logging.FileHandler(logfile) - if not env.is_accepted_stage(func_name): + if not env.is_accepted_stage(func): logger.addHandler(log_handler) logger.info(f"{stage_formatted} was not accepted.") return @@ -50,7 +50,7 @@ def country_stage_status(func): if "logger" in countries_meta[country]: _logger = countries_meta[country]["logger"] stage_formatted = " ".join(func_name.split("_")).capitalize() - if not env.is_accepted_stage(func_name): + if not env.is_accepted_stage(func): _logger.info(f"{stage_formatted} was not accepted.") return if "status" not in countries_meta[country]: diff --git a/tools/python/maps_generator/generator/env.py b/tools/python/maps_generator/generator/env.py index b45a043ea2..c58c5fc7f5 100644 --- a/tools/python/maps_generator/generator/env.py +++ b/tools/python/maps_generator/generator/env.py @@ -149,8 +149,8 @@ class Env: existing_names.add(name) return [c for c in self.countries if c in existing_names] - def is_accepted_stage(self, stage_name): - return stage_name not in self._skipped_stages + def is_accepted_stage(self, stage): + return stage.__name__ not in self._skipped_stages @property def descriptions_path(self): diff --git a/tools/python/maps_generator/generator/stages.py b/tools/python/maps_generator/generator/stages.py index a6cf668ca8..ce0a7195ab 100644 --- a/tools/python/maps_generator/generator/stages.py +++ b/tools/python/maps_generator/generator/stages.py @@ -83,7 +83,6 @@ def stage_features(env, **kwargs): dump_cities_boundaries=True, cities_boundaries_data=env.cities_boundaries_path, generate_features=True, - emit_coasts=True, **extra, **kwargs ) diff --git a/tools/python/maps_generator/maps_generator.py b/tools/python/maps_generator/maps_generator.py index 91917897a3..c41fafceba 100644 --- a/tools/python/maps_generator/maps_generator.py +++ b/tools/python/maps_generator/maps_generator.py @@ -75,14 +75,16 @@ def stage_preprocess(env, **kwargs): @stage def stage_features(env): extra = {} - if env.is_accepted_stage(stage_descriptions.__name__): + if env.is_accepted_stage(stage_descriptions): extra["idToWikidata"] = env.id_to_wikidata_path - if env.is_accepted_stage(stage_download_production_external.__name__): + if env.is_accepted_stage(stage_download_production_external): extra["booking_data"] = env.hotels_path extra["promo_catalog_cities"] = env.promo_catalog_cities_path extra["popular_places_data"] = env.popularity_path extra["brands_data"] = env.food_paths extra["brands_translations_data"] = env.food_translations_path + if env.is_accepted_stage(stage_coastline): + extra["emit_coasts"]=True stages.stage_features(env, **extra) if os.path.exists(env.packed_polygons_path): @@ -219,7 +221,7 @@ def stage_countries_txt(env): env.countries_synonyms_path, env.hierarchy_path, env.mwm_path, env.mwm_version) - if env.is_accepted_stage(stage_download_production_external.__name__): + if env.is_accepted_stage(stage_download_production_external): countries_json = json.loads(countries) inject_promo_cities(countries_json, env.promo_catalog_cities_path, env.mwm_path, env.types_path, env.mwm_path)