def load_config(self, path, default=False): if not isinstance(path, Path): path = Path(path) if default: self.load_defaults(path) with path.open() as f: self._raw_config = f.read() self._path = path recursive_dictionary_update(self._config, json.loads(self._raw_config))
def load_config(self, path, default=False): if not isinstance(path, Path): path = Path(path) if default: self.load_defaults(path) try: with path.open() as f: self._raw_config = f.read() except FileNotFoundError: path.touch() with path.open("w") as f: f.write("{}") self._raw_config = "{}" self._path = path recursive_dictionary_update(self._config, json.loads(self._raw_config)) if "plugins" not in self._config: self._config['plugins'] = DotDict({})
def __init__(self): self.loop = asyncio.get_event_loop() self.plugin_config = self.config.get_plugin_config(self.name) if isinstance(self.default_config, collections.Mapping): temp = recursive_dictionary_update(self.default_config, self.plugin_config) self.plugin_config.update(temp) else: self.plugin_config = self.default_config
def load_config(self, path, default=False): if not isinstance(path, Path): path = Path(path) if default: self.load_defaults(path) try: with path.open() as f: self._raw_config = f.read() except FileNotFoundError: path.touch() with path.open("w") as f: f.write("{}") self._raw_config = "{}" self._path = path try: recursive_dictionary_update(self._config, json.loads(self._raw_config)) except ValueError as e: logger.error("Error while loading config.json file:\n\t" "{}".format(e)) sys.exit(1) if "plugins" not in self._config: self._config['plugins'] = DotDict({})
def load_defaults(self, path): path = Path(str(path) + ".default") with path.open() as f: self._raw_default_config = f.read() recursive_dictionary_update(self._config, json.loads(self._raw_default_config))