[kernel-tests] 67/73: Use print() as a function for Python 3. [PEP 3105]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is an automated email from the git hooks/post-receive script.

jforbes pushed a commit to branch master
in repository kernel-tests.

commit 655fa33fde96e57153e1664ee53753cf17c70300
Author: Craig Rodrigues <rodrigc@xxxxxxxxxxx>
Date:   Sat Nov 14 16:43:44 2015 -0800

    Use print() as a function for Python 3. [PEP 3105]
    
    import __future__.print_function to keep things working on Python 2.
---
 .../libhugetlbfs/huge_page_setup_helper.py         | 122 +++++++++++----------
 .../libhugetlbfs/libhugetlbfs/tests/run_tests.py   |  60 +++++-----
 fedora_submit.py                                   |   9 +-
 3 files changed, 98 insertions(+), 93 deletions(-)

diff --git a/default/libhugetlbfs/libhugetlbfs/huge_page_setup_helper.py b/default/libhugetlbfs/libhugetlbfs/huge_page_setup_helper.py
index 8bfef14..67ea91c 100755
--- a/default/libhugetlbfs/libhugetlbfs/huge_page_setup_helper.py
+++ b/default/libhugetlbfs/libhugetlbfs/huge_page_setup_helper.py
@@ -8,19 +8,21 @@
 #
 # Requires hugeadm from libhugetlbfs 2.7 (or backported support)
 #
+from __future__ import print_function
+
 import os
 
 debug = False
 
 # must be executed under the root to operate
 if os.geteuid() != 0:
-    print "You must be root to setup hugepages!"
+    print("You must be root to setup hugepages!")
     os._exit(1)
 
 # config files we need access to
 sysctlConf = "/etc/sysctl.conf"
 if not os.access(sysctlConf, os.W_OK):
-    print "Cannot access %s" % sysctlConf
+    print("Cannot access %s" % sysctlConf)
     if debug == False:
         os._exit(1)
 
@@ -41,7 +43,7 @@ for line in hugeadmexplain:
         break
 
 if memTotal == 0:
-    print "Your version of libhugetlbfs' hugeadm utility is too old!"
+    print("Your version of libhugetlbfs' hugeadm utility is too old!")
     os._exit(1)
 
 
@@ -54,7 +56,7 @@ for line in poolList:
         break
 
 if hugePageSize == 0:
-    print "Aborting, cannot determine system huge page size!"
+    print("Aborting, cannot determine system huge page size!")
     os._exit(1)
 
 # Get initial sysctl settings
@@ -83,15 +85,15 @@ for line in groupNames:
 
 
 # dump system config as we see it before we start tweaking it
