zephyr_mirror: Add a test mode that just prints messages.

This is useful for trying out new versions of the forwarding code
while the mirroring bot is still running in production.

(imported from commit bcdaf91fed55ac0974b1efe31dd13ed006b6fd06)
This commit is contained in:
Tim Abbott 2012-11-08 13:49:03 -05:00
parent ef065d112f
commit 8d27bcbad7

View file

@ -99,6 +99,10 @@ def send_humbug(zeph):
message["recipient"] = zeph["recipient"]
message['content'] = unwrap_lines(zeph['content'])
if options.test_mode:
print message
return {'result': "success"}
return humbug_client.send_message(message)
def fetch_fullname(username):
@ -382,6 +386,11 @@ def forward_to_zephyr(message):
zwrite_args.extend([to_zephyr_username(user["email"]).replace("@ATHENA.MIT.EDU", "")
for user in message["display_recipient"]])
if options.test_mode:
print zwrite_args
print wrapped_content.encode("utf-8")
return
p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
p.communicate(input=wrapped_content.encode("utf-8"))
@ -591,6 +600,11 @@ if __name__ == "__main__":
default="/mit/tabbott/for_friends",
help=optparse.SUPPRESS_HELP,
action='store')
parser.add_option('--test-mode',
dest='test_mode',
default=False,
help=optparse.SUPPRESS_HELP,
action='store_true')
parser.add_option('--api-key-file',
dest='api_key_file',
default=os.path.join(os.environ["HOME"], "Private", ".humbug-api-key"),
@ -641,6 +655,7 @@ or specify the --api-key-file option.""" % (options.api_key_file,)))
bot_name = "extra_mirror.py"
else:
bot_name = "zephyr_mirror.py"
if not options.test_mode:
proc = subprocess.Popen(['pgrep', '-U', os.environ["USER"], "-f", bot_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)