当前位置: 首页>>代码示例>>Python>>正文


Python Util.dict_merge方法代码示例

本文整理汇总了Python中mpf.system.utility_functions.Util.dict_merge方法的典型用法代码示例。如果您正苦于以下问题:Python Util.dict_merge方法的具体用法?Python Util.dict_merge怎么用?Python Util.dict_merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpf.system.utility_functions.Util的用法示例。


在下文中一共展示了Util.dict_merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_config_file

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def load_config_file(filename, verify_version=True, halt_on_error=True):
        config = FileManager.load(filename, verify_version, halt_on_error)

        if 'config' in config:
            path = os.path.split(filename)[0]

            for file in Util.string_to_list(config['config']):
                full_file = os.path.join(path, file)
                config = Util.dict_merge(config,
                                           Config.load_config_file(full_file))
        return config
开发者ID:HarryXS,项目名称:mpf,代码行数:13,代码来源:config.py

示例2: _load_machine_config

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def _load_machine_config(self):
        for num, config_file in enumerate(self.options['configfile']):

            if not (config_file.startswith('/') or
                    config_file.startswith('\\')):

                config_file = os.path.join(self.machine_path,
                    self.config['mpf']['paths']['config'], config_file)

            self.log.info("Machine config file #%s: %s", num+1, config_file)

            self.config = Util.dict_merge(self.config,
                Config.load_config_file(config_file))
开发者ID:HarryXS,项目名称:mpf,代码行数:15,代码来源:machine.py

示例3: _load_mode

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def _load_mode(self, mode_string):
        """Loads a mode, reads in its config, and creates the Mode object.

        Args:
            mode: String name of the mode you're loading. This is the name of
                the mode's folder in your game's machine_files/modes folder.

        """
        self.log.debug('Processing mode: %s', mode_string)

        config = dict()

        # find the folder for this mode:
        mode_path = os.path.join(self.machine.machine_path,
            self.machine.config['media_controller']['paths']['modes'], mode_string)

        if not os.path.exists(mode_path):
            mode_path = os.path.abspath(os.path.join('mpf', self.machine.config['media_controller']['paths']['modes'], mode_string))

        # Is there an MPF default config for this mode? If so, load it first
        mpf_mode_config = os.path.join(
            'mpf',
            self.machine.config['media_controller']['paths']['modes'],
            mode_string,
            'config',
            mode_string + '.yaml')

        if os.path.isfile(mpf_mode_config):
            config = Config.load_config_file(mpf_mode_config)

        # Now figure out if there's a machine-specific config for this mode, and
        # if so, merge it into the config

        mode_config_folder = os.path.join(self.machine.machine_path,
            self.machine.config['media_controller']['paths']['modes'], mode_string, 'config')

        found_file = False
        for path, _, files in os.walk(mode_config_folder):
            for file in files:
                file_root, file_ext = os.path.splitext(file)

                if file_root == mode_string:
                    config = Util.dict_merge(config,
                        Config.load_config_file(os.path.join(path, file)))
                    found_file = True
                    break

            if found_file:
                break

        return Mode(self.machine, config, mode_string, mode_path)
开发者ID:HarryXS,项目名称:mpf,代码行数:53,代码来源:mode_controller.py

示例4: _get_merged_settings

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def _get_merged_settings(self, section_name):
        # Returns a dict_merged dict of a config section from the machine-wide
        # config with the mode-specific config merged in.

        if section_name in self.machine.config:
            return_dict = copy.deepcopy(self.machine.config[section_name])
        else:
            return_dict = CaseInsensitiveDict()

        if section_name in self.config:
            return_dict = Util.dict_merge(return_dict,
                                          self.config[section_name],
                                          combine_lists=False)

        return return_dict
开发者ID:HarryXS,项目名称:mpf,代码行数:17,代码来源:mode.py

示例5: process_config

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def process_config(config_spec, source, target=None):
        config_spec = yaml.load(config_spec)
        processed_config = source

        for k in config_spec.keys():
            if k in source:
                processed_config[k] = Config.validate_config_item(
                    config_spec[k], source[k])
            else:
                log.debug('Processing default settings for key "%s:"', k)
                processed_config[k] = Config.validate_config_item(
                    config_spec[k])

        if target:
            processed_config = Util.dict_merge(target, processed_config)

        return processed_config
开发者ID:qcapen,项目名称:mpf,代码行数:19,代码来源:config.py

