"""User-specific paths, with compatibility for existing checkout installations.""" import os from pathlib import Path def user_directory(variable, fallback): value = os.environ.get(variable, '') # XDG paths must be absolute; ignore empty or relative values. base = Path(value) if value and Path(value).is_absolute() else Path.home() / fallback return base / 'ocado-grocy' def config_file(): # Keep an existing installation on its original journal until migrated. legacy = Path('config.toml') return legacy if legacy.exists() else user_directory('XDG_CONFIG_HOME', '.config') / 'config.toml' def state_directory(): return user_directory('XDG_STATE_HOME', '.local/state') def archive_directory(): if Path('config.toml').exists(): return Path('history') return user_directory('XDG_DATA_HOME', '.local/share') / 'history' def browser_directory(): if Path('config.toml').exists(): return Path('.ocado-browser') return state_directory() / 'browser' def journal_file(settings, config_path): configured = settings.get('import', {}).get('state_file') if configured: path = Path(configured).expanduser() return path if path.is_absolute() else config_path.resolve().parent / path user_config = user_directory('XDG_CONFIG_HOME', '.config') / 'config.toml' if config_path.resolve() == user_config.resolve(): return state_directory() / 'imports.sqlite3' # Explicit custom/legacy configs retain the historical relative default. return config_path.resolve().parent / 'imports.sqlite3'