Move examples from the deprecated optparse to argparse, and remove the redundant -v option.

This commit is contained in:
Emmanuel Gil Peyrot 2014-08-16 22:37:29 +02:00 committed by Florent Le Coz
parent 67ca2dd0f4
commit 8660148960
26 changed files with 632 additions and 731 deletions

View File

@ -23,7 +23,7 @@ import datetime
from glob import glob from glob import glob
from os.path import splitext, basename, join as pjoin from os.path import splitext, basename, join as pjoin
from optparse import OptionParser from argparse import ArgumentParser
from urllib import urlopen from urllib import urlopen
import slixmpp import slixmpp
@ -115,47 +115,44 @@ if __name__ == '__main__':
# #
# "client" an IoT device or other party that would like to get data from another device # "client" an IoT device or other party that would like to get data from another device
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM', parser.add_argument("-t", "--pingto", help="set jid to ping",
action='store_const', dest='loglevel', action="store", type="string", dest="pingjid",
const=5, default=logging.INFO)
optp.add_option('-t', '--pingto', help='set jid to ping',
action='store', type='string', dest='pingjid',
default=None) default=None)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
# IoT test # IoT test
optp.add_option("-c", "--sensorjid", dest="sensorjid", parser.add_argument("-c", "--sensorjid", dest="sensorjid",
help="Another device to call for data on", default=None) help="Another device to call for data on", default=None)
optp.add_option("-n", "--nodeid", dest="nodeid", parser.add_argument("-n", "--nodeid", dest="nodeid",
help="I am a device get ready to be called", default=None) help="I am a device get ready to be called", default=None)
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = IoT_TestDevice(opts.jid,opts.password) xmpp = IoT_TestDevice(args.jid,args.password)
xmpp.register_plugin('xep_0030') xmpp.register_plugin('xep_0030')
#xmpp['xep_0030'].add_feature(feature='urn:xmpp:iot:sensordata', #xmpp['xep_0030'].add_feature(feature='urn:xmpp:iot:sensordata',
# node=None, # node=None,
@ -163,27 +160,27 @@ if __name__ == '__main__':
xmpp.register_plugin('xep_0323') xmpp.register_plugin('xep_0323')
xmpp.register_plugin('xep_0325') xmpp.register_plugin('xep_0325')
if opts.nodeid: if args.nodeid:
# xmpp['xep_0030'].add_feature(feature='urn:xmpp:sn', # xmpp['xep_0030'].add_feature(feature='urn:xmpp:sn',
# node=opts.nodeid, # node=args.nodeid,
# jid=xmpp.boundjid.full) # jid=xmpp.boundjid.full)
myDevice = TheDevice(opts.nodeid); myDevice = TheDevice(args.nodeid);
# myDevice._add_field(name="Relay", typename="numeric", unit="Bool"); # myDevice._add_field(name="Relay", typename="numeric", unit="Bool");
myDevice._add_field(name="Temperature", typename="numeric", unit="C"); myDevice._add_field(name="Temperature", typename="numeric", unit="C");
myDevice._set_momentary_timestamp("2013-03-07T16:24:30") myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}); myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10); xmpp['xep_0323'].register_node(nodeId=args.nodeid, device=myDevice, commTimeout=10);
xmpp.beClientOrServer(server=True) xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()): while not(xmpp.testForRelease()):
xmpp.connect() xmpp.connect()
xmpp.process(block=True) xmpp.process(block=True)
logging.debug("lost connection") logging.debug("lost connection")
if opts.sensorjid: if args.sensorjid:
logging.debug("will try to call another device for data") logging.debug("will try to call another device for data")
xmpp.beClientOrServer(server=False,clientJID=opts.sensorjid) xmpp.beClientOrServer(server=False,clientJID=args.sensorjid)
xmpp.connect() xmpp.connect()
xmpp.process(block=True) xmpp.process(block=True)
logging.debug("ready ending") logging.debug("ready ending")

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -132,40 +132,37 @@ class CommandBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the CommandBot and register plugins. Note that while plugins may # Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = CommandBot(opts.jid, opts.password) xmpp = CommandBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands xmpp.register_plugin('xep_0050') # Adhoc Commands

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -131,48 +131,45 @@ class CommandUserBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-o", "--other", dest="other", parser.add_argument("-o", "--other", dest="other",
help="JID providing commands") help="JID providing commands")
optp.add_option("-g", "--greeting", dest="greeting", parser.add_argument("-g", "--greeting", dest="greeting",
help="Greeting") help="Greeting")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.other is None: if args.other is None:
opts.other = input("JID Providing Commands: ") args.other = input("JID Providing Commands: ")
if opts.greeting is None: if args.greeting is None:
opts.greeting = input("Greeting: ") args.greeting = input("Greeting: ")
# Setup the CommandBot and register plugins. Note that while plugins may # Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = CommandUserBot(opts.jid, opts.password, opts.other, opts.greeting) xmpp = CommandUserBot(args.jid, args.password, args.other, args.greeting)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands xmpp.register_plugin('xep_0050') # Adhoc Commands

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -105,44 +105,41 @@ class AdminCommands(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-c", "--command", dest="command", parser.add_argument("-c", "--command", dest="command",
help="admin command to use") help="admin command to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.command is None: if args.command is None:
opts.command = input("Admin command: ") args.command = input("Admin command: ")
# Setup the CommandBot and register plugins. Note that while plugins may # Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = AdminCommands(opts.jid, opts.password, opts.command) xmpp = AdminCommands(args.jid, args.password, args.command)
xmpp.register_plugin('xep_0133') # Service Administration xmpp.register_plugin('xep_0133') # Service Administration
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -96,40 +96,37 @@ class ActionBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the CommandBot and register plugins. Note that while plugins may # Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = ActionBot(opts.jid, opts.password) xmpp = ActionBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands xmpp.register_plugin('xep_0050') # Adhoc Commands

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp import Iq from slixmpp import Iq
@ -100,44 +100,41 @@ class ActionUserBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-o", "--other", dest="other", parser.add_argument("-o", "--other", dest="other",
help="JID providing custom stanza") help="JID providing custom stanza")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.other is None: if args.other is None:
opts.other = input("JID Providing custom stanza: ") args.other = input("JID Providing custom stanza: ")
# Setup the CommandBot and register plugins. Note that while plugins may # Setup the CommandBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = ActionUserBot(opts.jid, opts.password, opts.other) xmpp = ActionUserBot(args.jid, args.password, args.other)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0050') # Adhoc Commands xmpp.register_plugin('xep_0050') # Adhoc Commands

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
@ -124,52 +124,41 @@ class Disco(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser(description=Disco.__doc__)
optp.version = '%%prog 0.1'
optp.usage = "Usage: %%prog [options] %s <jid> [<node>]" % \
'all|info|items|identities|features'
optp.add_option('-q','--quiet', help='set logging to ERROR', parser.add_argument("-q","--quiet", help="set logging to ERROR",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.ERROR, const=logging.ERROR,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-d','--debug', help='set logging to DEBUG', parser.add_argument("-d","--debug", help="set logging to DEBUG",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.DEBUG, const=logging.DEBUG,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-v','--verbose', help='set logging to COMM',
action='store_const',
dest='loglevel',
const=5,
default=logging.ERROR)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts,args = optp.parse_args() parser.add_argument("query", choices=["all", "info", "items", "identities", "features"])
parser.add_argument("target-jid")
parser.add_argument("node", nargs='?')
args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if len(args) < 2: if args.jid is None:
optp.print_help() args.jid = input("Username: ")
exit() if args.password is None:
args.password = getpass("Password: ")
if len(args) == 2:
args = (args[0], args[1], '')
if opts.jid is None:
opts.jid = input("Username: ")
if opts.password is None:
opts.password = getpass("Password: ")
# Setup the Disco browser. # Setup the Disco browser.
xmpp = Disco(opts.jid, opts.password, args[1], args[2], args[0]) xmpp = Disco(args.jid, args.password, args.target_jid, args.node, args.query)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -12,7 +12,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
import threading import threading
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.exceptions import XMPPError from slixmpp.exceptions import XMPPError
@ -113,40 +113,36 @@ class AvatarDownloader(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
optp.add_option('-q','--quiet', help='set logging to ERROR', parser.add_argument("-q","--quiet", help="set logging to ERROR",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.ERROR, const=logging.ERROR,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-d','--debug', help='set logging to DEBUG', parser.add_argument("-d","--debug", help="set logging to DEBUG",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.DEBUG, const=logging.DEBUG,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-v','--verbose', help='set logging to COMM',
action='store_const',
dest='loglevel',
const=5,
default=logging.ERROR)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts,args = optp.parse_args()
args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = AvatarDownloader(opts.jid, opts.password) xmpp = AvatarDownloader(args.jid, args.password)
xmpp.register_plugin('xep_0054') xmpp.register_plugin('xep_0054')
xmpp.register_plugin('xep_0153') xmpp.register_plugin('xep_0153')
xmpp.register_plugin('xep_0084') xmpp.register_plugin('xep_0084')

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -72,40 +72,37 @@ class EchoBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser(description=EchoBot.__doc__)
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the EchoBot and register plugins. Note that while plugins may # Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = EchoBot(opts.jid, opts.password) xmpp = EchoBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub xmpp.register_plugin('xep_0060') # PubSub

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.componentxmpp import ComponentXMPP from slixmpp.componentxmpp import ComponentXMPP
@ -56,48 +56,45 @@ class EchoComponent(ComponentXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser(description=EchoComponent.__doc__)
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-s", "--server", dest="server", parser.add_argument("-s", "--server", dest="server",
help="server to connect to") help="server to connect to")
optp.add_option("-P", "--port", dest="port", parser.add_argument("-P", "--port", dest="port",
help="port to connect to") help="port to connect to")
opts, args = optp.parse_args() args = parser.parse_args()
if opts.jid is None: if args.jid is None:
opts.jid = input("Component JID: ") args.jid = input("Component JID: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.server is None: if args.server is None:
opts.server = input("Server: ") args.server = input("Server: ")
if opts.port is None: if args.port is None:
opts.port = int(input("Port: ")) args.port = int(input("Port: "))
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
# Setup the EchoComponent and register plugins. Note that while plugins # Setup the EchoComponent and register plugins. Note that while plugins
# may have interdependencies, the order in which you register them does # may have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = EchoComponent(opts.jid, opts.password, opts.server, opts.port) xmpp = EchoComponent(args.jid, args.password, args.server, args.port)
xmpp.registerPlugin('xep_0030') # Service Discovery xmpp.registerPlugin('xep_0030') # Service Discovery
xmpp.registerPlugin('xep_0004') # Data Forms xmpp.registerPlugin('xep_0004') # Data Forms
xmpp.registerPlugin('xep_0060') # PubSub xmpp.registerPlugin('xep_0060') # PubSub

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -92,40 +92,37 @@ class GTalkBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the GTalkBot and register plugins. Note that while plugins may # Setup the GTalkBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = GTalkBot(opts.jid, opts.password) xmpp = GTalkBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub xmpp.register_plugin('xep_0060') # PubSub

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -82,37 +82,34 @@ class IBBReceiver(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = IBBReceiver(opts.jid, opts.password) xmpp = IBBReceiver(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -64,48 +64,45 @@ class IBBSender(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-r", "--receiver", dest="receiver", parser.add_argument("-r", "--receiver", dest="receiver",
help="JID to use") help="JID to use")
optp.add_option("-f", "--file", dest="filename", parser.add_argument("-f", "--file", dest="filename",
help="JID to use") help="JID to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.receiver is None: if args.receiver is None:
opts.receiver = input("Receiver: ") args.receiver = input("Receiver: ")
if opts.filename is None: if args.filename is None:
opts.filename = input("File path: ") args.filename = input("File path: ")
# Setup the EchoBot and register plugins. Note that while plugins may # Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = IBBSender(opts.jid, opts.password, opts.receiver, opts.filename) xmpp = IBBSender(args.jid, args.password, args.receiver, args.filename)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0047') # In-band Bytestreams xmpp.register_plugin('xep_0047') # In-band Bytestreams

View File

@ -4,55 +4,52 @@
import sys import sys
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("--oldjid", dest="old_jid", parser.add_argument("--oldjid", dest="old_jid",
help="JID of the old account") help="JID of the old account")
optp.add_option("--oldpassword", dest="old_password", parser.add_argument("--oldpassword", dest="old_password",
help="password of the old account") help="password of the old account")
optp.add_option("--newjid", dest="new_jid", parser.add_argument("--newjid", dest="new_jid",
help="JID of the old account") help="JID of the old account")
optp.add_option("--newpassword", dest="new_password", parser.add_argument("--newpassword", dest="new_password",
help="password of the old account") help="password of the old account")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.old_jid is None: if args.old_jid is None:
opts.old_jid = input("Old JID: ") args.old_jid = input("Old JID: ")
if opts.old_password is None: if args.old_password is None:
opts.old_password = getpass("Old Password: ") args.old_password = getpass("Old Password: ")
if opts.new_jid is None: if args.new_jid is None:
opts.new_jid = input("New JID: ") args.new_jid = input("New JID: ")
if opts.new_password is None: if args.new_password is None:
opts.new_password = getpass("New Password: ") args.new_password = getpass("New Password: ")
old_xmpp = slixmpp.ClientXMPP(opts.old_jid, opts.old_password) old_xmpp = slixmpp.ClientXMPP(args.old_jid, args.old_password)
# If you are connecting to Facebook and wish to use the # If you are connecting to Facebook and wish to use the
# X-FACEBOOK-PLATFORM authentication mechanism, you will need # X-FACEBOOK-PLATFORM authentication mechanism, you will need
@ -88,7 +85,7 @@ if not roster:
print('No roster to migrate') print('No roster to migrate')
sys.exit() sys.exit()
new_xmpp = slixmpp.ClientXMPP(opts.new_jid, opts.new_password) new_xmpp = slixmpp.ClientXMPP(args.new_jid, args.new_password)
def on_session2(event): def on_session2(event):
new_xmpp.get_roster() new_xmpp.get_roster()
new_xmpp.send_presence() new_xmpp.send_presence()

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -121,48 +121,45 @@ class MUCBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-r", "--room", dest="room", parser.add_argument("-r", "--room", dest="room",
help="MUC room to join") help="MUC room to join")
optp.add_option("-n", "--nick", dest="nick", parser.add_argument("-n", "--nick", dest="nick",
help="MUC nickname") help="MUC nickname")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.room is None: if args.room is None:
opts.room = input("MUC room: ") args.room = input("MUC room: ")
if opts.nick is None: if args.nick is None:
opts.nick = input("MUC nickname: ") args.nick = input("MUC nickname: ")
# Setup the MUCBot and register plugins. Note that while plugins may # Setup the MUCBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = MUCBot(opts.jid, opts.password, opts.room, opts.nick) xmpp = MUCBot(args.jid, args.password, args.room, args.nick)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0199') # XMPP Ping xmpp.register_plugin('xep_0199') # XMPP Ping

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -68,43 +68,40 @@ class PingTest(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM', parser.add_argument("-t", "--pingto", help="set jid to ping",
action='store_const', dest='loglevel', action="store", type="string", dest="pingjid",
const=5, default=logging.INFO)
optp.add_option('-t', '--pingto', help='set jid to ping',
action='store', type='string', dest='pingjid',
default=None) default=None)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the PingTest and register plugins. Note that while plugins may # Setup the PingTest and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = PingTest(opts.jid, opts.password, opts.pingjid) xmpp = PingTest(args.jid, args.password, args.pingjid)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub xmpp.register_plugin('xep_0060') # PubSub

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -71,58 +71,53 @@ class EchoBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("--phost", dest="proxy_host", parser.add_argument("--phost", dest="proxy_host",
help="Proxy hostname") help="Proxy hostname")
optp.add_option("--pport", dest="proxy_port", parser.add_argument("--pport", dest="proxy_port",
help="Proxy port") help="Proxy port")
optp.add_option("--puser", dest="proxy_user", parser.add_argument("--puser", dest="proxy_user",
help="Proxy username") help="Proxy username")
optp.add_option("--ppass", dest="proxy_pass", parser.add_argument("--ppass", dest="proxy_pass",
help="Proxy password") help="Proxy password")
args = parser.parse_args()
opts, args = optp.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.proxy_host is None: if args.proxy_host is None:
opts.proxy_host = input("Proxy host: ") args.proxy_host = input("Proxy host: ")
if opts.proxy_port is None: if args.proxy_port is None:
opts.proxy_port = input("Proxy port: ") args.proxy_port = input("Proxy port: ")
if opts.proxy_user is None: if args.proxy_user is None:
opts.proxy_user = input("Proxy username: ") args.proxy_user = input("Proxy username: ")
if opts.proxy_pass is None and opts.proxy_user: if args.proxy_pass is None and args.proxy_user:
opts.proxy_pass = getpass("Proxy password: ") args.proxy_pass = getpass("Proxy password: ")
# Setup the EchoBot and register plugins. Note that while plugins may # Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = EchoBot(opts.jid, opts.password) xmpp = EchoBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub xmpp.register_plugin('xep_0060') # PubSub
@ -130,10 +125,10 @@ if __name__ == '__main__':
xmpp.use_proxy = True xmpp.use_proxy = True
xmpp.proxy_config = { xmpp.proxy_config = {
'host': opts.proxy_host, 'host': args.proxy_host,
'port': int(opts.proxy_port), 'port': int(args.proxy_port),
'username': opts.proxy_user, 'username': args.proxy_user,
'password': opts.proxy_pass} 'password': args.proxy_pass}
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -3,7 +3,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.xmlstream import ET, tostring from slixmpp.xmlstream import ET, tostring
@ -111,62 +111,51 @@ class PubsubClient(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
optp.version = '%%prog 0.1' parser.version = '%%prog 0.1'
optp.usage = "Usage: %%prog [options] <jid> " + \ parser.usage = "Usage: %%prog [options] <jid> " + \
'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \ 'nodes|create|delete|purge|subscribe|unsubscribe|publish|retract|get' + \
' [<node> <data>]' ' [<node> <data>]'
optp.add_option('-q','--quiet', help='set logging to ERROR', parser.add_argument("-q","--quiet", help="set logging to ERROR",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.ERROR, const=logging.ERROR,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-d','--debug', help='set logging to DEBUG', parser.add_argument("-d","--debug", help="set logging to DEBUG",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.DEBUG, const=logging.DEBUG,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-v','--verbose', help='set logging to COMM',
action='store_const',
dest='loglevel',
const=5,
default=logging.ERROR)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts,args = optp.parse_args()
parser.add_argument("server")
parser.add_argument("action", choice=["nodes", "create", "delete", "purge", "subscribe", "unsubscribe", "publish", "retract", "get"])
parser.add_argument("node", nargs='?')
parser.add_argument("data", nargs='?')
args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if len(args) < 2: if args.jid is None:
optp.print_help() args.jid = input("Username: ")
exit() if args.password is None:
args.password = getpass("Password: ")
if opts.jid is None:
opts.jid = input("Username: ")
if opts.password is None:
opts.password = getpass("Password: ")
if len(args) == 2:
args = (args[0], args[1], '', '', '')
elif len(args) == 3:
args = (args[0], args[1], args[2], '', '')
elif len(args) == 4:
args = (args[0], args[1], args[2], args[3], '')
# Setup the Pubsub client # Setup the Pubsub client
xmpp = PubsubClient(opts.jid, opts.password, xmpp = PubsubClient(args.jid, args.password,
server=args[0], server=args.server,
node=args[2], node=args.node,
action=args[1], action=args.action,
data=args[3]) data=args.data)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -3,7 +3,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.xmlstream import ET, tostring from slixmpp.xmlstream import ET, tostring
@ -84,41 +84,38 @@ class PubsubEvents(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
logging.info("Run this in conjunction with the pubsub_client.py " + \ logging.info("Run this in conjunction with the pubsub_client.py " + \
"example to watch events happen as you give commands.") "example to watch events happen as you give commands.")
# Setup the PubsubEvents listener # Setup the PubsubEvents listener
xmpp = PubsubEvents(opts.jid, opts.password) xmpp = PubsubEvents(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
@ -103,40 +103,37 @@ class RegisterBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
# Setup the RegisterBot and register plugins. Note that while plugins may # Setup the RegisterBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = RegisterBot(opts.jid, opts.password) xmpp = RegisterBot(args.jid, args.password)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data forms xmpp.register_plugin('xep_0004') # Data forms
xmpp.register_plugin('xep_0066') # Out-of-band Data xmpp.register_plugin('xep_0066') # Out-of-band Data

View File

@ -12,7 +12,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
import threading import threading
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
@ -101,40 +101,36 @@ class RosterBrowser(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
optp.add_option('-q','--quiet', help='set logging to ERROR', parser.add_argument("-q","--quiet", help="set logging to ERROR",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.ERROR, const=logging.ERROR,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-d','--debug', help='set logging to DEBUG', parser.add_argument("-d","--debug", help="set logging to DEBUG",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.DEBUG, const=logging.DEBUG,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-v','--verbose', help='set logging to COMM',
action='store_const',
dest='loglevel',
const=5,
default=logging.ERROR)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts,args = optp.parse_args()
args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = RosterBrowser(opts.jid, opts.password) xmpp = RosterBrowser(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -11,7 +11,7 @@
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
@ -65,48 +65,45 @@ class SendMsgBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser(description=SendMsgBot.__doc__)
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-t", "--to", dest="to", parser.add_argument("-t", "--to", dest="to",
help="JID to send the message to") help="JID to send the message to")
optp.add_option("-m", "--message", dest="message", parser.add_argument("-m", "--message", dest="message",
help="message to send") help="message to send")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.to is None: if args.to is None:
opts.to = input("Send To: ") args.to = input("Send To: ")
if opts.message is None: if args.message is None:
opts.message = input("Message: ") args.message = input("Message: ")
# Setup the EchoBot and register plugins. Note that while plugins may # Setup the EchoBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = SendMsgBot(opts.jid, opts.password, opts.to, opts.message) xmpp = SendMsgBot(args.jid, args.password, args.to, args.message)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0199') # XMPP Ping xmpp.register_plugin('xep_0199') # XMPP Ping

View File

@ -14,7 +14,7 @@ import imghdr
import logging import logging
from getpass import getpass from getpass import getpass
import threading import threading
from optparse import OptionParser from argparse import ArgumentParser
import slixmpp import slixmpp
from slixmpp.exceptions import XMPPError from slixmpp.exceptions import XMPPError
@ -99,44 +99,40 @@ class AvatarSetter(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
optp.add_option('-q','--quiet', help='set logging to ERROR', parser.add_argument("-q","--quiet", help="set logging to ERROR",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.ERROR, const=logging.ERROR,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-d','--debug', help='set logging to DEBUG', parser.add_argument("-d","--debug", help="set logging to DEBUG",
action='store_const', action="store_const",
dest='loglevel', dest="loglevel",
const=logging.DEBUG, const=logging.DEBUG,
default=logging.ERROR) default=logging.ERROR)
optp.add_option('-v','--verbose', help='set logging to COMM',
action='store_const',
dest='loglevel',
const=5,
default=logging.ERROR)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
optp.add_option("-f", "--file", dest="filepath", parser.add_argument("-f", "--file", dest="filepath",
help="path to the avatar file") help="path to the avatar file")
opts,args = optp.parse_args()
args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
if opts.filepath is None: if args.filepath is None:
opts.filepath = input("Avatar file location: ") args.filepath = input("Avatar file location: ")
xmpp = AvatarSetter(opts.jid, opts.password, opts.filepath) xmpp = AvatarSetter(args.jid, args.password, args.filepath)
xmpp.register_plugin('xep_0054') xmpp.register_plugin('xep_0054')
xmpp.register_plugin('xep_0153') xmpp.register_plugin('xep_0153')
xmpp.register_plugin('xep_0084') xmpp.register_plugin('xep_0084')

View File

@ -12,7 +12,7 @@
import sys import sys
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
try: try:
from httplib import HTTPSConnection from httplib import HTTPSConnection
@ -94,35 +94,32 @@ class ThirdPartyAuthBot(slixmpp.ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
access_token = None access_token = None
@ -146,8 +143,8 @@ if __name__ == '__main__':
params = urlencode({ params = urlencode({
'accountType': 'GOOGLE', 'accountType': 'GOOGLE',
'service': 'mail', 'service': 'mail',
'Email': JID(opts.jid).bare, 'Email': JID(args.jid).bare,
'Passwd': opts.password 'Passwd': args.password
}) })
headers = { headers = {
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
@ -198,7 +195,7 @@ if __name__ == '__main__':
# We're using an access token instead of a password, so we'll use `''` as # We're using an access token instead of a password, so we'll use `''` as
# a password argument filler. # a password argument filler.
xmpp = ThirdPartyAuthBot(opts.jid, '') xmpp = ThirdPartyAuthBot(args.jid, '')
xmpp.credentials['access_token'] = access_token xmpp.credentials['access_token'] = access_token
# The credentials dictionary is used to provide additional authentication # The credentials dictionary is used to provide additional authentication

View File

@ -3,7 +3,7 @@
import sys import sys
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
try: try:
import json import json
@ -71,37 +71,34 @@ class LocationBot(ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = LocationBot(opts.jid, opts.password) xmpp = LocationBot(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()

View File

@ -3,7 +3,7 @@
import sys import sys
import logging import logging
from getpass import getpass from getpass import getpass
from optparse import OptionParser from argparse import ArgumentParser
try: try:
from appscript import * from appscript import *
@ -83,37 +83,34 @@ class TuneBot(ClientXMPP):
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
optp = OptionParser() parser = ArgumentParser()
# Output verbosity options. # Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR', parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.ERROR, default=logging.INFO) const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG', parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action='store_const', dest='loglevel', action="store_const", dest="loglevel",
const=logging.DEBUG, default=logging.INFO) const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options. # JID and password options.
optp.add_option("-j", "--jid", dest="jid", parser.add_argument("-j", "--jid", dest="jid",
help="JID to use") help="JID to use")
optp.add_option("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="password to use") help="password to use")
opts, args = optp.parse_args() args = parser.parse_args()
# Setup logging. # Setup logging.
logging.basicConfig(level=opts.loglevel, logging.basicConfig(level=args.loglevel,
format='%(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s')
if opts.jid is None: if args.jid is None:
opts.jid = input("Username: ") args.jid = input("Username: ")
if opts.password is None: if args.password is None:
opts.password = getpass("Password: ") args.password = getpass("Password: ")
xmpp = TuneBot(opts.jid, opts.password) xmpp = TuneBot(args.jid, args.password)
# Connect to the XMPP server and start processing XMPP stanzas. # Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect() xmpp.connect()