jabber_mirror: Use the Zulip API option group

(imported from commit 68243e4ebd44cd3b08bf0789c34bb85016d0d1b9)
This commit is contained in:
Zev Benjamin 2014-02-21 14:28:12 -05:00
parent 5ba0b6b633
commit 4d47f487cb
1 changed files with 5 additions and 11 deletions

View File

@ -131,7 +131,7 @@ class JabberToZulipBot(ClientXMPP):
class ZulipToJabberBot(zulip.Client): class ZulipToJabberBot(zulip.Client):
def __init__(self, email, api_key): def __init__(self, email, api_key):
zulip.Client.__init__(self, email, api_key, client="jabber_mirror", zulip.Client.__init__(self, email, api_key, client="jabber_mirror",
site=options.zulip_server, verbose=False) site=options.zulip_site, verbose=False)
self.jabber = None self.jabber = None
self.email = email self.email = email
@ -198,29 +198,23 @@ if __name__ == '__main__':
parser.add_option('--no-use-tls', parser.add_option('--no-use-tls',
default=False, default=False,
action='store_true') action='store_true')
parser.add_option('--zulip-server',
default="https://api.zulip.com",
action='store',
help="Your Zulip API server (only needed for Zulip Enterprise)")
parser.add_option('--conference-domain', parser.add_option('--conference-domain',
default=None, default=None,
action='store', action='store',
help="Your Jabber conference domain (E.g. conference.jabber.example.com)") help="Your Jabber conference domain (E.g. conference.jabber.example.com)")
parser.add_option_group(zulip.generate_option_group(parser, "zulip-"))
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) < 2:
sys.exit("Usage: %s EMAIL ZULIP_APIKEY" % (sys.argv[0],));
email = args[0]
zulip_api_key = args[1]
if options.password is None: if options.password is None:
options.password = getpass.getpass("Jabber password: ") options.password = getpass.getpass("Jabber password: ")
if options.jabber_domain is None: if options.jabber_domain is None:
sys.exit("Must specify a Jabber server") sys.exit("Must specify a Jabber server")
(username, options.zulip_domain) = email.split("@") (username, options.zulip_domain) = options.zulip_email.split("@")
jabber_username = username + '@' + options.jabber_domain jabber_username = username + '@' + options.jabber_domain
zulip = ZulipToJabberBot(email=email, api_key=zulip_api_key); zulip = ZulipToJabberBot(email=options.zulip_email, api_key=options.zulip_api_key);
rooms = [s['name'] for s in zulip.get_streams()['streams']] rooms = [s['name'] for s in zulip.get_streams()['streams']]
xmpp = JabberToZulipBot(jabber_username, options.password, rooms, xmpp = JabberToZulipBot(jabber_username, options.password, rooms,
openfire=options.openfire) openfire=options.openfire)