Пример #1
0
    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)
Пример #2
0
    def add_options(self, **options):
        if "logger" in options:
            self.logger = options["logger"]

        for k, v in options.items():
            if k == "logger":
                continue

            if k not in GenTool.OPTIONS:
                raise OptionNotFound(f"{k} is unavailable option")

            if type(v) is not GenTool.OPTIONS[k]:
                raise ValidationError(
                    f"{k} required {str(GenTool.OPTIONS[k])},"
                    f" but not {str(type(v))}")

            self.options[k] = str(v).lower() if type(v) is bool else v
        return self
Пример #3
0
def step_download_and_convert_planet(env: Env, force_download: bool, **kwargs):
    if force_download or not is_verified(env.paths.planet_osm_pbf):
        download_files(
            {
                settings.PLANET_URL: env.paths.planet_osm_pbf,
                settings.PLANET_MD5_URL: md5_ext(env.paths.planet_osm_pbf),
            },
            env.force_download_files,
        )

        if not is_verified(env.paths.planet_osm_pbf):
            raise ValidationError(f"Wrong md5 sum for {env.paths.planet_osm_pbf}.")

    convert_planet(
        env[settings.OSM_TOOL_CONVERT],
        env.paths.planet_osm_pbf,
        env.paths.planet_o5m,
        output=env.get_subprocess_out(),
        error=env.get_subprocess_out(),
    )
    os.remove(env.paths.planet_osm_pbf)
    os.remove(md5_ext(env.paths.planet_osm_pbf))