diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2010-11-09 00:18:19 +0100 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2010-11-09 00:18:19 +0100 |
| commit | cf27be9bc60d18a558226ca7d248cffbf4324515 (patch) | |
| tree | 013c378fa60d3afc3b2469ab7b9ea4b2420fd73b | |
| parent | 52066a97a2e7931155d7a3d4fdda4082f9b6f9eb (diff) | |
| download | alias-cf27be9bc60d18a558226ca7d248cffbf4324515.tar.gz | |
Parse the command line to get component connection parameters.
Much better than being hard coded.
| -rw-r--r-- | server.py | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -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" |
