from ipaddress import AddressValueError
from optparse import OptionParser
+import configparser
from configparser import ConfigParser
from configparser import NoOptionError
#---------- startup ----------
-def common_startup():
- re = regexp.compile('#.*')
- cfg.read_string(re.sub('', defcfg))
+def common_startup(process_cfg):
+ # ConfigParser hates #-comments after values
+ trailingcomments_re = regexp.compile('#.*')
+ cfg.read_string(trailingcomments_re.sub('', defcfg))
need_defcfg = True
def readconfig(pathname, mandatory=True):
readconfig('/etc/hippotat/config', False)
readconfig('/etc/hippotat/config.d', False)
+ try: process_cfg()
+ except (configparser.Error, ValueError):
+ traceback.print_exc(file=sys.stderr)
+ print('\nInvalid configuration, giving up.', file=sys.stderr)
+ sys.exit(12)
+
#print(repr(debug_set), file=sys.stderr)
log_formatter = twisted.logger.formatEventAsClassicLogText