[28886] in Source-Commits

home help back first fref pref prev next nref lref last post

athrun commit: Update print statements and encoding for python 3

daemon@ATHENA.MIT.EDU (Benjamin Kaduk)
Sat Aug 22 22:45:18 2020

Date: Sat, 22 Aug 2020 22:45:14 -0400
From: Benjamin Kaduk <kaduk@mit.edu>
Message-ID: <202008230245.07N2jEEA022596@drugstore.mit.edu>
To: <source-commits@mit.edu>
MIME-Version: 1.0
Content-Type: text/plain

https://github.com/mit-athena/athrun/commit/3c9c5b72414454df3c4faad6d92929c5b6e0dc2b
commit 3c9c5b72414454df3c4faad6d92929c5b6e0dc2b
Author: Miriam Rittenberg <mrittenb@mit.edu>
Date:   Mon Aug 10 13:52:04 2020 -0400

    Update print statements and encoding for python 3

 attachandrun |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/attachandrun b/attachandrun
index 8660eb3..e831f64 100755
--- a/attachandrun
+++ b/attachandrun
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+from __future__ import print_function
 import errno
 import os
 import subprocess
@@ -13,19 +14,19 @@ def extract(args):
     return (args[0], args[1:])
 
 def usage():
-    print >>sys.stderr, 'Usage: %s [--check|-c] locker program program_name [args...]' % (progname,)
+    print('Usage: %s [--check|-c] locker program program_name [args...]' % (progname,), file=sys.stderr)
     sys.exit(1)
 
 def invoke(args):
     try:
         process = subprocess.Popen(args,
-                                   stdout=subprocess.PIPE)
+                                   stdout=subprocess.PIPE, universal_newlines=True)
         result, _ = process.communicate()
         if process.returncode != 0:
             raise Exception("Non-zero return code from '%s'" % (args[0],))
         return result.strip()
     except subprocess.CalledProcessError as e:
-        print >>sys.stderr, "Unable to invoke '%s'." % (args[0],)
+        print("Unable to invoke '%s'." % (args[0],), file=sys.stderr)
         sys.exit(1)
 
 def attach(locker):
@@ -77,11 +78,11 @@ def main():
 
     # Actually execute the program, 
     error = execute(program_location, argv)
-    print >>sys.stderr, "%s: %s: %s" % (progname, program_location, os.strerror(error))
+    print("%s: %s: %s" % (progname, program_location, os.strerror(error)), file=sys.stderr)
     
 if __name__ == '__main__':
     try:
         main()
     except Exception as e:
-        print >>sys.stderr, "%s: %s" % (progname, e)
+        print("%s: %s" % (progname, e), file=sys.stderr)
         usage()

home help back first fref pref prev next nref lref last post