From df672bb025a5f9b5d4a8ed5bec2af3da0185a35b Mon Sep 17 00:00:00 2001 From: Alexander Wainwright Date: Tue, 24 Jun 2025 20:54:56 +1000 Subject: [PATCH] Add /etc/locutus config reading when root --- pyproject.toml | 2 +- src/locutus/main.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fb82dfb..13a3de3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "locutus" -version = "0.1.0" +version = "0.1.1" description = "A simple borg wrapper" requires-python = ">=3.11" dependencies = [ diff --git a/src/locutus/main.py b/src/locutus/main.py index ad8f48a..39f3e58 100644 --- a/src/locutus/main.py +++ b/src/locutus/main.py @@ -4,8 +4,32 @@ import argparse import os import sys -DEFAULT_CONFIG = os.path.expanduser('~/.config/locutus/locutus.toml') -DEFAULT_PROFILE = os.path.expanduser('~/.config/locutus/locutus.rc') + +def get_default_config_paths(): + user_config = os.path.expanduser('~/.config/locutus/locutus.toml') + user_profile = os.path.expanduser('~/.config/locutus/locutus.rc') + system_config = '/etc/locutus/locutus.toml' + system_profile = '/etc/locutus/locutus.rc' + + # If --config/--profile are set by argparse, use them directly. + # Otherwise, pick: + if os.geteuid() == 0: # running as root + if os.path.exists(system_config): + return system_config, system_profile + elif os.path.exists(user_config): + return user_config, user_profile + else: + return system_config, system_profile + else: + if os.path.exists(user_config): + return user_config, user_profile + elif os.path.exists(system_config): + return system_config, system_profile + else: + return user_config, user_profile + + +DEFAULT_CONFIG, DEFAULT_PROFILE = get_default_config_paths() def parse_args() -> tuple[argparse.Namespace, argparse.ArgumentParser]: