Skip to content

Commit

Permalink
🥅 Catch error if ser2net is corrupt/invalid (allow menu to load with …
Browse files Browse the repository at this point in the history
…default serial settings). Resolves #200

🚑 hotfix, last update introduced an AttributeError related to partially implemented outlet_group feature
  • Loading branch information
wade ~ Pack3tL0ss committed Sep 6, 2024
1 parent 850ab12 commit bc63ada
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/consolepi-menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def do_menu_load_warnings(self):
log.show('No Local Adapters Detected')
if log.error_msgs:
# -- remove no ser2net.conf found msg if no local adapters
log.error_msgs = [m for m in log.error_msgs if 'ser2net' not in m]
log.error_msgs = [m for m in log.error_msgs if 'No ser2net configuration found' not in m]

def picocom_help(self):
print('----------------------- picocom Command Sequences -----------------------\n')
Expand Down
10 changes: 8 additions & 2 deletions src/pypkg/consolepi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self):
self.hosts = self.get_hosts()
self.power = self.cfg.get('power', False)
self.do_dli_menu = None # updated in get_outlets_from_file()
self.outlet_groups = {} # updated in get_outlets_from_file()
self.outlets = {} if not self.power else self.get_outlets_from_file()
self.remotes = self.get_remotes_from_file()
self.remote_update = self.get_remotes_from_file
Expand Down Expand Up @@ -518,13 +519,18 @@ def get_ser2netv4(self, file: Path = None) -> Dict:
########################################################
ser2net_conf = {}
if file is None and self.ser2net_file is None:
return ()
return {}

raw = self.ser2net_file.read_text() if not file else file.read_text()
raw_mod = "\n".join([line if not line.startswith("connection") else f"{line.split('&')[-1]}:" for line in raw.splitlines()])
banner = [line for line in raw.splitlines() if line.startswith("define: &banner")]
banner = None if not banner else banner[-1].replace("define: &banner", "").lstrip()
ser_dict = yaml.safe_load(raw_mod)
try:
ser_dict = yaml.safe_load(raw_mod)
except Exception as e:
log.error(f"Error ({e.__class__.__name__}) occured parsing {file or self.ser2net_file}, verify file contents.", show=True)
log.exception(e)
return {}

for k, v in ser_dict.items():
if not isinstance(v, dict):
Expand Down

0 comments on commit bc63ada

Please sign in to comment.