Prepare public release with MIT license and private user storage
This commit is contained in:
parent
41772b4d1a
commit
eb8932134a
12 changed files with 175 additions and 26 deletions
44
ocado_grocy/paths.py
Normal file
44
ocado_grocy/paths.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
"""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'
|
||||
Loading…
Add table
Add a link
Reference in a new issue