[Piglit] [PATCH 10/20] framework: Use print as a function.

Jon Severinsson jon at severinsson.net
Wed Apr 17 09:14:49 PDT 2013


Supported by Python 2.6+ and required by Python 3.x.
---
 framework/core.py        |    4 +++-
 framework/shader_test.py |    2 ++
 framework/threadpool.py  |   31 +++++++++++++++++--------------
 piglit-merge-results.py  |    4 +++-
 piglit-run.py            |   19 ++++++++++---------
 piglit-summary-html.py   |    4 +++-
 6 filer ändrade, 38 tillägg(+), 26 borttagningar(-)

diff --git a/framework/core.py b/framework/core.py
index 2c7f92d..26a44b0 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -22,6 +22,8 @@
 
 # Piglit core
 
+from __future__ import print_function
+
 from .log import log
 from .threads import ConcurrentTestPool
 from .threads import synchronized_self
@@ -198,7 +200,7 @@ def checkDir(dirname, failifexists):
 			exists = False
 
 	if exists and failifexists:
-		print >>sys.stderr, "%(dirname)s exists already.\nUse --overwrite if you want to overwrite it.\n" % locals()
+		print("%(dirname)s exists already.\nUse --overwrite if you want to overwrite it.\n" % locals(), file=sys.stderr)
 		exit(1)
 
 	try:
diff --git a/framework/shader_test.py b/framework/shader_test.py
index 67930a4..d17280a 100755
--- a/framework/shader_test.py
+++ b/framework/shader_test.py
@@ -23,6 +23,8 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from __future__ import print_function
+
 from .core import testBinDir, Group, Test, TestResult
 from .exectest import PlainExecTest
 
diff --git a/framework/threadpool.py b/framework/threadpool.py
index c46e04b..70d98b3 100644
--- a/framework/threadpool.py
+++ b/framework/threadpool.py
@@ -31,6 +31,9 @@ See the end of the module code for a brief, annotated usage example.
 Website : http://chrisarndt.de/projects/threadpool/
 
 """
+
+from __future__ import print_function
+
 __docformat__ = "restructuredtext en"
 
 __all__ = [
@@ -350,18 +353,18 @@ if __name__ == '__main__':
 
     # this will be called each time a result is available
     def print_result(request, result):
-        print "**** Result from request #%s: %r" % (request.requestID, result)
+        print("**** Result from request #%s: %r" % (request.requestID, result))
 
     # this will be called when an exception occurs within a thread
     # this example exception handler does little more than the default handler
     def handle_exception(request, exc_info):
         if not isinstance(exc_info, tuple):
             # Something is seriously wrong...
-            print request
-            print exc_info
+            print(request)
+            print(exc_info)
             raise SystemExit
-        print "**** Exception occured in request #%s: %s" % \
-          (request.requestID, exc_info)
+        print("**** Exception occured in request #%s: %s" %
+              (request.requestID, exc_info))
 
     # assemble the arguments for each job to a list...
     data = [random.randint(1,10) for i in range(20)]
@@ -381,13 +384,13 @@ if __name__ == '__main__':
     )
 
     # we create a pool of 3 worker threads
-    print "Creating thread pool with 3 worker threads."
+    print("Creating thread pool with 3 worker threads.")
     main = ThreadPool(3)
 
     # then we put the work requests in the queue...
     for req in requests:
         main.putRequest(req)
-        print "Work request #%s added." % req.requestID
+        print("Work request #%s added." % req.requestID)
     # or shorter:
     # [main.putRequest(req) for req in requests]
 
@@ -402,21 +405,21 @@ if __name__ == '__main__':
         try:
             time.sleep(0.5)
             main.poll()
-            print "Main thread working...",
-            print "(active worker threads: %i)" % (threading.activeCount()-1, )
+            print("Main thread working...", end=' ')
+            print("(active worker threads: %i)" % (threading.activeCount()-1, ))
             if i == 10:
-                print "**** Adding 3 more worker threads..."
+                print("**** Adding 3 more worker threads...")
                 main.createWorkers(3)
             if i == 20:
-                print "**** Dismissing 2 worker threads..."
+                print("**** Dismissing 2 worker threads...")
                 main.dismissWorkers(2)
             i += 1
         except KeyboardInterrupt:
-            print "**** Interrupted!"
+            print("**** Interrupted!")
             break
         except NoResultsPending:
-            print "**** No pending results."
+            print("**** No pending results.")
             break
     if main.dismissedWorkers:
-        print "Joining all dismissed worker threads..."
+        print("Joining all dismissed worker threads...")
         main.joinAllDismissedWorkers()
diff --git a/piglit-merge-results.py b/piglit-merge-results.py
index 26d5881..2f389c8 100755
--- a/piglit-merge-results.py
+++ b/piglit-merge-results.py
@@ -22,6 +22,8 @@
 # DEALINGS IN THE SOFTWARE.
 
 
+from __future__ import print_function
+
 from getopt import getopt, GetoptError
 import sys, os.path
 
@@ -43,7 +45,7 @@ Options:
 Example:
   %(progName)s results/main > results/summary
 """
-	print USAGE % {'progName': sys.argv[0]}
+	print(USAGE % {'progName': sys.argv[0]})
 	sys.exit(1)
 
 def main():
diff --git a/piglit-run.py b/piglit-run.py
index 6d6ec77..32c0c16 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -21,6 +21,7 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from __future__ import print_function
 
 import argparse
 import os.path as path
@@ -115,12 +116,12 @@ def main():
 	if args.concurrent is not None:
 		if (args.concurrent == '1' or args.concurrent == 'on'):
 			args.concurrency = True
-			print "Warning: Option -c, --concurrent is deprecated, " \
-					"concurrent test runs are on by default"
+			print("Warning: Option -c, --concurrent is deprecated, "
+					"concurrent test runs are on by default")
 		elif (args.concurrent == '0' or args.concurrent == 'off'):
 			args.concurrency = False
-			print "Warning: Option -c, --concurrent is deprecated, " \
-					"use --no-concurrency for non-concurrent test runs"
+			print("Warning: Option -c, --concurrent is deprecated, "
+					"use --no-concurrency for non-concurrent test runs")
 		# Ne need for else, since argparse restricts the arguments allowed
 
 	# If the deprecated tests option was passed print a warning
@@ -128,8 +129,8 @@ def main():
 		# This merges any options passed into the --tests option into the
 		# ones passed into -t or --tests-include and throws out duplicates
 		args.include_tests = list(set(args.include_tests + args.tests))
-		print "Warning: Option --tests is deprecated, use " \
-				"--include-tests instead"
+		print("Warning: Option --tests is deprecated, use "
+				"--include-tests instead")
 
 	# If resume is requested attempt to load the results file
 	# in the specified path
@@ -218,9 +219,9 @@ def main():
 	json_writer.close_dict()
 	json_writer.file.close()
 
-	print
-	print 'Thank you for running Piglit!'
-	print 'Results have been written to ' + result_filepath
+	print()
+	print('Thank you for running Piglit!')
+	print('Results have been written to ' + result_filepath)
 
 
 if __name__ == "__main__":
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index 087b503..5f9104e 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -21,6 +21,8 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
+from __future__ import print_function
+
 from getopt import getopt, GetoptError
 import cgi
 import os, os.path
@@ -281,7 +283,7 @@ Example list file:
 	[ 'other.result' ]
 ]
 """
-	print USAGE % {'progName': sys.argv[0]}
+	print(USAGE % {'progName': sys.argv[0]})
 	sys.exit(1)
 
 
-- 
1.7.10.4



More information about the Piglit mailing list