コード例 #1
0
ファイル: __init__.py プロジェクト: rawder/organicmaps
def init(borders_path=None):
    data_path = find_data_files("omim-data")

    if data_path is None:
        logger.error("omim-data was not found.")
        return False

    if borders_path is None:
        borders_path = os.path.join(data_path, "borders")

    if not os.path.exists(borders_path):
        tar_lzma_path = os.path.join(data_path, "borders.tar.xz")
        lzma_stream = BytesIO()
        with open(tar_lzma_path, mode="rb") as f:
            decompressed = lzma.decompress(f.read())
            lzma_stream.write(decompressed)

        lzma_stream.seek(0)
        try:
            with tarfile.open(fileobj=lzma_stream, mode="r") as tar:
                tar.extractall(borders_path)
        except PermissionError as e:
            logger.error(str(e))
            return False

        logger.info("{} was created.".format(borders_path))

    return True
コード例 #2
0
import os

resource_path = os.path.join(
    os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "data",
)
if not os.path.exists(resource_path):
    from data_files import find_data_files
    resource_path = find_data_files("omim-data")
    assert resource_path is not None


from mwm.feature_types import init as _init

_init(resource_path)

from mwm.feature_types import INDEX_TO_NAME_TYPE_MAPPING
from mwm.feature_types import NAME_TO_INDEX_TYPE_MAPPING
from mwm.feature_types import readable_type
from mwm.feature_types import type_index
from mwm.mwm_interface import GeomType
from mwm.mwm_interface import MapType
from mwm.mwm_interface import MetadataField
from mwm.mwm_interface import Point
from mwm.mwm_interface import Rect
from mwm.mwm_interface import RegionDataField
from mwm.mwm_interface import Triangle
from mwm.mwm_python import get_region_info
from mwm.utils import EnumAsStrEncoder

try:
    from mwm.mwm_pygen import MwmPygen as Mwm
