MCPcopy Create free account
hub / github.com/comaps/comaps / CfgReader

Class CfgReader

tools/python/maps_generator/generator/settings.py:43–71  ·  view source on GitHub ↗

Config reader. There are 3 way of getting an option. In priority order: 1. From system env. 2. From config. 3. From default values. For using the option from system env you can build an option name as MM__GEN__ + [SECTION_NAME] + _ + [VALUE_NAME].

Source from the content-addressed store, hash-verified

41
42
43class CfgReader:
44 """
45 Config reader.
46 There are 3 way of getting an option. In priority order:
47 1. From system env.
48 2. From config.
49 3. From default values.
50
51 For using the option from system env you can build an option name as
52 MM__GEN__ + [SECTION_NAME] + _ + [VALUE_NAME].
53 """
54
55 def __init__(self, default_settings_path: AnyStr):
56 self.config = ConfigParser(interpolation=ExtendedInterpolation())
57 self.config.read([get_config_path(default_settings_path)])
58
59 def get_opt(self, s: AnyStr, v: AnyStr, default: Any = None):
60 val = CfgReader._get_env_val(s, v)
61 if val is not None:
62 return val
63
64 return self.config.get(s, v) if self.config.has_option(s, v) else default
65
66 def get_opt_path(self, s: AnyStr, v: AnyStr, default: AnyStr = ""):
67 return os.path.expanduser(self.get_opt(s, v, default))
68
69 @staticmethod
70 def _get_env_val(s: AnyStr, v: AnyStr):
71 return os.environ.get(f"MM_GEN__{s.upper()}_{v.upper()}")
72
73
74DEFAULT_PLANET_URL = "https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf"

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected