コード例 #1
0
def build_coastline(**kwargs):
    env = Env()
    kwargs["ti"].xcom_push(key="build_name", value=env.build_name)

    run_generation(
        env,
        (
            sd.StageDownloadAndConvertPlanet(),
            sd.StageCoastline(use_old_if_fail=False),
            sd.StageCleanup(),
        ),
    )
    env.finish()
コード例 #2
0
def update_planet(**kwargs):
    env = Env()
    kwargs["ti"].xcom_push(key="build_name", value=env.build_name)

    if settings.DEBUG:
        env.add_skipped_stage(sd.StageUpdatePlanet)

    run_generation(
        env,
        (
            sd.StageDownloadAndConvertPlanet(),
            sd.StageUpdatePlanet(),
            sd.StageCleanup(),
        ),
    )
    env.finish()
コード例 #3
0
ファイル: build_maps.py プロジェクト: dualword/dualword-maps
 def build_epilog(**kwargs):
     build_name = kwargs["ti"].xcom_pull(key="build_name")
     params = MapsGenerationDAG.get_params(**kwargs)
     params.update({"build_name": build_name})
     env = Env(**params)
     run_generation_from_first_stage(
         env,
         (
             sd.StageCountriesTxt(),
             sd.StageExternalResources(),
             sd.StageLocalAds(),
             sd.StageStatistics(),
             sd.StageCleanup(),
         ),
     )
     env.finish()
コード例 #4
0
def main():
    root = logging.getLogger()
    root.addHandler(logging.NullHandler())
    options = parse_options()

    # Processing of 'continue' option.
    # 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"])
        if d is None:
            raise ContinueError(
                "The build cannot continue: the last build " "directory was not found."
            )
        build_name = d

    # Processing of 'countries' option.
    # There is processing 'countries' and 'without_countries' options.
    # Option 'without_countries' has more priority than 'countries'.
    # Options 'countries' and 'without_countries' can include '*'.
    # For example: '--countries="UK*, Japan"*' means
    # '--countries="UK_England_East Midlands, UK_England_East of England_Essex, ...,
    # Japan_Chubu Region_Aichi_Nagoya, Japan_Chubu Region_Aichi_Toyohashi, ..."'.
    countries_line = ""
    without_countries_line = ""
    if "COUNTRIES" in os.environ:
        countries_line = os.environ["COUNTRIES"]
    if options["countries"]:
        countries_line = options["countries"]
    else:
        countries_line = "*"

    if options["without_countries"]:
        without_countries_line = options["without_countries"]

    all_countries = get_all_countries_list(PathProvider.borders_path())

    def end_star_compare(prefix, full):
        return full.startswith(prefix)

    def compare(a, b):
        return a == b

    def get_countries_set_from_line(line):
        countries = []
        used_countries = set()
        countries_list = []
        if os.path.isfile(line):
            with open(line) as f:
                countries_list = [x.strip() for x in f]
        elif line:
            countries_list = [x.strip() for x in line.replace(";", ",").split(",")]

        for country_item in countries_list:
            cmp = compare
            _raw_country = country_item[:]
            if _raw_country and _raw_country[-1] == "*":
                _raw_country = _raw_country.replace("*", "")
                cmp = end_star_compare

            for country in all_countries:
                if cmp(_raw_country, country):
                    used_countries.add(country_item)
                    countries.append(country)

        countries = unique(countries)
        diff = set(countries_list) - used_countries
        if diff:
            raise ValidationError(f"Bad input countries {', '.join(diff)}")
        return set(countries)

    countries = get_countries_set_from_line(countries_line)
    without_countries = get_countries_set_from_line(without_countries_line)
    countries -= without_countries
    countries = list(countries)
    if not countries:
        countries = all_countries

    # Processing of 'order' option.
    # It defines an order of countries generation using a file from 'order' path.
    if options["order"]:
        ordered_countries = []
        countries = set(countries)
        with open(options["order"]) as file:
            for c in file:
                if c.strip().startswith("#"):
                    continue
                c = c.split("\t")[0].strip()
                if c in countries:
                    ordered_countries.append(c)
                    countries.remove(c)
            if countries:
                raise ValueError(
                    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(","):
            stage = s.strip()
            if not stages.stages.is_valid_stage_name(stage):
                raise SkipError(f"{stage} not found.")
            skipped_stages.add(stages.get_stage_type(stage))

    if settings.PLANET_URL != settings.DEFAULT_PLANET_URL:
        skipped_stages.add(sd.StageUpdatePlanet)

    if sd.StageCoastline in skipped_stages:
        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}."
                f" You can exclude them with --without_countries option."
            )

    if not settings.NEED_PLANET_UPDATE:
        skipped_stages.add(sd.StageUpdatePlanet)

    # Make env and run maps generation.
    env = Env(
        countries=countries,
        production=options["production"],
        build_name=build_name,
        skipped_stages=skipped_stages,
    )
    from_stage = None
    if options["from_stage"]:
        from_stage = f"{options['from_stage']}"
    if options["coasts"]:
        generate_coasts(env, from_stage)
    else:
        generate_maps(env, from_stage)
    env.finish()