-print "Current configuration:"
-print " * Total System Memory......: %6d MB" % memTotal
-print " * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024))
-print " * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024))
-print " * Number of Huge Pages.....: %6d"    % hugePages
-print " * Total size of Huge Pages.: %6d MB" % (hugePages * hugePageSize / (1024 * 1024))
-print " * Remaining System Memory..: %6d MB" % (memTotal - (hugePages * hugePageSize / (1024 * 1024)))
-print " * Huge Page User Group.....:  %s (%d)" % (hugeGIDName, hugeGID)
-print
+print("Current configuration:")
+print(" * Total System Memory......: %6d MB" % memTotal)
+print(" * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024)))
+print(" * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024)))
+print(" * Number of Huge Pages.....: %6d"    % hugePages)
+print(" * Total size of Huge Pages.: %6d MB" % (hugePages * hugePageSize / (1024 * 1024)))
+print(" * Remaining System Memory..: %6d MB" % (memTotal - (hugePages * hugePageSize / (1024 * 1024))))
+print(" * Huge Page User Group.....:  %s (%d)" % (hugeGIDName, hugeGID))
+print()
 
 
 # ask how memory they want to allocate for huge pages
@@ -113,19 +115,19 @@ while not userIn:
         # As a sanity safeguard, require at least 128M not be allocated to huge pages
         if userHugePageReqMB > (memTotal - 128):
             userIn = None
-            print "Refusing to allocate %d, you must leave at least 128MB for the system" % userHugePageReqMB
+            print("Refusing to allocate %d, you must leave at least 128MB for the system" % userHugePageReqMB)
         elif userHugePageReqMB < (hugePageSize / (1024 * 1024)):
             userIn = None
-            print "Sorry, allocation must be at least a page's worth!"
+            print("Sorry, allocation must be at least a page's worth!")
         else:
             break
     except ValueError:
         userIn = None
-        print "Input must be an integer, please try again!"
+        print("Input must be an integer, please try again!")
 userHugePageReqKB = userHugePageReqMB * 1024
 userHugePagesReq = userHugePageReqKB / (hugePageSize / 1024)
-print "Okay, we'll try to allocate %d MB for huge pages..." % userHugePageReqMB
-print
+print("Okay, we'll try to allocate %d MB for huge pages..." % userHugePageReqMB)
+print()
 
 
 # some basic user input validation
@@ -140,18 +142,18 @@ while inputIsValid == False:
         userGroupReq = 'hugepages'
     if userGroupReq[0].isdigit() or userGroupReq[0] == "-":
         foundbad = True
-        print "Group names cannot start with a number or dash, please try again!"
+        print("Group names cannot start with a number or dash, please try again!")
     for char in badchars:
         if char in userGroupReq:
             foundbad = True
-            print "Illegal characters in group name, please try again!"
+            print("Illegal characters in group name, please try again!")
             break
     if len(userGroupReq) > 16:
         foundbad = True
-        print "Group names can't be more than 16 characaters, please try again!"
+        print("Group names can't be more than 16 characaters, please try again!")
     if foundbad == False:
         inputIsValid = True
-print "Okay, we'll give group %s access to the huge pages" % userGroupReq
+print("Okay, we'll give group %s access to the huge pages" % userGroupReq)
 
 
 # see if group already exists, use it if it does, if not, create it
@@ -163,20 +165,20 @@ for line in groupNames:
         break
 
 if userGIDReq > -1:
-    print "Group %s (gid %d) already exists, we'll use it" % (userGroupReq, userGIDReq)
+    print("Group %s (gid %d) already exists, we'll use it" % (userGroupReq, userGIDReq))
 else:
     if debug == False:
         os.popen("/usr/sbin/groupadd %s" % userGroupReq)
     else:
-        print "/usr/sbin/groupadd %s" % userGroupReq
+        print("/usr/sbin/groupadd %s" % userGroupReq)
     groupNames = os.popen("/usr/bin/getent group %s" % userGroupReq).readlines()
     for line in groupNames:
         curGroupName = line.split(":")[0]
         if curGroupName == userGroupReq:
             userGIDReq = int(line.split(":")[2])
             break
-    print "Created group %s (gid %d) for huge page use" % (userGroupReq, userGIDReq)
-print
+    print("Created group %s (gid %d) for huge page use" % (userGroupReq, userGIDReq))
+print()
 
 
 # basic user input validation, take 2
@@ -190,16 +192,16 @@ while inputIsValid == False:
     for char in badchars:
         if char in userUsersReq:
             foundbad = True
-            print "Illegal characters in user name(s) or invalid list format, please try again!"
+            print("Illegal characters in user name(s) or invalid list format, please try again!")
             break
     for n in userUsersReq.split():
         if len(n) > 32:
             foundbad = True
-            print "User names can't be more than 32 characaters, please try again!"
+            print("User names can't be more than 32 characaters, please try again!")
             break
         if n[0] == "-":
             foundbad = True
-            print "User names cannot start with a dash, please try again!"
+            print("User names cannot start with a dash, please try again!")
             break
     if foundbad == False:
         inputIsValid = True
@@ -211,24 +213,24 @@ for hugeUser in hugePageUserList:
     for line in curUserList:
         curUser = line.split(":")[0]
         if curUser == hugeUser:
-            print "Adding user %s to huge page group" % hugeUser
+            print("Adding user %s to huge page group" % hugeUser)
             userExists = True
             if debug == False:
                 os.popen("/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser))
             else:
-                print "/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser)
+                print("/usr/sbin/usermod -a -G %s %s" % (userGroupReq, hugeUser))
         if userExists == True:
             break
     if userExists == False:
-        print "Creating user %s with membership in huge page group" % hugeUser
+        print("Creating user %s with membership in huge page group" % hugeUser)
         if debug == False:
             if hugeUser == userGroupReq:
                 os.popen("/usr/sbin/useradd %s -g %s" % (hugeUser, userGroupReq))
             else:
                 os.popen("/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq))
         else:
-            print "/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq)
-print
+            print("/usr/sbin/useradd %s -G %s" % (hugeUser, userGroupReq))
+print()
 
 
 # set values for the current running environment
@@ -238,11 +240,11 @@ if debug == False:
     os.popen("/usr/bin/hugeadm --set-shm-group %d" % userGIDReq)
     os.popen("/usr/bin/hugeadm --set-recommended-shmmax")
 else:
-    print "/usr/bin/hugeadm --pool-pages-min DEFAULT:%sM" % userHugePageReqMB
-    print "/usr/bin/hugeadm --pool-pages-max DEFAULT:%sM" % userHugePageReqMB
-    print "/usr/bin/hugeadm --set-shm-group %d" % userGIDReq
-    print "/usr/bin/hugeadm --set-recommended-shmmax"
-    print
+    print("/usr/bin/hugeadm --pool-pages-min DEFAULT:%sM" % userHugePageReqMB)
+    print("/usr/bin/hugeadm --pool-pages-max DEFAULT:%sM" % userHugePageReqMB)
+    print("/usr/bin/hugeadm --set-shm-group %d" % userGIDReq)
+    print("/usr/bin/hugeadm --set-recommended-shmmax")
+    print()
 
 # figure out what that shmmax value we just set was
 hugeadmexplain = os.popen("/usr/bin/hugeadm --explain 2>/dev/null").readlines()
@@ -258,7 +260,7 @@ if debug == False:
         try:
             sysctlConfLines = open(sysctlConf).readlines()
             os.rename(sysctlConf, sysctlConf + ".backup")
-            print("Saved original %s as %s.backup" % (sysctlConf, sysctlConf))
+            print(("Saved original %s as %s.backup" % (sysctlConf, sysctlConf)))
         except:
             pass
 
@@ -279,11 +281,11 @@ if debug == False:
     fd.close()
 
 else:
-    print "Add to %s:" % sysctlConf
-    print "kernel.shmmax = %d" % shmmax
-    print "vm.nr_hugepages = %d" % userHugePagesReq
-    print "vm.hugetlb_shm_group = %d" % userGIDReq
-    print
+    print("Add to %s:" % sysctlConf)
+    print("kernel.shmmax = %d" % shmmax)
+    print("vm.nr_hugepages = %d" % userHugePagesReq)
+    print("vm.hugetlb_shm_group = %d" % userGIDReq)
+    print()
 
 
 # write out limits.conf changes to persist across reboot
@@ -293,7 +295,7 @@ if debug == False:
         try:
             limitsConfLines = open(limitsConf).readlines()
             os.rename(limitsConf, limitsConf + ".backup")
-            print("Saved original %s as %s.backup" % (limitsConf, limitsConf))
+            print(("Saved original %s as %s.backup" % (limitsConf, limitsConf)))
         except:
             pass
 
@@ -319,25 +321,25 @@ if debug == False:
     fd.close()
 
 else:
-    print "Add to %s:" % limitsConf
+    print("Add to %s:" % limitsConf)
     for hugeUser in hugePageUserList:
-        print "%s		soft	memlock		%d" % (hugeUser, userHugePageReqKB)
-        print "%s		hard	memlock		%d" % (hugeUser, userHugePageReqKB)
+        print("%s		soft	memlock		%d" % (hugeUser, userHugePageReqKB))
+        print("%s		hard	memlock		%d" % (hugeUser, userHugePageReqKB))
 
 
 # dump the final configuration of things now that we're done tweaking
-print
-print "Final configuration:"
-print " * Total System Memory......: %6d MB" % memTotal
+print()
+print("Final configuration:")
+print(" * Total System Memory......: %6d MB" % memTotal)
 if debug == False:
-    print " * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024))
+    print(" * Shared Mem Max Mapping...: %6d MB" % (shmmax / (1024 * 1024)))
 else:
     # This should be what we *would* have set it to, had we actually run hugeadm --set-recommended-shmmax
-    print " * Shared Mem Max Mapping...: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024))
-print " * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024))
-print " * Available Huge Pages.....: %6d"    % userHugePagesReq
-print " * Total size of Huge Pages.: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024))
-print " * Remaining System Memory..: %6d MB" % (memTotal - userHugePageReqMB)
-print " * Huge Page User Group.....:  %s (%d)" % (userGroupReq, userGIDReq)
-print
+    print(" * Shared Mem Max Mapping...: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024)))
+print(" * System Huge Page Size....: %6d MB" % (hugePageSize / (1024 * 1024)))
+print(" * Available Huge Pages.....: %6d"    % userHugePagesReq)
+print(" * Total size of Huge Pages.: %6d MB" % (userHugePagesReq * hugePageSize / (1024 * 1024)))
+print(" * Remaining System Memory..: %6d MB" % (memTotal - userHugePageReqMB))
+print(" * Huge Page User Group.....:  %s (%d)" % (userGroupReq, userGIDReq))
+print()
 
diff --git a/default/libhugetlbfs/libhugetlbfs/tests/run_tests.py b/default/libhugetlbfs/libhugetlbfs/tests/run_tests.py
index 8055940..dc676b6 100755
--- a/default/libhugetlbfs/libhugetlbfs/tests/run_tests.py
+++ b/default/libhugetlbfs/libhugetlbfs/tests/run_tests.py
@@ -1,5 +1,7 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
+
 import subprocess
 import types
 import os
@@ -59,7 +61,7 @@ def snapshot_pool_state():
 def run_test_prog(bits, pagesize, cmd, **env):
     if paranoid_pool_check:
         beforepool = snapshot_pool_state()
-        print "Pool state: %s" % str(beforepool)
+        print("Pool state: %s" % str(beforepool))
 
     local_env = os.environ.copy()
     local_env.update(env)
@@ -82,9 +84,9 @@ def run_test_prog(bits, pagesize, cmd, **env):
     if paranoid_pool_check:
         afterpool = snapshot_pool_state()
         if afterpool != beforepool:
-            print >>sys.stderr, "Hugepage pool state not preserved!"
-            print >>sys.stderr, "BEFORE: %s" % str(beforepool)
-            print >>sys.stderr, "AFTER: %s" % str(afterpool)
+            print("Hugepage pool state not preserved!", file=sys.stderr)
+            print("BEFORE: %s" % str(beforepool), file=sys.stderr)
+            print("AFTER: %s" % str(afterpool), file=sys.stderr)
             sys.exit(98)
 
     return (rc, out)
@@ -142,22 +144,22 @@ def print_per_size(title, values):
     Print the results of a given result type on one line.  The results for all
     page sizes and word sizes are written in a table format.
     """
-    print "*%20s: " % title,
+    print("*%20s: " % title, end=' ')
     for sz in pagesizes:
-        print "%4s   %4s   " % (values[sz][32], values[sz][64]),
-    print
+        print("%4s   %4s   " % (values[sz][32], values[sz][64]), end=' ')
+    print()
 
 def results_summary():
     """
     Display a summary of the test results
     """
-    print "********** TEST SUMMARY"
-    print "*%21s" % "",
-    for p in pagesizes: print "%-13s " % pretty_page_size(p),
-    print
-    print "*%21s" % "",
-    for p in pagesizes: print "32-bit 64-bit ",
-    print
+    print("********** TEST SUMMARY")
+    print("*%21s" % "", end=' ')
+    for p in pagesizes: print("%-13s " % pretty_page_size(p), end=' ')
+    print()
+    print("*%21s" % "", end=' ')
+    for p in pagesizes: print("32-bit 64-bit ", end=' ')
+    print()
 
     print_per_size("Total testcases", R["total"])
     print_per_size("Skipped", R["skip"])
@@ -168,7 +170,7 @@ def results_summary():
     print_per_size("Expected FAIL", R["xfail"])
     print_per_size("Unexpected PASS", R["xpass"])
     print_per_size("Strange test result", R["strange"])
-    print "**********"
+    print("**********")
 
 def free_hpages():
     """
@@ -268,13 +270,13 @@ def check_hugetlbfs_path():
                 okbits.append(b)
                 mounts.append(out)
         if len(okbits) == 0:
-            print "run_tests.py: No mountpoints available for page size %s" % \
-                  pretty_page_size(p)
+            print("run_tests.py: No mountpoints available for page size %s" % \
+                  pretty_page_size(p))
             wordsizes_by_pagesize[p] = set()
             continue
         for b in wordsizes - set(okbits):
-            print "run_tests.py: The %i bit word size is not compatible with " \
-                  "%s pages" % (b, pretty_page_size(p))
+            print("run_tests.py: The %i bit word size is not compatible with " \
+                  "%s pages" % (b, pretty_page_size(p)))
         wordsizes_by_pagesize[p] = set(okbits)
 
 def check_linkhuge_tests():
@@ -296,10 +298,10 @@ def check_linkhuge_tests():
 
 def print_cmd(pagesize, bits, cmd, env):
     if env:
-        print ' '.join(['%s=%s' % (k, v) for k, v in env.items()]),
+        print(' '.join(['%s=%s' % (k, v) for k, v in env.items()]), end=' ')
     if type(cmd) != types.StringType:
         cmd = ' '.join(cmd)
-    print "%s (%s: %i):\t" % (cmd, pretty_page_size(pagesize), bits),
+    print("%s (%s: %i):\t" % (cmd, pretty_page_size(pagesize), bits), end=' ')
     sys.stdout.flush()
 
 def run_test(pagesize, bits, cmd, **env):
@@ -319,7 +321,7 @@ def run_test(pagesize, bits, cmd, **env):
 
     print_cmd(pagesize, bits, cmd, env)
     (rc, out) = run_test_prog(bits, pagesize, cmd, **env)
-    print out
+    print(out)
 
     R["total"][pagesize][bits] += 1
     if rc == 0:    R["pass"][pagesize][bits] += 1
@@ -338,7 +340,7 @@ def skip_test(pagesize, bits, cmd, **env):
     R["total"][pagesize][bits] += 1
     R["skip"][pagesize][bits] += 1
     print_cmd(pagesize, bits, cmd, env)
-    print "SKIPPED"
+    print("SKIPPED")
 
 def do_test(cmd, bits=None, **env):
     """
@@ -459,7 +461,7 @@ def setup_shm_sysctl(limit):
         fh = open(f, "w")
         fh.write(`limit`)
         fh.close()
-    print "set shmmax limit to %s" % limit
+    print("set shmmax limit to %s" % limit)
     return sysctls
 
 def restore_shm_sysctl(sysctls):
@@ -655,7 +657,7 @@ def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "vVfdt:b:p:c")
     except getopt.GetoptError, err:
-        print str(err)
+        print(str(err))
         sys.exit(1)
     for opt, arg in opts:
        if opt == "-v":
@@ -680,8 +682,8 @@ def main():
     if len(pagesizes) == 0: pagesizes = get_pagesizes()
 
     if len(pagesizes) == 0:
-        print "Unable to find available page sizes, are you sure hugetlbfs"
-        print "is mounted and there are available huge pages?"
+        print("Unable to find available page sizes, are you sure hugetlbfs")
+        print("is mounted and there are available huge pages?")
         return 1
 
     setup_env(env_override, env_defaults)
@@ -689,8 +691,8 @@ def main():
 
     (rc, system_default_hpage_size) = hpage_size()
     if rc != 0:
-        print "Unable to find system default hugepage size."
-        print "Is hugepage supported included in this kernel?"
+        print("Unable to find system default hugepage size.")
+        print("Is hugepage supported included in this kernel?")
         return 1
 
     check_hugetlbfs_path()
diff --git a/fedora_submit.py b/fedora_submit.py
index 76c040d..e20cfb6 100755
--- a/fedora_submit.py
+++ b/fedora_submit.py
@@ -2,6 +2,7 @@
 #
 # Licensed under the terms of the GNU GPL License version 2
 
+from __future__ import print_function
 from fedora.client import OpenIdBaseClient
 import getpass
 import sys, getopt
@@ -14,11 +15,11 @@ argv = sys.argv[1:]
 try:
     opts, args = getopt.getopt(argv,"hu:p:l:",["user=","password=", "logfile="])
 except getopt.GetoptError:
-    print 'fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>'
+    print('fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>')
     sys.exit(2)
 for opt, arg in opts:
     if opt == '-h':
-        print 'fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>'
+        print('fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>')
         sys.exit()
     elif opt in ("-u", "--user"):
         username = arg
@@ -28,7 +29,7 @@ for opt, arg in opts:
         log = arg
 
 if username == '' or log == '':
-    print 'fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>'
+    print('fedora_submit.py -u <fasuser> [-p <password>] -l <logfile>')
     sys.exit(2)
 if password == '':
     password = getpass.getpass('FAS password: ')
@@ -51,4 +52,4 @@ req = submitclient.send_request(
     files= { 'test_result': ('logfile', open(log, 'rb'), 'text/x-log'),}
 )
  
-print req.message
+print(req.message)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
kernel mailing list -- kernel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to kernel-leave@xxxxxxxxxxxxxxxxxxxxxxx




[Index of Archives]     [Fedora General Discussion]     [Older Fedora Users Archive]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Announce]     [Fedora Package Review]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Coolkey]     [Yum Users]     [Tux]     [Yosemite News]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [USB]     [Asterisk PBX]

  Powered by Linux