customizable general config

evnironment variables SECOP_<DIRNAME> may overwrite configured
directories logdir, piddir and confdir

Change-Id: Idc13339c36c15853e09d1dd20f04c4a622436fbe
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22974
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2020-04-16 10:37:53 +02:00
parent da7a027949
commit f3ecd912da

View File

@ -21,42 +21,39 @@
# ***************************************************************************** # *****************************************************************************
"""Define helpers""" """Define helpers"""
import errno
import fnmatch
import linecache import linecache
import os
import re
import signal
import socket import socket
import subprocess
import sys import sys
import threading import threading
import traceback import traceback
import importlib import importlib
from os import path from os import path, environ
repodir = path.abspath(path.join(path.dirname(__file__), '..', '..')) repodir = path.abspath(path.join(path.dirname(__file__), '..', '..'))
CONFIG = { if path.splitext(sys.executable)[1] == ".exe" and not path.basename(sys.executable).startswith('python'):
'piddir': os.path.join(repodir, 'pid'),
'logdir': os.path.join(repodir, 'log'),
'confdir': os.path.join(repodir, 'cfg'),
'basedir': repodir,
}
if path.splitext(sys.executable)[1] == ".exe" and not os.path.basename(sys.executable).startswith('python'):
CONFIG = { CONFIG = {
'piddir': './', 'piddir': './',
'logdir': './log', 'logdir': './log',
'confdir': './', 'confdir': './',
'basedir': path.dirname(sys.executable),
} }
elif not os.path.exists(os.path.join(repodir, '.git')): elif not path.exists(path.join(repodir, '.git')):
CONFIG = { CONFIG = {
'piddir': '/var/run/secop', 'piddir': '/var/run/secop',
'logdir': '/var/log', 'logdir': '/var/log',
'confdir': '/etc/secop', 'confdir': '/etc/secop',
'basedir': repodir,
} }
else:
CONFIG = {
'piddir': path.join(repodir, 'pid'),
'logdir': path.join(repodir, 'log'),
'confdir': path.join(repodir, 'cfg'),
}
# overwrite with env variables SECOP_LOGDIR, SECOP_PIDDIR, SECOP_CONFDIR, if present
for dirname in CONFIG:
CONFIG[dirname] = environ.get('SECOP_%s' % dirname.upper(), CONFIG[dirname])
# this is not customizable
CONFIG['basedir'] = repodir
unset_value = object() unset_value = object()