From 374b2adb8a7ee55c5cad87955add772096f73999 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sat, 20 Nov 2010 22:54:01 +0100 Subject: Add config file feature. New -c switch to specify a config file on the command line. See config.ini.sample for an example of a config file. The configuration options can then be shared across modules : just import config module. --- server.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index 187aec7..0395799 100644 --- a/server.py +++ b/server.py @@ -1,11 +1,11 @@ import logging -import ConfigParser from argparse import ArgumentParser from sleekxmpp.componentxmpp import ComponentXMPP from sleekxmpp.xmlstream.xmlstream import XMLStream from user import UserHandler +from config import filename, config class ObjectComponent(ComponentXMPP): @@ -58,20 +58,36 @@ if __name__ == '__main__': help = 'Name the component will have') commandline.add_argument('-r', '--root', help = 'Root directory of the user files') + commandline.add_argument('-c', '--config', + help = 'Name of the config file to use') commandline.add_argument('-d', '--debug', help = 'Set log level to DEBUG', action = 'store_const', const = logging.DEBUG, default = logging.INFO) - commandline.add_argument('host', + commandline.add_argument('-o', '--host', help = 'Host to connect to') + args = commandline.parse_args() - logging.basicConfig(level = args.debug) - component = ObjectComponent(args.name, args.secret, - args.host, args.port, args.root) + + if args.config is None: + logging.basicConfig(level = args.debug) + config.name = args.name + config.port = args.port + config.secret = args.secret + config.root = args.root + config.host = args.host + else: + filename = args.config + logging.basicConfig(level = args.debug) + config.read(filename) + + component = ObjectComponent(config.name, config.secret, + config.host, config.port, + config.root) if component.connect(): - logging.info('Component {} connected'.format(args.name)) + logging.info('Component {} connected'.format(component.boundjid)) component.process(False) else : print "Couldn't connect" -- cgit v1.2.3-70-g09d2