Try to read config from /etc/dibbler/dibbler.conf

This commit is contained in:
2026-01-06 16:01:31 +09:00
parent f4b5e1d6d4
commit 78161a96be
2 changed files with 28 additions and 2 deletions

View File

@@ -1,6 +1,25 @@
# This module is supposed to act as a singleton and be filled
# with config variables by cli.py
from pathlib import Path
import os
import configparser
config = configparser.ConfigParser()
DEFAULT_CONFIG_PATH = Path('/etc/dibbler/dibbler.conf')
def default_config_path_submissive_and_readable() -> bool:
return DEFAULT_CONFIG_PATH.is_file() and any(
[
(
DEFAULT_CONFIG_PATH.stat().st_mode & 0o400
and DEFAULT_CONFIG_PATH.stat().st_uid == os.getuid()
),
(
DEFAULT_CONFIG_PATH.stat().st_mode & 0o040
and DEFAULT_CONFIG_PATH.stat().st_gid == os.getgid()
),
(DEFAULT_CONFIG_PATH.stat().st_mode & 0o004),
]
)

View File

@@ -1,6 +1,7 @@
import argparse
import sys
from dibbler.conf import config
from dibbler.conf import DEFAULT_CONFIG_PATH, config, default_config_path_submissive_and_readable
parser = argparse.ArgumentParser()
@@ -25,7 +26,13 @@ subparsers.add_parser("seed-data", help="Fill with mock data")
def main():
args = parser.parse_args()
config.read(args.config)
if args.config is not None:
config.read(args.config)
elif default_config_path_submissive_and_readable():
config.read(DEFAULT_CONFIG_PATH)
else:
print("Could not read config file, it was neither provided nor readable in default location", file=sys.stderr)
if args.subcommand == "loop":
import dibbler.subcommands.loop as loop