From 3071afe3d4203babe9d1f09c00f8713f5b7e01db Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 11 Oct 2012 16:20:38 -0400 Subject: [PATCH] zephyr_mirror: Automatically subscribe to streams in ~/.zephyr.subs. (imported from commit b28b28a81416c52813975c2cdbf65d282deec3df) --- zephyr_mirror.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/zephyr_mirror.py b/zephyr_mirror.py index ac1b452..676ed44 100644 --- a/zephyr_mirror.py +++ b/zephyr_mirror.py @@ -37,6 +37,10 @@ parser.add_option('--forward-from-humbug', dest='forward_to_humbug', default=True, action='store_false') +parser.add_option('--no-auto-subscribe', + dest='auto_subscribe', + default=True, + action='store_false') parser.add_option('--site', dest='site', default="https://app.humbughq.com", @@ -286,7 +290,33 @@ def humbug_to_zephyr(options): humbug_client.call_on_each_message(maybe_forward_to_zephyr, options={"mit_sync_bot": 'yes'}) +def add_humbug_subscriptions(): + print "Adding your ~/.zephyr.subs subscriptions to Humbug!" + zephyr_subscriptions = set() + subs_file = os.path.join(os.environ["HOME"], ".zephyr.subs") + if not os.path.exists(subs_file): + print >>sys.stderr, "Couldn't find .zephyr.subs!" + print >>sys.stderr, "Do you mean to run with --no-auto-subscribe?" + return + + for line in file(subs_file, "r").readlines(): + line = line.strip() + if len(line) == 0: + continue + try: + (cls, instance, recipient) = line.split(",") + if instance != "*" or recipient != "*": + print "Skipping ~/.zephyr.subs line: [%s] due to non-* values" % (line,) + continue + zephyr_subscriptions.add(cls) + except: + print >>sys.stderr, "Couldn't parse ~/.zephyr.subs file line: [%s]" % (line,) + if len(zephyr_subscriptions) != 0: + humbug_client.subscribe(list(zephyr_subscriptions)) + if options.forward_to_humbug: + if options.auto_subscribe: + add_humbug_subscriptions() zephyr_to_humbug(options) else: humbug_to_zephyr(options)