From f3ecd912da682a0dcefa7621e4e94335a00f5244 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 16 Apr 2020 10:37:53 +0200 Subject: [PATCH] customizable general config evnironment variables SECOP_ 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 Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker --- secop/lib/__init__.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/secop/lib/__init__.py b/secop/lib/__init__.py index c77573d..66af30e 100644 --- a/secop/lib/__init__.py +++ b/secop/lib/__init__.py @@ -21,42 +21,39 @@ # ***************************************************************************** """Define helpers""" -import errno -import fnmatch import linecache -import os -import re -import signal import socket -import subprocess import sys import threading import traceback import importlib -from os import path +from os import path, environ repodir = path.abspath(path.join(path.dirname(__file__), '..', '..')) -CONFIG = { - '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'): +if path.splitext(sys.executable)[1] == ".exe" and not path.basename(sys.executable).startswith('python'): CONFIG = { 'piddir': './', 'logdir': './log', 'confdir': './', - 'basedir': path.dirname(sys.executable), } -elif not os.path.exists(os.path.join(repodir, '.git')): - CONFIG = { +elif not path.exists(path.join(repodir, '.git')): + CONFIG = { 'piddir': '/var/run/secop', 'logdir': '/var/log', '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()