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.version import openwebrx_version
|
||||||
from owrx.audio.queue import DecoderQueue
|
from owrx.audio.queue import DecoderQueue
|
||||||
from owrx.admin import add_admin_parser, run_admin_action
|
from owrx.admin import add_admin_parser, run_admin_action
|
||||||
|
from pathlib import Path
|
||||||
import signal
|
import signal
|
||||||
import argparse
|
import argparse
|
||||||
import socket
|
import socket
|
||||||
|
|
@ -44,6 +45,14 @@ def handleSignal(sig, frame):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="OpenWebRX - Open Source SDR Web App for Everyone!")
|
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("-v", "--version", action="store_true", help="Show the software version")
|
||||||
parser.add_argument("--debug", action="store_true", help="Set loglevel to DEBUG")
|
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))
|
print("OpenWebRX version {version}".format(version=openwebrx_version))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
CoreConfig.load(args.config)
|
||||||
|
|
||||||
if args.module == "admin":
|
if args.module == "admin":
|
||||||
return run_admin_action(adminparser, args)
|
return run_admin_action(adminparser, args)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
from owrx.config import ConfigError
|
from owrx.config import ConfigError
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
from glob import glob
|
|
||||||
|
|
||||||
|
|
||||||
class CoreConfig(object):
|
class CoreConfig(object):
|
||||||
|
defaultSearchLocations = ["./openwebrx.conf", "/etc/openwebrx/openwebrx.conf"]
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
"core": {
|
"core": {
|
||||||
"data_directory": "/var/lib/openwebrx",
|
"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()
|
config = ConfigParser()
|
||||||
# set up config defaults
|
# set up config defaults
|
||||||
config.read_dict(CoreConfig.defaults)
|
config.read_dict(CoreConfig.defaults)
|
||||||
# check for overrides
|
# read the allocated files
|
||||||
overrides_dir = "/etc/openwebrx/openwebrx.conf.d"
|
config.read(configFiles)
|
||||||
if os.path.exists(overrides_dir) and os.path.isdir(overrides_dir):
|
|
||||||
overrides = glob(overrides_dir + "/*.conf")
|
CoreConfig.sharedConfig = config
|
||||||
else:
|
|
||||||
overrides = []
|
def __init__(self):
|
||||||
# sequence things together
|
config = CoreConfig.sharedConfig
|
||||||
config.read(["./openwebrx.conf", "/etc/openwebrx/openwebrx.conf"] + overrides)
|
|
||||||
self.data_directory = config.get("core", "data_directory")
|
self.data_directory = config.get("core", "data_directory")
|
||||||
CoreConfig.checkDirectory(self.data_directory, "data_directory")
|
CoreConfig.checkDirectory(self.data_directory, "data_directory")
|
||||||
self.temporary_directory = config.get("core", "temporary_directory")
|
self.temporary_directory = config.get("core", "temporary_directory")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue