aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2010-11-20 22:54:01 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2010-11-20 22:54:01 +0100
commit374b2adb8a7ee55c5cad87955add772096f73999 (patch)
treebffb6cb3018e74b7a43b1c4b69b2ecd30ac871ea /server.py
parentf3fbfe116584393f5b373d98541c803c695f6ffb (diff)
downloadalias-374b2adb8a7ee55c5cad87955add772096f73999.tar.gz
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.
Diffstat (limited to 'server.py')
-rw-r--r--server.py28
1 files changed, 22 insertions, 6 deletions
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"