-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command "mpf init" to initialize a project folder
- Loading branch information
1 parent
b619883
commit 2af5478
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Command to initialize an MPF project folder.""" | ||
|
||
import os | ||
import pathlib | ||
import shutil | ||
|
||
SUBCOMMAND = True | ||
INITIAL_MODES = ("attract", "base") | ||
|
||
class Command: | ||
|
||
"""Initializes an MPF project folder.""" | ||
|
||
__slots__ = ("path", ) | ||
|
||
def __init__(self, argv, path): | ||
"""Generate config and mode folders.""" | ||
# If a path is provided, use it | ||
if len(argv) > 1: | ||
path = os.path.join(path, argv[1]) | ||
self.path = path | ||
|
||
print(f"Initializing MPF project at path {self.path}") | ||
|
||
try: | ||
os.stat(self.path) | ||
except FileNotFoundError: | ||
os.makedirs(self.path) | ||
|
||
self.generate_config_file() | ||
self.generate_mode_folder() | ||
|
||
print("MPF project initialization complete!") | ||
|
||
def generate_config_file(self): | ||
# Create the config folder | ||
config_dir = os.path.join(self.path, "config") | ||
try: | ||
os.stat(config_dir) | ||
except FileNotFoundError: | ||
os.mkdir(config_dir) | ||
|
||
config_file = os.path.join(config_dir, "config.yaml") | ||
try: | ||
os.stat(config_file) | ||
except FileNotFoundError: | ||
base_config_file = os.path.join(pathlib.Path(__file__).parent.absolute(), "templates/config.yaml") | ||
shutil.copy2(base_config_file, config_file) | ||
|
||
def generate_mode_folder(self): | ||
mode_dir = os.path.join(self.path, "modes") | ||
try: | ||
os.stat(mode_dir) | ||
except FileNotFoundError: | ||
os.mkdir(mode_dir) | ||
|
||
|
||
for mode in INITIAL_MODES: | ||
mode_path = os.path.join(mode_dir, mode, "config") | ||
try: | ||
os.stat(mode_path) | ||
except FileNotFoundError: | ||
os.makedirs(mode_path) | ||
mode_config = os.path.join(mode_path, f"{mode}.yaml") | ||
try: | ||
os.stat(mode_config) | ||
except FileNotFoundError: | ||
mode_config_template = os.path.join(pathlib.Path(__file__).parent.absolute(), f"templates/{mode}.yaml") | ||
shutil.copy2(mode_config_template, mode_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#config_version=6 | ||
|
||
# Attract mode that starts when the machine boots up, stops | ||
# whenever a game is started, and re-starts after the game ends. | ||
|
||
slide_player: | ||
mode_attract_started: attract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#config_version=6 | ||
|
||
# Base mode that starts at the beginning of each ball | ||
# and stops at the end of each ball. | ||
|
||
mode: | ||
start_events: ball_starting | ||
stop_events: ball_will_end | ||
priority: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#config_version=6 | ||
|
||
## MPF Main Machine Config File | ||
# | ||
# This file defines your system-wide properties like switches, | ||
# drivers, ball devices, hardware platforms, and more. You can | ||
# include everything here, or create sub-config files to be | ||
# imported and merged with this one. | ||
|
||
modes: | ||
- attract | ||
- base |