示例#1
0
    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)
示例#2
0
    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)
示例#3
0
文件: machine.py 项目: HarryXS/mpf
    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))
示例#4
0
    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['media_controller']['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))
    def __init__(self, options):
        self.options = options
        self.log = logging.getLogger('machinewizard')
        self.log.info("MPF Wizard v%s", version.__version__)
        self.log.debug("Init Options: {}".format(self.options))
        self.verify_system_info()

        self.done = False
        self.machine_path = None  # Path to this machine's folder root

        FileManager.init()

        self.mpfconfig = dict()
        self.mpfconfig = Config.load_config_file(self.options['mpfconfigfile'])

        self.config_files = dict()
        #self.config = Config.load_config_file(self.options['mpfconfigfile'])
        self._set_machine_path()
        self._load_config_from_files()
        
        self.log.info('machine config loaded')
示例#6
0
    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
示例#7
0
 def _load_mpf_config(self):
     self.config = Config.load_config_file(self.options['mpfconfigfile'])
示例#8
0
文件: machine.py 项目: HarryXS/mpf
 def _load_mpf_config(self):
     self.config = Config.load_config_file(self.options['mpfconfigfile'])
    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. First check the machine folder/modes,
        # if that's not a valid folder, check the mpf/modes folder.
        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

        # Figure out where the code is for this mode.

        # If a custom 'code' setting exists, first look in the machine folder
        # for it, and if it's not there, then look in mpf/modes for it.

        if 'code' in config['mode']:
            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