mirror of
https://github.com/jketterl/openwebrx.git
synced 2026-01-03 07:10:15 +01:00
add config command line argument
This commit is contained in:
parent
5673699696
commit
0abec76b79
|
|
@ -20,6 +20,7 @@ from owrx.reporting import ReportingEngine
|
|||
from owrx.version import openwebrx_version
|
||||
from owrx.audio.queue import DecoderQueue
|
||||
from owrx.admin import add_admin_parser, run_admin_action
|
||||
from pathlib import Path
|
||||
import signal
|
||||
import argparse
|
||||
import socket
|
||||
|
|
@ -44,6 +45,14 @@ def handleSignal(sig, frame):
|
|||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="OpenWebRX - Open Source SDR Web App for Everyone!")
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--config",
|
||||
action="store",
|
||||
help="Read core configuration from specified file",
|
||||
metavar="configfile",
|
||||
type=Path,
|
||||
)
|
||||
parser.add_argument("-v", "--version", action="store_true", help="Show the software version")
|
||||
parser.add_argument("--debug", action="store_true", help="Set loglevel to DEBUG")
|
||||
|
||||
|
|
@ -66,6 +75,8 @@ def main():
|
|||
print("OpenWebRX version {version}".format(version=openwebrx_version))
|
||||
return 0
|
||||
|
||||
CoreConfig.load(args.config)
|
||||
|
||||
if args.module == "admin":
|
||||
return run_admin_action(adminparser, args)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from owrx.config import ConfigError
|
||||
from configparser import ConfigParser
|
||||
from pathlib import Path
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
|
||||
class CoreConfig(object):
|
||||
defaultSearchLocations = ["./openwebrx.conf", "/etc/openwebrx/openwebrx.conf"]
|
||||
|
||||
defaults = {
|
||||
"core": {
|
||||
"data_directory": "/var/lib/openwebrx",
|
||||
|
|
@ -20,18 +22,41 @@ class CoreConfig(object):
|
|||
}
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
sharedConfig = None
|
||||
|
||||
@staticmethod
|
||||
def load(file: Path = None):
|
||||
|
||||
def expand_base(base: Path):
|
||||
# check if config exists
|
||||
if not base.exists() or not base.is_file():
|
||||
return []
|
||||
# every location can additionally have a directory containing config overrides
|
||||
# this directory must have the same name, with the ".d" suffix
|
||||
override_dir = Path(str(base) + ".d")
|
||||
# check if override dir exists
|
||||
if not override_dir.exists() or not override_dir.is_dir():
|
||||
return [base]
|
||||
# load all .conf files from the override dir
|
||||
overrides = override_dir.glob("*.conf")
|
||||
return [base] + [o for o in overrides if o.is_file()]
|
||||
|
||||
if file is None:
|
||||
bases = [Path(b) for b in CoreConfig.defaultSearchLocations]
|
||||
else:
|
||||
bases = [file]
|
||||
configFiles = [o for b in bases for o in expand_base(b)]
|
||||
|
||||
config = ConfigParser()
|
||||
# set up config defaults
|
||||
config.read_dict(CoreConfig.defaults)
|
||||
# check for overrides
|
||||
overrides_dir = "/etc/openwebrx/openwebrx.conf.d"
|
||||
if os.path.exists(overrides_dir) and os.path.isdir(overrides_dir):
|
||||
overrides = glob(overrides_dir + "/*.conf")
|
||||
else:
|
||||
overrides = []
|
||||
# sequence things together
|
||||
config.read(["./openwebrx.conf", "/etc/openwebrx/openwebrx.conf"] + overrides)
|
||||
# read the allocated files
|
||||
config.read(configFiles)
|
||||
|
||||
CoreConfig.sharedConfig = config
|
||||
|
||||
def __init__(self):
|
||||
config = CoreConfig.sharedConfig
|
||||
self.data_directory = config.get("core", "data_directory")
|
||||
CoreConfig.checkDirectory(self.data_directory, "data_directory")
|
||||
self.temporary_directory = config.get("core", "temporary_directory")
|
||||
|
|
|
|||
Loading…
Reference in a new issue