Skip to content

Commit

Permalink
Skip deprecated config options in updater
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhinham committed Jun 13, 2022
1 parent 7d30442 commit a2bd976
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `i2c_dac_address` and `i2c_dac_init` configuration options have been deprecated and have no longer have any effect. DACs requiring initialization are now automatically detected.
- The `[fluidsynth.soundfont.x]` sections have now been deprecated. SoundFont effects profiles must now be stored in separate .cfg files, with the same file name as the SoundFont (minus extension). This means that file index no longer influences SoundFont settings. See `soundfonts/GeneralUser GS v1.511.cfg` for an example.
- The maximum number of SoundFonts has been increased to 512.
- Updater: deprecated options are now removed when merging configs.

## [0.11.3] - 2022-04-13

Expand Down
46 changes: 36 additions & 10 deletions scripts/mt32pi_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# -----------------------------------------------------------------------------
# Changelog
# -----------------------------------------------------------------------------
# 0.2.3 - 2022-06-13
# - Remove deprecated options from config file.
#
# 0.2.2 - 2022-04-13
# - Disable colors if colorama or Windows Terminal unavailable on Windows.
# - Fix text alignment and error message colors on Windows.
Expand Down Expand Up @@ -79,7 +82,7 @@
GITHUB_REPO = "dwhinham/mt32-pi"
GITHUB_API_URL = f"https://api.github.com/repos/{GITHUB_REPO}/releases"
SCRIPT_URL = f"https://github.com/{GITHUB_REPO}/raw/master/scripts/mt32pi_updater.py"
SCRIPT_VERSION = "0.2.2"
SCRIPT_VERSION = "0.2.3"

# Config keys
K_SECTION = "updater"
Expand Down Expand Up @@ -160,6 +163,13 @@
"wpa_supplicant.conf", # Wi-Fi configuration file
]

DEPRECATED_OPTIONS = {
"audio": [
"i2c_dac_address",
"i2c_dac_init",
]
}


def print_status(message):
stripped_message = ANSI_ESCAPE_REGEX.sub("", message)
Expand Down Expand Up @@ -488,27 +498,32 @@ def update_option(config_lines, section, key, value):
insert_new_option_line(config_lines, section_index + 1, key, value)


def merge_configs(old_config_path, new_config_path):
def merge_configs(old_config_path, new_config_path, skipped_options):
print_status("Merging your old settings into the new config file template...")

try:
config_old = ConfigParser()
config_old.read(old_config_path)
# print(
# {
# section: dict(config_old.items(section))
# for section in config_old.sections()
# }
# )

new_config_lines = []
with open(install_dir / "mt32-pi.cfg", "r") as in_file:
with open(new_config_path, "r") as in_file:
new_config_lines = in_file.read().splitlines()

for section in config_old.sections():
# Don't merge deprecated sections
if section.startswith("fluidsynth.soundfont."):
skipped_options.append(f"[{section}] (whole section)")
continue

for item in config_old.items(section):
key = item[0]
value = item[1]

# Don't merge deprecated options
if section in DEPRECATED_OPTIONS and key in DEPRECATED_OPTIONS[section]:
skipped_options.append(key)
continue

update_option(new_config_lines, section, key, value)

with open(new_config_path, "w") as out_file:
Expand Down Expand Up @@ -635,6 +650,7 @@ def reboot(host):
with tempfile.TemporaryDirectory() as temp_dir_name:
temp_dir = Path(temp_dir_name)
host = config.get(K_SECTION, K_HOST)
skipped_options = []

print_status(
"Connecting to your mt32-pi's embedded FTP server at"
Expand Down Expand Up @@ -686,7 +702,9 @@ def reboot(host):

# Create backup of old config and merge with new
shutil.move(temp_dir / "mt32-pi.cfg", old_config_path)
merge_configs(old_config_path, new_config_path) or exit(1)
merge_configs(
old_config_path, new_config_path, skipped_options
) or exit(1)

# Move new Wi-Fi/boot configs aside in case the user needs to adapt them
shutil.move(install_dir / "config.txt", install_dir / "config.txt.new")
Expand Down Expand Up @@ -722,6 +740,14 @@ def reboot(host):
f"{COLOR_PURPLE}-{COLOR_RESET} The settings from your old config file have"
" been merged into the latest config template."
)
if skipped_options:
skipped_list = ", ".join(
[f"{COLOR_PURPLE}{o}{COLOR_RESET}" for o in skipped_options]
)
print(
f"{COLOR_PURPLE}-{COLOR_RESET} The following deprecated options were"
f" removed from your config file: {skipped_list}"
)
print(
f"{COLOR_PURPLE}-{COLOR_RESET} A backup of your old config is available as"
f" {COLOR_PURPLE}mt32-pi.cfg.bak{COLOR_RESET} on the root of your Raspberry"
Expand Down

0 comments on commit a2bd976

Please sign in to comment.