varios fixes at psi repo, as of 2022-02-01
Change-Id: I8cdc849126d52ef0f2f27a0faf661830aac6f874
This commit is contained in:
@ -27,42 +27,62 @@ import socket
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
from configparser import ConfigParser
|
||||
from os import environ, path
|
||||
|
||||
|
||||
repodir = path.abspath(path.join(path.dirname(__file__), '..', '..'))
|
||||
|
||||
if path.splitext(sys.executable)[1] == ".exe" and not path.basename(sys.executable).startswith('python'):
|
||||
CONFIG = {
|
||||
'piddir': './',
|
||||
'logdir': './log',
|
||||
'confdir': './',
|
||||
}
|
||||
elif not path.exists(path.join(repodir, '.git')):
|
||||
CONFIG = {
|
||||
'piddir': '/var/run/secop',
|
||||
'logdir': '/var/log',
|
||||
'confdir': '/etc/secop',
|
||||
}
|
||||
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
|
||||
|
||||
# TODO: if ever more general options are need, we should think about a general config file
|
||||
|
||||
|
||||
CONFIG = {}
|
||||
unset_value = object()
|
||||
|
||||
|
||||
def getGeneralConfig(confdir=None):
|
||||
global CONFIG # pylint: disable=global-statement
|
||||
|
||||
if CONFIG:
|
||||
if confdir:
|
||||
raise ValueError('getGeneralConfig with argument must be called first')
|
||||
else:
|
||||
repodir = path.abspath(path.join(path.dirname(__file__), '..', '..'))
|
||||
if path.splitext(sys.executable)[1] == ".exe" and not path.basename(sys.executable).startswith('python'):
|
||||
# special MS windows environment
|
||||
CONFIG = {
|
||||
'piddir': './',
|
||||
'logdir': './log',
|
||||
'confdir': './',
|
||||
}
|
||||
elif not path.exists(path.join(repodir, '.git')):
|
||||
CONFIG = {
|
||||
'piddir': '/var/run/secop',
|
||||
'logdir': '/var/log',
|
||||
'confdir': '/etc/secop',
|
||||
}
|
||||
else:
|
||||
CONFIG = {
|
||||
'piddir': path.join(repodir, 'pid'),
|
||||
'logdir': path.join(repodir, 'log'),
|
||||
'confdir': path.join(repodir, 'cfg'),
|
||||
}
|
||||
gen_config_path = confdir or environ.get('FRAPPY_CONFIG_FILE',
|
||||
path.join(CONFIG['confdir'], 'generalConfig.cfg'))
|
||||
if gen_config_path and path.exists(gen_config_path):
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = str
|
||||
parser.read([gen_config_path])
|
||||
CONFIG = {}
|
||||
# only the FRAPPY section is relevant, other sections might be used by others
|
||||
for key, value in parser['FRAPPY'].items():
|
||||
if value.startswith('./'):
|
||||
CONFIG[key] = path.abspath(path.join(repodir, value))
|
||||
else:
|
||||
# expand ~ to username, also in path lists separated with ':'
|
||||
CONFIG[key] = ':'.join(path.expanduser(v) for v in value.split(':'))
|
||||
else:
|
||||
for dirname in CONFIG:
|
||||
CONFIG[dirname] = environ.get('SECOP_%s' % dirname.upper(), CONFIG[dirname])
|
||||
# this is not customizable
|
||||
CONFIG['basedir'] = repodir
|
||||
return CONFIG
|
||||
|
||||
|
||||
class lazy_property:
|
||||
"""A property that calculates its value only once."""
|
||||
|
||||
@ -253,10 +273,6 @@ def getfqdn(name=''):
|
||||
return socket.getfqdn(name)
|
||||
|
||||
|
||||
def getGeneralConfig():
|
||||
return CONFIG
|
||||
|
||||
|
||||
def formatStatusBits(sword, labels, start=0):
|
||||
"""Return a list of labels according to bit state in `sword` starting
|
||||
with bit `start` and the first label in `labels`.
|
||||
@ -266,3 +282,11 @@ def formatStatusBits(sword, labels, start=0):
|
||||
if sword & (1 << i) and lbl:
|
||||
result.append(lbl)
|
||||
return result
|
||||
|
||||
|
||||
class UniqueObject:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return 'UniqueObject(%r)' % self.name
|
||||
|
Reference in New Issue
Block a user