Try to read config from /etc/dibbler/dibbler.conf
This commit is contained in:
@@ -1,6 +1,25 @@
|
|||||||
# This module is supposed to act as a singleton and be filled
|
# This module is supposed to act as a singleton and be filled
|
||||||
# with config variables by cli.py
|
# with config variables by cli.py
|
||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
config = configparser.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),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|||||||
+9
-2
@@ -1,6 +1,7 @@
|
|||||||
import argparse
|
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()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
@@ -25,7 +26,13 @@ subparsers.add_parser("seed-data", help="Fill with mock data")
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parser.parse_args()
|
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":
|
if args.subcommand == "loop":
|
||||||
import dibbler.subcommands.loop as loop
|
import dibbler.subcommands.loop as loop
|
||||||
|
|||||||
Reference in New Issue
Block a user