Skip to content

Commit

Permalink
fixes bug with settings not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
shitwolfymakes committed Jun 21, 2022
1 parent 235ebc4 commit 74cd0da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 46 deletions.
2 changes: 2 additions & 0 deletions arm/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ def _load_config(fp):

apprise_config = _load_config(apprise_config_path)
arm_config = _load_config(arm_config_path)
with open(abcde_config_path, "r") as abcde_read_file:
abcde_config = abcde_read_file.read()
19 changes: 5 additions & 14 deletions arm/ui/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,9 @@ def settings():
}
# Load up the comments.json, so we can comment the arm.yaml
comments = ui_utils.generate_comments()
# Get the current config, so we can show the current values
arm_cfg_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "arm.yaml")
current_cfg = ui_utils.get_settings(arm_cfg_file)
# load abcde config
abcde_cfg = ui_utils.get_abcde_cfg(cfg.arm_config['ABCDE_CONFIG_FILE']).strip()
form = SettingsForm()
return render_template('settings.html', settings=current_cfg, ui_settings=armui_cfg,
form=form, jsoncomments=comments, abcde_cfg=abcde_cfg, stats=stats)
return render_template('settings.html', settings=cfg.arm_config, ui_settings=armui_cfg,
form=form, jsoncomments=comments, abcde_cfg=cfg.abcde_config, stats=stats)


@app.route('/save_settings', methods=['POST'])
Expand All @@ -328,8 +323,6 @@ def save_settings():
"""
Save arm ripper settings from post
"""
# Path to arm.yaml
arm_cfg_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "arm.yaml")
# Load up the comments.json, so we can comment the arm.yaml
comments = ui_utils.generate_comments()
success = False
Expand All @@ -339,7 +332,7 @@ def save_settings():
# Build the new arm.yaml with updated values from the user
arm_cfg = ui_utils.build_arm_cfg(request.form.to_dict(), comments)
# Save updated arm.yaml
with open(arm_cfg_file, "w") as settings_file:
with open(cfg.arm_config_path, "w") as settings_file:
settings_file.write(arm_cfg)
settings_file.close()
success = True
Expand Down Expand Up @@ -379,16 +372,14 @@ def save_abcde():
"""
Save abcde config settings from post
"""
# Path to abcde.conf
abcde_cfg = ui_utils.get_abcde_cfg(cfg.arm_config['ABCDE_CONFIG_FILE'])
success = False
abcde_cfg_str = ""
form = AbcdeForm()
if form.validate():
app.logger.debug(f"routes.save_abcde: Saving new abcde.conf: {abcde_cfg}")
app.logger.debug(f"routes.save_abcde: Saving new abcde.conf: {cfg.abcde_config_path}")
abcde_cfg_str = str(form.abcdeConfig.data).strip()
# Save updated abcde.conf
with open(cfg.arm_config['ABCDE_CONFIG_FILE'], "w") as abcde_file:
with open(cfg.abcde_config_path, "w") as abcde_file:
abcde_file.write(abcde_cfg_str)
abcde_file.close()
success = True
Expand Down
32 changes: 0 additions & 32 deletions arm/ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import bcrypt
import requests
from werkzeug.routing import ValidationError
import yaml
from flask.logging import default_handler # noqa: F401

import arm.config.config as cfg
Expand Down Expand Up @@ -469,25 +468,6 @@ def set_file_last_modified(file_path, date_time):
set_file_last_modified(arm_main, now)


def get_settings(arm_cfg_file):
"""
yaml file loader - is used for loading fresh arm.yaml config\n
:param arm_cfg_file: full path to arm.yaml
:return: the loaded yaml file
"""
try:
with open(arm_cfg_file, "r") as yaml_file:
try:
yaml_cfg = yaml.load(yaml_file, Loader=yaml.FullLoader)
except Exception as error:
app.logger.debug(error)
yaml_cfg = yaml.safe_load(yaml_file) # For older versions use this
except FileNotFoundError as error:
app.logger.debug(error)
yaml_cfg = {}
return yaml_cfg


def build_arm_cfg(form_data, comments):
"""
Main function for saving new updated arm.yaml\n
Expand Down Expand Up @@ -706,18 +686,6 @@ def import_movie_add(poster_image, imdb_id, movie_group, my_path):
return movie_dict


def get_abcde_cfg(abcde_cfg_file):
"""
load and return as string abcde.cfg
"""
try:
with open(abcde_cfg_file, "r") as abcde_read_file:
abcde = abcde_read_file.read()
except FileNotFoundError:
abcde = "File not found"
return abcde


def get_git_revision_hash() -> str:
"""Get full hash of current git commit"""
return subprocess.check_output(['git', 'rev-parse', 'HEAD'],
Expand Down

0 comments on commit 74cd0da

Please sign in to comment.