コード例 #3
0
def init(default_settings_path: AnyStr):
    # Try to read a config and to overload default settings
    cfg = CfgReader(default_settings_path)

    # Main section:
    global DEBUG
    global MAIN_OUT_PATH
    global TMPDIR
    _DEBUG = cfg.get_opt("Main", "DEBUG")
    DEBUG = DEBUG if _DEBUG is None else int(_DEBUG)
    MAIN_OUT_PATH = cfg.get_opt_path("Main", "MAIN_OUT_PATH", MAIN_OUT_PATH)
    TMPDIR = cfg.get_opt_path("Main", "TMPDIR", TMPDIR)

    # Developer section:
    global BUILD_PATH
    global OMIM_PATH
    BUILD_PATH = cfg.get_opt_path("Developer", "BUILD_PATH", BUILD_PATH)
    OMIM_PATH = cfg.get_opt_path("Developer", "OMIM_PATH", OMIM_PATH)

    # Osm tools section:
    global OSM_TOOLS_SRC_PATH
    global OSM_TOOLS_PATH
    OSM_TOOLS_SRC_PATH = cfg.get_opt_path("Osm tools", "OSM_TOOLS_SRC_PATH",
                                          OSM_TOOLS_SRC_PATH)
    OSM_TOOLS_PATH = cfg.get_opt_path("Osm tools", "OSM_TOOLS_PATH",
                                      OSM_TOOLS_PATH)

    # Generator tool section:
    global USER_RESOURCE_PATH
    global NODE_STORAGE
    USER_RESOURCE_PATH = cfg.get_opt_path("Generator tool",
                                          "USER_RESOURCE_PATH",
                                          USER_RESOURCE_PATH)
    NODE_STORAGE = cfg.get_opt("Generator tool", "NODE_STORAGE", NODE_STORAGE)

    if not os.path.exists(USER_RESOURCE_PATH):
        from data_files import find_data_files
        USER_RESOURCE_PATH = find_data_files("omim-data")
        assert USER_RESOURCE_PATH is not None

        import borders
        # Issue: If maps_generator is installed in your system as a system
        # package and borders.init() is called first time, call borders.init()
        # might return False, because you need root permission.
        assert borders.init()

    # Stages section:
    global NEED_PLANET_UPDATE
    NEED_PLANET_UPDATE = cfg.get_opt("Stages", "NEED_PLANET_UPDATE",
                                     NEED_PLANET_UPDATE)

    # Logging section:
    global LOG_FILE_PATH
    global LOGGING
    LOG_FILE_PATH = os.path.join(MAIN_OUT_PATH, "generation.log")
    LOG_FILE_PATH = cfg.get_opt_path("Logging", "MAIN_LOG", LOG_FILE_PATH)
    os.makedirs(os.path.dirname(os.path.abspath(LOG_FILE_PATH)), exist_ok=True)
    LOGGING["handlers"]["file"]["filename"] = LOG_FILE_PATH

    # External sction:
    global PLANET_URL
    global PLANET_MD5_URL
    global PLANET_COASTS_URL
    global UGC_URL
    global HOTELS_URL
    global PROMO_CATALOG_CITIES_URL
    global PROMO_CATALOG_COUNTRIES_URL
    global POPULARITY_URL
    global SUBWAY_URL
    global TRANSIT_URL
    global FOOD_URL
    global UK_POSTCODES_URL
    global US_POSTCODES_URL
    global FOOD_TRANSLATIONS_URL
    global SRTM_PATH
    global ISOLINES_PATH

    PLANET_URL = cfg.get_opt_path("External", "PLANET_URL", PLANET_URL)
    PLANET_MD5_URL = cfg.get_opt_path("External", "PLANET_MD5_URL",
                                      PLANET_MD5_URL)
    PLANET_COASTS_URL = cfg.get_opt_path("External", "PLANET_COASTS_URL",
                                         PLANET_COASTS_URL)
    UGC_URL = cfg.get_opt_path("External", "UGC_URL", UGC_URL)
    HOTELS_URL = cfg.get_opt_path("External", "HOTELS_URL", HOTELS_URL)
    PROMO_CATALOG_CITIES_URL = cfg.get_opt_path("External",
                                                "PROMO_CATALOG_CITIES_URL",
                                                PROMO_CATALOG_CITIES_URL)
    PROMO_CATALOG_COUNTRIES_URL = cfg.get_opt_path(
        "External", "PROMO_CATALOG_COUNTRIES_URL", PROMO_CATALOG_COUNTRIES_URL)
    POPULARITY_URL = cfg.get_opt_path("External", "POPULARITY_URL",
                                      POPULARITY_URL)
    SUBWAY_URL = cfg.get_opt("External", "SUBWAY_URL", SUBWAY_URL)
    TRANSIT_URL = cfg.get_opt("External", "TRANSIT_URL", TRANSIT_URL)
    FOOD_URL = cfg.get_opt("External", "FOOD_URL", FOOD_URL)

    UK_POSTCODES_URL = cfg.get_opt("External", "UK_POSTCODES_URL",
                                   UK_POSTCODES_URL)
    US_POSTCODES_URL = cfg.get_opt("External", "US_POSTCODES_URL",
                                   US_POSTCODES_URL)
    FOOD_TRANSLATIONS_URL = cfg.get_opt("External", "FOOD_TRANSLATIONS_URL",
                                        FOOD_TRANSLATIONS_URL)
    SRTM_PATH = cfg.get_opt_path("External", "SRTM_PATH", SRTM_PATH)
    ISOLINES_PATH = cfg.get_opt_path("External", "ISOLINES_PATH",
                                     ISOLINES_PATH)

    # Stats section:
    global STATS_TYPES_CONFIG
    STATS_TYPES_CONFIG = cfg.get_opt_path("Stats", "STATS_TYPES_CONFIG",
                                          STATS_TYPES_CONFIG)

    # Common:
    global THREADS_COUNT
    threads_count = int(cfg.get_opt("Common", "THREADS_COUNT", THREADS_COUNT))
    if threads_count > 0:
        THREADS_COUNT = threads_count

    # Planet and costs:
    global PLANET_COASTS_GEOM_URL
    global PLANET_COASTS_RAWGEOM_URL
    PLANET_COASTS_GEOM_URL = os.path.join(PLANET_COASTS_URL,
                                          "latest_coasts.geom")
    PLANET_COASTS_RAWGEOM_URL = os.path.join(PLANET_COASTS_URL,
                                             "latest_coasts.rawgeom")

    if DEBUG:
        PLANET_URL = "https://www.dropbox.com/s/m3ru5tnj8g9u4cz/planet-latest.o5m?raw=1"
        PLANET_MD5_URL = (
            "https://www.dropbox.com/s/8wdl2hy22jgisk5/planet-latest.o5m.md5?raw=1"
        )
        NODE_STORAGE = "map"
        NEED_PLANET_UPDATE = False