diff --git a/tools/python/maps_generator/README.md b/tools/python/maps_generator/README.md index 5990522b58..9ebaab12cd 100644 --- a/tools/python/maps_generator/README.md +++ b/tools/python/maps_generator/README.md @@ -140,6 +140,8 @@ optional arguments: -c [CONTINUE], --continue [CONTINUE] Continue the last build or specified in CONTINUE from the last stopped stage. + -s SUFFIX, --suffix SUFFIX + Suffix the name of a build directory. --countries COUNTRIES List of regions, separated by a comma or a semicolon, or path to file with regions, separated by a line diff --git a/tools/python/maps_generator/__main__.py b/tools/python/maps_generator/__main__.py index 10d6be4f43..86856e3720 100644 --- a/tools/python/maps_generator/__main__.py +++ b/tools/python/maps_generator/__main__.py @@ -86,6 +86,13 @@ def parse_options(): help="Continue the last build or specified in CONTINUE from the " "last stopped stage.", ) + parser.add_argument( + "-s", + "--suffix", + default="", + type=str, + help="Suffix of the name of a build directory.", + ) parser.add_argument( "--countries", type=str, @@ -139,7 +146,7 @@ def parse_options(): ), help="Mwm generation order.", ) - return vars(parser.parse_args()) + return parser.parse_args() def main(): @@ -151,8 +158,9 @@ def main(): # If 'continue' is set maps generation is continued from the last build # that is found automatically. build_name = None - if options["continue"] is None or options["continue"]: - d = find_last_build_dir(options["continue"]) + continue_ = getattr(options, "continue") + if continue_ is None or continue_: + d = find_last_build_dir(continue_) if d is None: raise ContinueError( "The build cannot continue: the last build " "directory was not found." @@ -170,13 +178,13 @@ def main(): without_countries_line = "" if "COUNTRIES" in os.environ: countries_line = os.environ["COUNTRIES"] - if options["countries"]: - countries_line = options["countries"] + if options.countries: + countries_line = options.countries else: countries_line = "*" - if options["without_countries"]: - without_countries_line = options["without_countries"] + if options.without_countries: + without_countries_line = options.without_countries all_countries = get_all_countries_list(PathProvider.borders_path()) @@ -223,10 +231,10 @@ def main(): # Processing of 'order' option. # It defines an order of countries generation using a file from 'order' path. - if options["order"]: + if options.order: ordered_countries = [] countries = set(countries) - with open(options["order"]) as file: + with open(options.order) as file: for c in file: if c.strip().startswith("#"): continue @@ -236,14 +244,14 @@ def main(): countries.remove(c) if countries: raise ValueError( - f"{options['order']} does not have an order " f"for {countries}." + f"{options.order} does not have an order " f"for {countries}." ) countries = ordered_countries # Processing of 'skip' option. skipped_stages = set() - if options["skip"]: - for s in options["skip"].replace(";", ",").split(","): + if options.skip: + for s in options.skip.replace(";", ",").split(","): stage = s.strip() if not stages.stages.is_valid_stage_name(stage): raise SkipError(f"{stage} not found.") @@ -253,7 +261,7 @@ def main(): skipped_stages.add(sd.StageUpdatePlanet) if sd.StageCoastline in skipped_stages: - if any(x in WORLDS_NAMES for x in options["countries"]): + if any(x in WORLDS_NAMES for x in options.countries): raise SkipError( f"You can not skip {stages.get_stage_name(sd.StageCoastline)}" f" if you want to generate {WORLDS_NAMES}." @@ -266,14 +274,15 @@ def main(): # Make env and run maps generation. env = Env( countries=countries, - production=options["production"], + production=options.production, build_name=build_name, + build_suffix=options.suffix, skipped_stages=skipped_stages, ) from_stage = None - if options["from_stage"]: - from_stage = f"{options['from_stage']}" - if options["coasts"]: + if options.from_stage: + from_stage = f"{options.from_stage}" + if options.coasts: generate_coasts(env, from_stage) else: generate_maps(env, from_stage) diff --git a/tools/python/maps_generator/generator/env.py b/tools/python/maps_generator/generator/env.py index 568f404036..3827c61c20 100644 --- a/tools/python/maps_generator/generator/env.py +++ b/tools/python/maps_generator/generator/env.py @@ -346,6 +346,7 @@ class Env: countries: Optional[List[AnyStr]] = None, production: bool = False, build_name: Optional[AnyStr] = None, + build_suffix: AnyStr = "", skipped_stages: Optional[Set[Type[Stage]]] = None, ): self.setup_logging() @@ -366,18 +367,24 @@ class Env: self.node_storage = settings.NODE_STORAGE version_format = "%Y_%m_%d__%H_%M_%S" + suffix_div = "-" dt = None if build_name is None: dt = datetime.datetime.now() build_name = dt.strftime(version_format) + if build_suffix: + build_name = f"{build_name}{suffix_div}{build_suffix}" else: - dt = datetime.datetime.strptime(build_name, version_format) + date_str, build_suffix = build_name.split(suffix_div, maxsplit=1) + dt = datetime.datetime.strptime(date_str, version_format) + self.build_suffix = build_suffix self.mwm_version = dt.strftime("%y%m%d") self.planet_version = dt.strftime("%s") self.build_path = os.path.join(settings.MAIN_OUT_PATH, build_name) self.build_name = build_name + logger.info(f"Build name is {self.build_name}.") logger.info(f"Build path is {self.build_path}.") self.paths = PathProvider(self.build_path, self.mwm_version)