8c722dece1
Let the user see errors reported in read_paths.
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import os
|
|
import pathlib
|
|
import logging
|
|
import sys
|
|
|
|
from . import bot as bot_mod, config as config_mod
|
|
|
|
def parse_arguments(arglist):
|
|
try:
|
|
config_dir = pathlib.Path(os.environ['XDG_CONFIG_DIR'])
|
|
except KeyError:
|
|
if os.getuid():
|
|
config_dir = pathlib.Path.home() / '.config'
|
|
else:
|
|
config_dir = pathlib.Path('/etc')
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
'--config-file', '-C',
|
|
type=pathlib.Path,
|
|
default=config_dir / 'forwardxmpp/config.ini',
|
|
help="Path to INI configuration file."
|
|
" Default %(default)s.",
|
|
)
|
|
return parser.parse_args(arglist)
|
|
|
|
def setup_logger(logger, loglevel, stream):
|
|
formatter = logging.Formatter('%(name)s: %(levelname)s: %(message)s')
|
|
handler = logging.StreamHandler(stream)
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
logger.setLevel(loglevel)
|
|
|
|
def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr):
|
|
args = parse_arguments(arglist)
|
|
root_logger = logging.getLogger()
|
|
config = config_mod.Config()
|
|
setup_logger(root_logger, config.get_loglevel(), stderr)
|
|
for _ in config.read_paths([args.config_file]):
|
|
pass
|
|
root_logger.setLevel(config.get_loglevel())
|
|
if not config.ready():
|
|
return 3
|
|
bot = bot_mod.ForwardBot(config)
|
|
bot.connect()
|
|
bot.process()
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
exit(main())
|