X-Git-Url: https://git.distorted.org.uk/~mdw/hippotat/blobdiff_plain/4a7807035129c7bab2e22c7a5cea7c3ef2d415ea..e5f6fff02ac195add8cf14ad4a597d58c6613a9b:/hippotatlib/__init__.py diff --git a/hippotatlib/__init__.py b/hippotatlib/__init__.py index cbcd967..4f0bc8c 100644 --- a/hippotatlib/__init__.py +++ b/hippotatlib/__init__.py @@ -1,4 +1,26 @@ # -*- python -*- +# +# Hippotat - Asinine IP Over HTTP program +# hippotatlib/__init__.py - common library code +# +# Copyright 2017 Ian Jackson +# +# GPLv3+ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program, in the file GPLv3. If not, +# see . + import signal signal.signal(signal.SIGINT, signal.SIG_DFL) @@ -540,12 +562,18 @@ def common_startup(process_cfg): need_defcfg = False readconfig(value) + def read_defconfig(): + readconfig('/etc/hippotat/config.d', False) + readconfig('/etc/hippotat/passwords.d', False) + readconfig('/etc/hippotat/master.cfg', False) + def dfs_less_detailed(dl): return [df for df in DBG.iterconstants() if df <= dl] def ds_default(od,os,dl,op): global debug_set - debug_set = set(dfs_less_detailed(debug_def_detail)) + debug_set.clear + debug_set |= set(dfs_less_detailed(debug_def_detail)) def ds_select(od,os, spec, op): for it in spec.split(','): @@ -602,22 +630,23 @@ just `+': all DFLAGs. action='callback', callback= oc_config) - (opts, args) = optparser.parse_args() - if len(args): optparser.error('no non-option arguments please') if need_defcfg: - readconfig('/etc/hippotat/config', False) - readconfig('/etc/hippotat/config.d', False) + read_defconfig() + + (opts, args) = optparser.parse_args() + if len(args): optparser.error('no non-option arguments please') try: (pss, pcs) = _cfg_process_putatives() - process_cfg(pss, pcs) + process_cfg(opts, pss, pcs) 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) + + #print('X', debug_set, file=sys.stderr) log_formatter = twisted.logger.formatEventAsClassicLogText stdout_obs = twisted.logger.FileLogObserver(sys.stdout, log_formatter) @@ -626,15 +655,16 @@ just `+': all DFLAGs. stdsomething_obs = twisted.logger.FilteringLogObserver( stderr_obs, [pred], stdout_obs ) - log_observer = twisted.logger.FilteringLogObserver( + global file_log_observer + file_log_observer = twisted.logger.FilteringLogObserver( stdsomething_obs, [LogNotBoringTwisted()] ) #log_observer = stdsomething_obs twisted.logger.globalLogBeginner.beginLoggingTo( - [ log_observer, crash_on_critical ] + [ file_log_observer, crash_on_critical ] ) def common_run(): log_debug(DBG.INIT, 'entering reactor') if not _crashing: reactor.run() - print('CRASHED (end)', file=sys.stderr) + print('ENDED', file=sys.stderr)