Fix up a few errors that sneaked in while updating vmenu code and a couple other things. Logs should be much nicer now.

This commit is contained in:
Storm Dragon 2025-06-25 10:55:48 -04:00
parent b1edc53362
commit 40b88efa34
5 changed files with 143 additions and 2 deletions

View File

@ -0,0 +1,134 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
import os
import shutil
import tempfile
import configparser
from datetime import datetime
class ConfigCommand():
"""Base class for configuration management commands"""
def __init__(self):
self.env = None
self.settingsFile = None
self.config = None
def initialize(self, environment):
self.env = environment
self.settingsFile = self.env['runtime']['settingsManager'].settingsFile
self.config = self.env['runtime']['settingsManager'].settings
def shutdown(self):
pass
def setCallback(self, callback):
pass
def presentText(self, text, interrupt=True, flush=True):
"""Present text to user with proper speech handling"""
self.env['runtime']['outputManager'].presentText(text, interrupt=interrupt, flush=flush)
def playSound(self, soundName):
"""Play system sound"""
soundIcon = ''
if soundName == 'Accept':
soundIcon = 'Accept'
elif soundName == 'Error':
soundIcon = 'ErrorSound'
elif soundName == 'Cancel':
soundIcon = 'Cancel'
if soundIcon:
self.env['runtime']['outputManager'].presentText('', soundIcon=soundIcon, interrupt=False)
def backupConfig(self, announce=True):
"""Create backup of current configuration file"""
try:
if not os.path.exists(self.settingsFile):
message = "Configuration file not found"
if announce:
self.presentText(message)
return False, message
# Create backup with timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
backup_path = f"{self.settingsFile}.backup_{timestamp}"
shutil.copy2(self.settingsFile, backup_path)
message = f"Configuration backed up to {backup_path}"
if announce:
self.presentText("Configuration backup created successfully")
return True, message
except Exception as e:
message = f"Failed to backup configuration: {str(e)}"
if announce:
self.presentText(message)
return False, message
def reloadConfig(self):
"""Reload configuration from file"""
try:
# Force settings manager to reload from file
self.env['runtime']['settingsManager'].loadSettings()
self.config = self.env['runtime']['settingsManager'].settings
return True
except Exception as e:
self.presentText(f"Failed to reload configuration: {str(e)}")
return False
def findDefaultConfig(self):
"""Find default configuration file path"""
# Look for default config in multiple locations
default_paths = [
'/etc/fenrir/settings/settings.conf.default',
'/usr/share/fenrir/settings/settings.conf',
os.path.join(os.path.dirname(self.settingsFile), 'settings.conf.default'),
os.path.join(os.path.dirname(os.path.dirname(self.settingsFile)), 'settings', 'settings.conf.default')
]
for path in default_paths:
if os.path.exists(path):
return path
return None
def createBasicDefaults(self):
"""Create basic default configuration manually"""
try:
# Create a new config with basic defaults
self.config = configparser.ConfigParser()
# Add basic sections and settings
self.config.add_section('speech')
self.config.set('speech', 'driver', 'speechdDriver')
self.config.set('speech', 'rate', '0.75')
self.config.set('speech', 'pitch', '0.5')
self.config.set('speech', 'volume', '1.0')
self.config.add_section('sound')
self.config.set('sound', 'driver', 'genericDriver')
self.config.set('sound', 'volume', '0.7')
self.config.add_section('keyboard')
self.config.set('keyboard', 'driver', 'evdevDriver')
self.config.set('keyboard', 'keyboardLayout', 'desktop')
self.config.add_section('screen')
self.config.set('screen', 'driver', 'vcsaDriver')
self.config.add_section('general')
self.config.set('general', 'debugMode', 'Off')
return True
except Exception as e:
self.presentText(f"Failed to create basic defaults: {str(e)}")
return False

View File

@ -84,6 +84,9 @@ class commandManager():
fileName = fileName.split('/')[-1]
if fileName.startswith('__'):
continue
# Skip base classes that shouldn't be loaded as commands
if fileName.endswith('_base'):
continue
# Check if command already exists to prevent duplicate loading
if fileName.upper() in self.env['commands'][section] and self.env['commands'][section][fileName.upper()] is not None:
continue

View File

@ -174,7 +174,8 @@ class settingsManager():
def loadDriver(self, driverName, driverType):
try:
self.env['runtime'][driverType].shutdown(self.env)
if self.env['runtime'][driverType] is not None:
self.env['runtime'][driverType].shutdown(self.env)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('settingsManager loadDriver: Error shutting down driver: ' + str(e), debug.debugLevel.ERROR)
try:

View File

@ -269,6 +269,9 @@ class vmenuManager():
fileName = fileName.split('/')[-1]
if fileName.startswith('__'):
continue
# Skip base classes that shouldn't be loaded as commands
if fileName.endswith('_base'):
continue
command = self.env['runtime']['commandManager'].loadFile(root + '/' + f)
tree.update({fileName + ' ' + _('Action'): command})
except Exception as e:

View File

@ -4,5 +4,5 @@
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
version = "2025.06.20"
version = "2025.06.25"
codeName = "testing"