oft: Convert to print_function

Replace the Python 'print' keyword ('print x') with the function
version ('print(x)'). This is the recommended approach for new Python
code.

In addition, replace a number of 'print' calls with either logging or
calls to 'die' to be consistent.

Signed-off-by: Stephen Finucane <stephenfinucane@hotmail.com>
diff --git a/oft b/oft
index 5016a63..ec80451 100755
--- a/oft
+++ b/oft
@@ -12,6 +12,8 @@
 oftest.config dictionary.
 """
 
+from __future__ import print_function
+
 import sys
 import optparse
 import logging
@@ -391,20 +393,9 @@
     return result
 
 def die(msg, exit_val=1):
-    print msg
     logging.critical(msg)
     sys.exit(exit_val)
 
-def _space_to(n, str):
-    """
-    Generate a string of spaces to achieve width n given string str
-    If length of str >= n, return one space
-    """
-    spaces = n - len(str)
-    if spaces > 0:
-        return " " * spaces
-    return " "
-
 #
 # Main script
 #
@@ -429,7 +420,7 @@
 
 test_specs = args
 if config["test_spec"] != "":
-    print >> sys.stderr, "WARNING: The --test-spec option is deprecated"
+    logging.warning("The '--test-spec' option is deprecated.")
     test_specs += config["test_spec"].split(',')
 if config["test_file"] != None:
     with open(config["test_file"], 'r') as f:
@@ -448,52 +439,48 @@
     mod_count = 0
     test_count = 0
     all_groups = set()
-    print """\
-Tests are shown grouped by module. If a test is in any groups beyond "standard"
-and its module's group then they are shown in parentheses."""
-    print
-    print """\
+
+    print("""
+Tests are shown grouped by module. If a test is in any groups beyond
+"standard" and its module's group then they are shown in parentheses.
+
 Tests marked with '*' are non-standard and may require vendor extensions or
-special switch configuration. These are not part of the "standard" test group."""
-    print
-    print """\
-Tests marked with '!' are disabled because they are experimental, special-purpose,
-or are too long to be run normally. These are not part of the "standard" test
-group or their module's test group."""
-    print
-    print "Tests marked (TP1) after name take --test-params including:"
-    print "    'vid=N;strip_vlan=bool;add_vlan=bool'"
-    print
-    print "Test List:"
+special switch configuration. These are not part of the "standard" test group.
+
+Tests marked with '!' are disabled because they are experimental,
+special-purpose, or are too long to be run normally. These are not part of
+the "standard" test group or their module's test group.
+
+Tests marked (TP1) after name take --test-params including:
+
+    'vid=N;strip_vlan=bool;add_vlan=bool'
+
+Test List:
+""")
     for (modname, (mod, tests)) in test_modules.items():
         mod_count += 1
         desc = (mod.__doc__ or "No description").strip().split('\n')[0]
-        start_str = "  Module " + mod.__name__ + ": "
-        print start_str + _space_to(22, start_str) + desc
+        print("  Module %13s: %s" % (mod.__name__, desc))
+
         for (testname, test) in tests.items():
-            try:
-                desc = (test.__doc__ or "").strip()
-                desc = desc.split('\n')[0]
-            except:
-                desc = "No description"
+            desc = (test.__doc__ or "No description").strip().split('\n')[0]
+
             groups = set(test._groups) - set(["all", "standard", modname])
             all_groups.update(test._groups)
             if groups:
                 desc = "(%s) %s" % (",".join(groups), desc)
             if hasattr(test, "_versions"):
                 desc = "(%s) %s" % (",".join(sorted(test._versions)), desc)
+
             start_str = " %s%s %s:" % (test._nonstandard and "*" or " ",
                                        test._disabled and "!" or " ",
                                        testname)
-            if len(start_str) > 22:
-                desc = "\n" + _space_to(22, "") + desc
-            print start_str + _space_to(22, start_str) + desc
+            print("  %22s : %s" % (start_str, desc))
             test_count += 1
         print
-    print "%d modules shown with a total of %d tests" % \
-        (mod_count, test_count)
-    print
-    print "Test groups: %s" % (', '.join(sorted(all_groups)))
+    print("'%d' modules shown with a total of '%d' tests\n" %
+          (mod_count, test_count))
+    print("Test groups: %s" % (', '.join(sorted(all_groups))))
 
     sys.exit(0)
 
@@ -503,7 +490,8 @@
 if config["list_test_names"]:
     for (modname, (mod, tests)) in test_modules.items():
         for (testname, test) in tests.items():
-            print "%s.%s" % (modname, testname)
+            print("%s.%s" % (modname, testname))
+
     sys.exit(0)
 
 # Generate the test suite
@@ -544,8 +532,7 @@
 oftest.testutils.MINSIZE = config['minsize']
 
 if os.getuid() != 0 and not config["allow_user"]:
-    print "ERROR: Super-user privileges required. Please re-run with " \
-          "sudo or as root."
+    die("Super-user privileges required. Please re-run with sudo or as root.")
     sys.exit(1)
 
 if config["random_seed"] is not None:
@@ -586,12 +573,9 @@
         result = unittest.TextTestRunner(verbosity=2).run(suite)
     oftest.open_logfile('main')
     if oftest.testutils.skipped_test_count > 0:
-        ts = " tests"
-        if oftest.testutils.skipped_test_count == 1:
-            ts = " test"
-        logging.info("Skipped " + str(oftest.testutils.skipped_test_count) + ts)
-        print("Skipped " + str(oftest.testutils.skipped_test_count) + ts)
-    logging.info("*** TEST RUN END  : " + time.asctime())
+        message = "Skipped %d test(s)" % oftest.testutils.skipped_test_count
+        logging.info(message)
+    logging.info("*** TEST RUN END  : %s", time.asctime())
 
     # Shutdown the dataplane
     oftest.dataplane_instance.kill()