def check_config_file_version(filename): """Checks to see if the version of the file name passed matches the config version MPF needs. Args: filename: The file with path to check. Raises: exception if the version of the file doesn't match what MPF needs. """ filename = FileManager.locate_file(filename) file_interface = FileManager.get_file_interface(filename) file_version = file_interface.get_config_file_version(filename) if file_version != int(version.__config_version__): log.error("Config file %s is version %s. MPF %s requires " "version %s", filename, file_version, version.__version__, version.__config_version__) log.error("Use the Config File Migrator to automatically " "migrate your config file to the latest version.") log.error("Migration tool: " "https://missionpinball.com/docs/tools/config-file-migrator/") log.error("More info on config version %s: %s", version.__config_version__, version.__config_version_url__) return False else: return True
def _writing_thread(self, delay_secs=0): if delay_secs: time.sleep(delay_secs) self.log.debug("Writing %s to: %s", self.name, self.filename) FileManager.save(self.filename, self.data) # The MIT License (MIT) # Copyright (c) 2013-2015 Brian Madden and Gabe Knuth # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE.
def check_config_file_version(filename): """Checks to see if the version of the file name passed matches the config version MPF needs. Args: filename: The file with path to check. Raises: exception if the version of the file doesn't match what MPF needs. """ filename = FileManager.locate_file(filename) file_interface = FileManager.get_file_interface(filename) file_version = file_interface.get_config_file_version(filename) if file_version != int(version.__config_version__): log.error( "Config file %s is version %s. MPF %s requires " "version %s", filename, file_version, version.__version__, version.__config_version__) log.error("Use the Config File Migrator to automatically " "migrate your config file to the latest version.") log.error( "Migration tool: " "https://missionpinball.com/docs/tools/config-file-migrator/") log.error("More info on config version %s: %s", version.__config_version__, version.__config_version_url__) return False else: return True
def load_config(): global previous_config_version global new_config_version global section_deprecations global section_replacements global section_warnings global string_replacements config_dict = FileManager.load(CONFIG_VERSION_FILE) for key in config_dict.keys(): if type(key) is not int: del config_dict[key] # todo could add support for command line param to specify version new_config_version = max(config_dict) previous_config_version = new_config_version-1 print print ("Migrating MPF config files from v" + str(previous_config_version) + " to v" + str(new_config_version)) target_file_versions.add(previous_config_version) if options['force']: print ("Will also re-check v" + str(new_config_version) + " files") target_file_versions.add(new_config_version) section_replacements = config_dict[new_config_version].get('section_replacements', dict()) section_warnings = config_dict[new_config_version].get('section_warnings', dict()) section_deprecations = config_dict[new_config_version].get('section_deprecations', dict()) string_replacements = config_dict[new_config_version].get('string_replacements', dict())
def _load(self): self.log.debug("Loading %s from %s", self.name, self.filename) if os.path.isfile(self.filename): self.data = FileManager.load(self.filename, halt_on_error=False) else: self.log.debug("Didn't find the %s file. No prob. We'll create " "it when we save.", self.name)
def _load(self): self.log.debug("Loading %s from %s", self.name, self.filename) if os.path.isfile(self.filename): self.data = FileManager.load(self.filename, halt_on_error=False) else: self.log.debug( "Didn't find the %s file. No prob. We'll create " "it when we save.", self.name)
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
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')
def _load_config_file(self, filename, verify_version=True, halt_on_error=True): config_file = MPFConfigFile(filename, FileManager.load(filename, verify_version, halt_on_error, True)) try: if 'config' in config_file.config: path = os.path.split(filename)[0] for file in Util.string_to_list(config_file.config['config']): full_file = os.path.join(path, file) new_config = self._load_config_file(full_file) config_file.add_child_file(new_config) return config_file except TypeError: return dict()
def load_config(): global previous_config_version global new_config_version global section_deprecations global section_replacements global section_warnings global string_replacements config_dict = FileManager.load(CONFIG_VERSION_FILE) for key in config_dict.keys(): if type(key) is not int: del config_dict[key] # todo could add support for command line param to specify version new_config_version = max(config_dict) previous_config_version = new_config_version - 1 print print("Migrating MPF config files from v" + str(previous_config_version) + " to v" + str(new_config_version)) target_file_versions.add(previous_config_version) if options['force']: print("Will also re-check v" + str(new_config_version) + " files") target_file_versions.add(new_config_version) section_replacements = config_dict[new_config_version].get( 'section_replacements', dict()) section_warnings = config_dict[new_config_version].get( 'section_warnings', dict()) section_deprecations = config_dict[new_config_version].get( 'section_deprecations', dict()) string_replacements = config_dict[new_config_version].get( 'string_replacements', dict())
def __init__(self, options): self.options = options self.log = logging.getLogger("Machine") self.log.info("Mission Pinball Framework v%s", version.__version__) self.log.debug("Command line arguments: {}".format(self.options)) self.verify_system_info() self.loop_start_time = 0 self.tick_num = 0 self.done = False self.machine_path = None # Path to this machine's folder root self.monitors = dict() self.plugins = list() self.scriptlets = list() self.modes = list() self.asset_managers = dict() self.game = None self.active_debugger = dict() self.machine_vars = CaseInsensitiveDict() self.machine_var_monitor = False self.machine_var_data_manager = None self.flag_bcp_reset_complete = False self.asset_loader_complete = False self.delay = DelayManager() self.crash_queue = Queue.Queue() Task.create(self._check_crash_queue) FileManager.init() self.config = dict() self._load_mpf_config() self._set_machine_path() self._load_machine_config() self.configure_debugger() self.hardware_platforms = dict() self.default_platform = None if not self.options['force_platform']: for section, platform in self.config['hardware'].iteritems(): if platform.lower() != 'default' and section != 'driverboards': self.add_platform(platform) self.set_default_platform(self.config['hardware']['platform']) else: self.add_platform(self.options['force_platform']) self.set_default_platform(self.options['force_platform']) # Do this here so there's a credit_string var even if they're not using # the credits mode try: credit_string = self.config['credits']['free_play_string'] except KeyError: credit_string = 'FREE PLAY' self.create_machine_var('credits_string', credit_string, silent=True) self._load_system_modules() # This is called so hw platforms have a change to register for events, # and/or anything else they need to do with system modules since # they're not set up yet when the hw platforms are constructed. for platform in self.hardware_platforms.values(): platform.initialize() self.validate_machine_config_section('machine') self.validate_machine_config_section('timing') self.validate_machine_config_section('hardware') self.validate_machine_config_section('game') self._register_system_events() self._load_machine_vars() self.events.post("init_phase_1") self.events._process_event_queue() self.events.post("init_phase_2") self.events._process_event_queue() self._load_plugins() self.events.post("init_phase_3") self.events._process_event_queue() self._load_scriptlets() self.events.post("init_phase_4") self.events._process_event_queue() self.events.post("init_phase_5") self.events._process_event_queue() self.reset()
def save_tree_to_file(self, filename): print "Exporting file..." FileManager.save(filename, self.collections) print "Export complete!"
def load_show_from_disk(self): return FileManager.load(self.file_name)
def __init__(self, options): self.options = options self.log = logging.getLogger("MediaController") self.log.debug("Command line arguments: {}".format(self.options)) self.log.info("Media Controller Version %s", version.__version__) self.log.debug("Backbox Control Protocol Version %s", version.__bcp_version__) self.log.debug("Config File Version %s", version.__config_version__) python_version = sys.version_info if python_version[0] != 2 or python_version[1] != 7: self.log.error("Incorrect Python version. MPF requires Python 2.7." "x. You have Python %s.%s.%s.", python_version[0], python_version[1], python_version[2]) sys.exit() self.log.debug("Python version: %s.%s.%s", python_version[0], python_version[1], python_version[2]) self.log.debug("Platform: %s", sys.platform) self.log.debug("Python executable location: %s", sys.executable) self.log.debug("32-bit Python? %s", sys.maxsize < 2**32) self.active_debugger = dict() self.config = dict() self.done = False # todo self.machine_path = None self.asset_managers = dict() self.window = None self.window_manager = None self.pygame = False self.pygame_requested = False self.registered_pygame_handlers = dict() self.pygame_allowed_events = list() self.socket_thread = None self.receive_queue = Queue.Queue() self.sending_queue = Queue.Queue() self.crash_queue = Queue.Queue() self.modes = CaseInsensitiveDict() self.player_list = list() self.player = None self.HZ = 0 self.next_tick_time = 0 self.secs_per_tick = 0 self.machine_vars = CaseInsensitiveDict() self.machine_var_monitor = False self.tick_num = 0 self.delay = DelayManager() self._pc_assets_to_load = 0 self._pc_total_assets = 0 self.pc_connected = False Task.create(self._check_crash_queue) self.bcp_commands = {'ball_start': self.bcp_ball_start, 'ball_end': self.bcp_ball_end, 'config': self.bcp_config, 'error': self.bcp_error, 'get': self.bcp_get, 'goodbye': self.bcp_goodbye, 'hello': self.bcp_hello, 'machine_variable': self.bcp_machine_variable, 'mode_start': self.bcp_mode_start, 'mode_stop': self.bcp_mode_stop, 'player_added': self.bcp_player_add, 'player_score': self.bcp_player_score, 'player_turn_start': self.bcp_player_turn_start, 'player_variable': self.bcp_player_variable, 'reset': self.reset, 'set': self.bcp_set, 'shot': self.bcp_shot, 'switch': self.bcp_switch, 'timer': self.bcp_timer, 'trigger': self.bcp_trigger, } FileManager.init() self.config = dict() self._load_mc_config() self._set_machine_path() self._load_machine_config() # Find the machine_files location. If it starts with a forward or # backward slash, then we assume it's from the mpf root. Otherwise we # assume it's from the subfolder location specified in the # mpfconfig file location if (options['machine_path'].startswith('/') or options['machine_path'].startswith('\\')): machine_path = options['machine_path'] else: machine_path = os.path.join(self.config['media_controller']['paths'] ['machine_files'], options['machine_path']) self.machine_path = os.path.abspath(machine_path) # Add the machine folder to our path so we can import modules from it sys.path.append(self.machine_path) self.log.info("Machine folder: %s", machine_path) mediacontroller_config_spec = ''' exit_on_disconnect: boolean|True port: int|5050 ''' self.config['media_controller'] = ( Config.process_config(mediacontroller_config_spec, self.config['media_controller'])) self.events = EventManager(self, setup_event_player=False) self.timing = Timing(self) # Load the media controller modules self.config['media_controller']['modules'] = ( self.config['media_controller']['modules'].split(' ')) self.log.info("Loading Modules...") for module in self.config['media_controller']['modules']: self.log.debug("Loading module: %s", module) module_parts = module.split('.') exec('self.' + module_parts[0] + '=' + module + '(self)') # todo there's probably a more pythonic way to do this, and I know # exec() is supposedly unsafe, but meh, if you have access to put # malicious files in the system folder then you have access to this # code too. self.start_socket_thread() self.events.post("init_phase_1") self.events._process_event_queue() self.events.post("init_phase_2") self.events._process_event_queue() self.events.post("init_phase_3") self.events._process_event_queue() self.events.post("init_phase_4") self.events._process_event_queue() self.events.post("init_phase_5") self.events._process_event_queue() self.reset()