Skip to content

Commit

Permalink
Merge pull request #1107 from avanwinkle/config-processor-expected-ve…
Browse files Browse the repository at this point in the history
…rsion

Common method for expecting config/show version tag
  • Loading branch information
jabdoa2 committed Feb 28, 2018
2 parents a59bdba + 12a0c8e commit 9474b74
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mpf/core/config_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ def _load_config_file_and_return_loaded_files(
"""Load a config file and return loaded files."""
# config_type is str 'machine' or 'mode', which specifies whether this
# file being loaded is a machine config or a mode config file
if config_type in ("machine", "mode"):
expected_version_str = "#config_version={}".format(__config_version__)
elif config_type == "show":
expected_version_str = "#show_version={}".format(__show_version__)
else:
raise AssertionError("Invalid config_type {}".format(config_type))
expected_version_str = ConfigProcessor.get_expected_version(config_type)

config = FileManager.load(filename, expected_version_str, True)
subfiles = []
Expand Down Expand Up @@ -175,7 +170,8 @@ def load_config_file(filename, config_type: str,
"""Load a config file."""
# config_type is str 'machine' or 'mode', which specifies whether this
# file being loaded is a machine config or a mode config file
config = FileManager.load(filename, True, True)
expected_version_str = ConfigProcessor.get_expected_version(config_type)
config = FileManager.load(filename, expected_version_str, True)

if not ConfigValidator.config_spec:
ConfigValidator.load_config_spec()
Expand Down Expand Up @@ -208,3 +204,13 @@ def load_config_file(filename, config_type: str,
return config
except TypeError:
return dict()

@staticmethod
def get_expected_version(config_type: str) -> str:
"""Return the expected config or show version tag, e.g. #config_version=5."""
if config_type in ("machine", "mode"):
return "#config_version={}".format(__config_version__)
elif config_type == "show":
return "#show_version={}".format(__show_version__)
else:
raise AssertionError("Invalid config_type {}".format(config_type))

0 comments on commit 9474b74

Please sign in to comment.