--- a/requirements.txt Tue May 10 14:33:06 2016 +0800
+++ b/requirements.txt Tue May 10 17:17:47 2016 +0800
--- a/rollbot.py Tue May 10 14:33:06 2016 +0800
+++ b/rollbot.py Tue May 10 17:17:47 2016 +0800
-from argparse import ArgumentParser
+from argparse import ArgumentParser, FileType, SUPPRESS
self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True)
- parser = ArgumentParser()
+def lookup(key, args, config, default=None):
+ return getattr(args, key)
+ return config.get(key, default)
- parser.add_argument('-j', '--jid', help='JID to use')
- parser.add_argument('-p', '--password', help='password to use')
- parser.add_argument('-n', '--nick', help='MUC nickname', default='rollbot')
+ parser = ArgumentParser(argument_default=SUPPRESS)
+ parser.add_argument('-c', '--config', help='configuration file (YAML)', type=FileType('r'))
+ group = parser.add_argument_group('main configuration', 'options that can be specified in the configuration file')
+ group.add_argument('-j', '--jid', help='JID to use')
+ group.add_argument('-p', '--password', help='password to use')
+ group.add_argument('-n', '--nick', help='MUC nickname')
group = parser.add_mutually_exclusive_group()
group.add_argument('-q', '--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO)
logging.basicConfig(level=args.loglevel, format='%(asctime)s %(levelname)-8s %(message)s')
- rollbot = RollBot(args.jid, args.password, args.nick)
+ if hasattr(args, 'config'):
+ config = yaml.safe_load(args.config)
+ jid = lookup('jid', args, config)
+ password = lookup('password', args, config)
+ nick = lookup('nick', args, config, default='rollbot')
+ rollbot = RollBot(jid, password, nick)
rollbot.auto_authorize = True
rollbot.auto_subscribe = True
rollbot.register_plugin('xep_0030') # Service Discovery