configurable search path for cfg files
This commit is contained in:
parent
5aff4b9dab
commit
c1ffc160a2
@ -24,6 +24,7 @@
|
||||
"""Define helpers"""
|
||||
|
||||
import os
|
||||
from os.path import join, exists, dirname, isdir
|
||||
import ast
|
||||
import time
|
||||
import threading
|
||||
@ -93,11 +94,7 @@ class Server:
|
||||
merged_cfg = OrderedDict()
|
||||
ambiguous_sections = set()
|
||||
for cfgfile in cfgfiles.split(','):
|
||||
if cfgfile.endswith('.cfg') and os.path.exists(cfgfile):
|
||||
filename = cfgfile
|
||||
else:
|
||||
filename = os.path.join(cfg['confdir'], cfgfile + '.cfg')
|
||||
cfgdict = self.loadCfgFile(filename)
|
||||
cfgdict = self.loadCfgFile(cfgfile)
|
||||
ambiguous_sections |= set(merged_cfg) & set(cfgdict)
|
||||
merged_cfg.update(cfgdict)
|
||||
self.node_cfg = merged_cfg.pop('NODE', {})
|
||||
@ -114,9 +111,22 @@ class Server:
|
||||
if ambiguous_sections:
|
||||
self.log.warning('ambiguous sections in %s: %r' % (cfgfiles, tuple(ambiguous_sections)))
|
||||
self._cfgfiles = cfgfiles
|
||||
self._pidfile = os.path.join(cfg['piddir'], name + '.pid')
|
||||
self._pidfile = join(cfg['piddir'], name + '.pid')
|
||||
|
||||
def loadCfgFile(self, filename):
|
||||
def loadCfgFile(self, cfgfile):
|
||||
if not cfgfile.endswith('.cfg'):
|
||||
cfgfile += '.cfg'
|
||||
if '/' in cfgfile: # specified as full path
|
||||
filename = cfgfile if exists(cfgfile) else None
|
||||
else:
|
||||
cfg = getGeneralConfig()
|
||||
for filename in [join(d, cfgfile) for d in cfg['confdir'].split(':')]:
|
||||
if exists(filename):
|
||||
break
|
||||
else:
|
||||
filename = None
|
||||
if filename is None:
|
||||
raise ConfigError("Couldn't find cfg file %r" % cfgfile)
|
||||
self.log.debug('Parse config file %s ...' % filename)
|
||||
result = OrderedDict()
|
||||
parser = configparser.ConfigParser()
|
||||
@ -154,8 +164,8 @@ class Server:
|
||||
def start(self):
|
||||
if not DaemonContext:
|
||||
raise ConfigError('can not daemonize, as python-daemon is not installed')
|
||||
piddir = os.path.dirname(self._pidfile)
|
||||
if not os.path.isdir(piddir):
|
||||
piddir = dirname(self._pidfile)
|
||||
if not isdir(piddir):
|
||||
os.makedirs(piddir)
|
||||
pidfile = pidlockfile.TimeoutPIDLockFile(self._pidfile)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user