From e9d87828c25f39d3f7a1b25e1bbb00a970491260 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 27 Sep 2015 13:54:20 -0700 Subject: [PATCH] scripts/runner: make py3-compatible --- src/wormhole/scripts/runner.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/wormhole/scripts/runner.py b/src/wormhole/scripts/runner.py index 0469320..044fd8b 100644 --- a/src/wormhole/scripts/runner.py +++ b/src/wormhole/scripts/runner.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys, argparse from textwrap import dedent from .. import public_relay @@ -120,14 +121,19 @@ def run(args, stdout, stderr, executable=None): also invoked by entry() below.""" args = parser.parse_args() + if not getattr(args, "func", None): + # So far this only works on py3. py2 exits with a really terse + # "error: too few arguments" during parse_args(). + parser.print_help() + sys.exit(0) try: #rc = command.func(args, stdout, stderr) rc = args.func(args) return rc except ImportError as e: - print >>stderr, "--- ImportError ---" - print >>stderr, e - print >>stderr, "Please run 'python setup.py build'" + print("--- ImportError ---", file=stderr) + print(e, file=stderr) + print("Please run 'python setup.py build'", file=stderr) raise return 1 @@ -138,4 +144,4 @@ def entry(): if __name__ == "__main__": args = parser.parse_args() - print args + print(args)