示例6: _load_mode

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def _load_mode(self, mode_string):
        """Loads a mode, reads in its config, and creates the Mode object.

        Args:
            mode: String name of the mode you're loading. This is the name of
                the mode's folder in your game's machine_files/modes folder.

        """
        if self.debug:
            self.log.debug('Processing mode: %s', mode_string)

        config = dict()

        # find the folder for this mode:
        mode_path = os.path.join(self.machine.machine_path,
            self.machine.config['mpf']['paths']['modes'], mode_string)

        if not os.path.exists(mode_path):
            mode_path = os.path.abspath(os.path.join('mpf', self.machine.config['mpf']['paths']['modes'], mode_string))


        # Is there an MPF default config for this mode? If so, load it first
        mpf_mode_config = os.path.join(
            'mpf',
            self.machine.config['mpf']['paths']['modes'],
            mode_string,
            'config',
            mode_string + '.yaml')

        if os.path.isfile(mpf_mode_config):
            config = Config.load_config_file(mpf_mode_config)

        # Now figure out if there's a machine-specific config for this mode, and
        # if so, merge it into the config

        mode_config_folder = os.path.join(self.machine.machine_path,
            self.machine.config['mpf']['paths']['modes'], mode_string, 'config')

        found_file = False
        for path, _, files in os.walk(mode_config_folder):
            for file in files:
                file_root, file_ext = os.path.splitext(file)

                if file_root == mode_string:
                    config = Util.dict_merge(config,
                        Config.load_config_file(os.path.join(path, file)))
                    found_file = True
                    break

            if found_file:
                break

        if 'code' in config['mode']:

            # need to figure out if this mode code is in the machine folder or
            # the default mpf folder

            mode_code_file = os.path.join(self.machine.machine_path,
                self.machine.config['mpf']['paths']['modes'],
                mode_string,
                'code',
                config['mode']['code'].split('.')[0] + '.py')

            if os.path.isfile(mode_code_file):  # code is in the machine folder
                import_str = (self.machine.config['mpf']['paths']['modes'] +
                              '.' + mode_string + '.code.' +
                              config['mode']['code'].split('.')[0])
                i = __import__(import_str, fromlist=[''])

                if self.debug:
                    self.log.debug("Loading Mode class code from %s",
                                   mode_code_file)

                mode_object = getattr(i, config['mode']['code'].split('.')[1])(
                    self.machine, config, mode_string, mode_path)

            else:  # code is in the mpf folder
                import_str = ('mpf.' +
                              self.machine.config['mpf']['paths']['modes'] +
                              '.' + mode_string + '.code.' +
                              config['mode']['code'].split('.')[0])
                i = __import__(import_str, fromlist=[''])

                if self.debug:
                    self.log.debug("Loading Mode class code from %s",
                                   import_str)

                mode_object = getattr(i, config['mode']['code'].split('.')[1])(
                    self.machine, config, mode_string, mode_path)

        else:  # no code specified, so using the default Mode class
            if self.debug:
                self.log.debug("Loading default Mode class code")
            mode_object = Mode(self.machine, config, mode_string, mode_path)

        return mode_object
开发者ID:qcapen,项目名称:mpf,代码行数:98,代码来源:mode_controller.py

示例7: process_config2

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
    def process_config2(self, config_spec, source, section_name=None,
                        target=None, result_type='dict'):
        # config_spec, str i.e. "device:shot"
        # source is dict
        # section_name is str used for logging failures

        if not section_name:
            section_name = config_spec

        validation_failure_info = (config_spec, section_name)

        orig_spec = config_spec

        config_spec = config_spec.split(':')
        this_spec = self.machine.config['config_validator']

        for i in range(len(config_spec)):
            this_spec = this_spec[config_spec[i]]

        self.check_for_invalid_sections(this_spec, source,
                                        validation_failure_info)

        processed_config = source

        for k in this_spec.keys():
            if k in source:  # validate the entry that exists

                if type(this_spec[k]) is dict:
                    # This means we're looking for a list of dicts

                    final_list = list()
                    if k in source:
                        for i in source[k]:  # individual step
                            final_list.append(self.process_config2(
                                orig_spec + ':' + k, source=i, section_name=k))

                    processed_config[k] = final_list

                elif result_type == 'list':
                    # spec is dict
                    # item is source
                    processed_config = self.validate_config_item2(
                        spec=this_spec[k], item=source[k],
                        validation_failure_info=(validation_failure_info, k))

                else:
                    processed_config[k] = self.validate_config_item2(
                        this_spec[k], item=source[k],
                        validation_failure_info=(validation_failure_info, k))

            else:  # create the default entry

                if type(this_spec[k]) is dict:
                    processed_config[k] = list()

                else:
                    if result_type == 'list':
                        processed_config = self.validate_config_item2(
                            this_spec[k],
                            validation_failure_info=(validation_failure_info,
                                                     k))

                    else:
                        processed_config[k] = self.validate_config_item2(
                            this_spec[k],
                            validation_failure_info=(validation_failure_info,
                                                     k))

        if target:
            processed_config = Util.dict_merge(target, processed_config)

        #if result_type == 'list':
            #quit()

        return processed_config
开发者ID:qcapen,项目名称:mpf,代码行数:77,代码来源:config.py

示例8: get_merged_config

# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import dict_merge [as 别名]
 def get_merged_config(self):
     merged_config = self.config
     for key in self.child_files:
         merged_config = Util.dict_merge(merged_config, self.child_files[key].get_merged_config())
     
     return merged_config
开发者ID:missionpinball,项目名称:mpf-wizard,代码行数:8,代码来源:config_storage.py


注:本文中的mpf.system.utility_functions.Util.dict_merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。