Move config to ~/.config/neo-pod-desktop/config.ini with migration

- Config is now in XDG_CONFIG_HOME (~/.config/) for write access in AppImage
- Auto-migrates existing config.ini from project root on first run
- Creates directory on save() if not exists
This commit is contained in:
Maksim Totmin 2026-05-31 18:01:55 +07:00
parent 7a86732953
commit 8a1f6811c0

View File

@ -21,23 +21,33 @@ class ConfigLoader:
def __init__(self, config_file: Optional[str] = None): def __init__(self, config_file: Optional[str] = None):
""" """
Initialize the configuration loader Initialize the configuration loader
Args: Args:
config_file: Path to configuration file (optional) config_file: Path to configuration file (optional)
""" """
# Default config file is in the project root directory
if not config_file: if not config_file:
self.config_file = os.path.join( self.config_file = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), os.path.expanduser("~"), ".config", "neo-pod-desktop", "config.ini"
"config.ini"
) )
self._migrate_old_config()
else: else:
self.config_file = config_file self.config_file = config_file
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
# Load configuration # Load configuration
self.load() self.load()
def _migrate_old_config(self):
"""Migrate config from old project-root location to XDG config dir."""
old_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"config.ini"
)
if os.path.exists(old_path) and not os.path.exists(self.config_file):
logger.info("Migrating config from %s to %s", old_path, self.config_file)
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
os.rename(old_path, self.config_file)
def load(self) -> bool: def load(self) -> bool:
""" """
@ -63,16 +73,17 @@ class ConfigLoader:
def save(self) -> bool: def save(self) -> bool:
""" """
Save configuration to file Save configuration to file
Returns: Returns:
True if successful, False otherwise True if successful, False otherwise
""" """
try: try:
logger.info(f"Saving configuration to {self.config_file}") logger.info(f"Saving configuration to {self.config_file}")
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
with open(self.config_file, 'w') as f: with open(self.config_file, 'w') as f:
self.config.write(f) self.config.write(f)
return True return True
except Exception as e: except Exception as e:
logger.error(f"Failed to save configuration: {e}") logger.error(f"Failed to save configuration: {e}")