Add /etc/locutus config reading when root

This commit is contained in:
Alexander Wainwright
2025-06-24 20:54:56 +10:00
parent f79664c5e5
commit df672bb025
2 changed files with 27 additions and 3 deletions

View File

@@ -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 = [

View File

@@ -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]: