From cf27be9bc60d18a558226ca7d248cffbf4324515 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Tue, 9 Nov 2010 00:18:19 +0100 Subject: Parse the command line to get component connection parameters. Much better than being hard coded. --- server.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index fcc4d89..705ebb7 100644 --- a/server.py +++ b/server.py @@ -1,4 +1,5 @@ -from sleekxmpp.componentxmpp import ComponentXMPP +from sleekxmpp.componentxmpp import ComponentXMPP +from argparse import ArgumentParser class ObjectComponent(ComponentXMPP): @@ -14,7 +15,22 @@ class ObjectComponent(ComponentXMPP): msg.reply("Thanks for sending\n%(body)s" % msg).send() if __name__ == '__main__' : - component = ObjectComponent("object.alias.fr.nf", "toto", "localhost", 5347) - component.connect() - component.process() + commandline = ArgumentParser(description='Connect the alias component to a given server') + commandline.add_argument('-p', '--port', + help='Port to connect to', + type=int) + commandline.add_argument('-s', '--secret', + help='password') + commandline.add_argument('-n', '--name', + help='Name the component will have') + commandline.add_argument('host', + help='Host to connect to') + args = commandline.parse_args() + component = ObjectComponent(args.name, args.secret,args.host,args.port) + + if component.connect() : + print 'Component', args.name, 'connected to', args.host + ':' + str(args.port) + component.process() + else : + print "Couldn't connect" -- cgit v1.2.3-70-g09d2