def load_config_stack(configs=None, cache=False): """ load a stack of config dicts into a single dict Args: configs (list): list of dicts to load cache (boolean): True if result should be cached Returns: merged dict of all configuration files """ if not configs: configs = [LocalConf(DEFAULT_CONFIG), RemoteConf(), LocalConf(SYSTEM_CONFIG), LocalConf(USER_CONFIG), Configuration.__patch] else: # Handle strings in stack for index, item in enumerate(configs): if isinstance(item, str): configs[index] = LocalConf(item) # Merge all configs into one base = {} for c in configs: merge_dict(base, c) # copy into cache if cache: Configuration.__config.clear() for key in base: Configuration.__config[key] = base[key] return Configuration.__config else: return base
def load_config_stack(configs=None, cache=False): """Load a stack of config dicts into a single dict Arguments: configs (list): list of dicts to load cache (boolean): True if result should be cached Returns: (dict) merged dict of all configuration files """ if not configs: configs = [LocalConf(DEFAULT_CONFIG), RemoteConf(), LocalConf(SYSTEM_CONFIG), LocalConf(USER_CONFIG), Configuration.__patch] else: # Handle strings in stack for index, item in enumerate(configs): if isinstance(item, str): configs[index] = LocalConf(item) # Merge all configs into one base = {} for c in configs: merge_dict(base, c) # copy into cache if cache: Configuration.__config.clear() for key in base: Configuration.__config[key] = base[key] return Configuration.__config else: return base
def load_config_stack(configs=None, cache=False, remote=True): """Load a stack of config dicts into a single dict Args: configs (list): list of dicts to load cache (boolean): True if result should be cached remote (boolean): False if the Mycroft Home settings shouldn't be loaded Returns: (dict) merged dict of all configuration files """ if not configs: configs = [] # First use the patched config configs.append(Configuration.__patch) # Then use XDG config # This includes both the user config and # /etc/xdg/mycroft/mycroft.conf for conf_dir in xdg.BaseDirectory.load_config_paths('mycroft'): configs.append(LocalConf(join(conf_dir, 'mycroft.conf'))) # Then check the old user config if isfile(OLD_USER_CONFIG): _log_old_location_deprecation() configs.append(LocalConf(OLD_USER_CONFIG)) # Then use the system config (/etc/mycroft/mycroft.conf) configs.append(LocalConf(SYSTEM_CONFIG)) # Then use remote config if remote: configs.append(RemoteConf()) # Then use the config that comes with the package configs.append(LocalConf(DEFAULT_CONFIG)) # Make sure we reverse the array, as merge_dict will put every new # file on top of the previous one configs = reversed(configs) else: # Handle strings in stack for index, item in enumerate(configs): if isinstance(item, str): configs[index] = LocalConf(item) # Merge all configs into one base = {} for c in configs: merge_dict(base, c) # copy into cache if cache: Configuration.__config.clear() for key in base: Configuration.__config[key] = base[key] return Configuration.__config else: return base
def init(cls): """ Initializes the class, sets the default log level and creates the required handlers. """ # Check configs manually, the Mycroft configuration system can't be # used since it uses the LOG system and would cause horrible cyclic # dependencies. confs = [SYSTEM_CONFIG, USER_CONFIG] config = {} for conf in confs: try: merge_dict(config, load_commented_json(conf) if isfile(conf) else {}) except Exception as e: print('couldn\'t load {}: {}'.format(conf, str(e))) cls.level = logging.getLevelName(config.get('log_level', 'INFO')) log_message_format = ( '{asctime} | {levelname:8} | {process:5} | {name} | {message}') formatter = logging.Formatter(log_message_format, style='{') formatter.default_msec_format = '%s.%03d' cls.handler = logging.StreamHandler(sys.stdout) cls.handler.setFormatter(formatter) # Enable logging in external modules cls.create_logger('').setLevel(cls.level)
def patch(message): """Patch the volatile dict usable by skills Arguments: message: Messagebus message should contain a config in the data payload. """ config = message.data.get("config", {}) merge_dict(Configuration.__patch, config) Configuration.load_config_stack(cache=True)
def patch(message): """ patch the volatile dict usable by skills Args: message: Messagebus message should contain a config in the data payload. """ config = message.data.get("config", {}) merge_dict(Configuration.__patch, config) Configuration.load_config_stack(cache=True)
def init(cls): confs = [SYSTEM_CONFIG, USER_CONFIG] config = {} for conf in confs: merge_dict(config, load_commented_json(conf) if isfile(conf) else {}) cls.level = logging.getLevelName(config.get('log_level', 'DEBUG')) fmt = '%(asctime)s.%(msecs)03d - ' \ '%(name)s - %(levelname)s - %(message)s' datefmt = '%H:%M:%S' formatter = logging.Formatter(fmt, datefmt) cls.handler = logging.StreamHandler(sys.stdout) cls.handler.setFormatter(formatter) cls.create_logger('') # Enables logging in external modules
def init(cls): confs = [SYSTEM_CONFIG, USER_CONFIG] config = {} for conf in confs: try: merge_dict(config, load_commented_json(conf) if isfile(conf) else {}) except Exception as e: print('couldn\'t load {}: {}'.format(conf, str(e))) cls.level = logging.getLevelName(config.get('log_level', 'INFO')) fmt = '%(asctime)s.%(msecs)03d - ' \ '%(name)s - %(levelname)s - %(message)s' datefmt = '%H:%M:%S' formatter = logging.Formatter(fmt, datefmt) cls.handler = logging.StreamHandler(sys.stdout) cls.handler.setFormatter(formatter) # Enable logging in external modules cls.create_logger('').setLevel(cls.level)
def merge(self, conf): merge_dict(self, conf)
def merge(self, conf): merge_dict(self, conf)