]> granicus.if.org Git - zfs/commitdiff
Python 3 fixes
authorMatthew Thode <mthode@mthode.org>
Fri, 8 Nov 2013 21:53:54 +0000 (15:53 -0600)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 8 Nov 2013 22:30:29 +0000 (14:30 -0800)
Future proofing for compatibility with newer versions of Python.

Signed-off-by: Matthew Thode <prometheanfire@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #1838

cmd/arcstat/arcstat.py
cmd/dbufstat/dbufstat.py

index 24f4aa77e174d092d33b6beb3cf72ddd39e115ca..2b5ac76f5bea91a20105005d2519d04b384f122e 100755 (executable)
@@ -191,7 +191,7 @@ def prettynum(sz, scale, num=0):
         return "%s" % num
 
     # Rounding error, return 0
-    elif num > 0 and num < 1:
+    elif 0 < num < 1:
         num = 0
 
     while num > scale and index < 5:
@@ -259,10 +259,10 @@ def init():
                 "columns"
             ]
         )
-
-    except getopt.error, msg:
+    except getopt.error as msg:
         sys.stderr.write(msg)
         usage()
+        opts = None
 
     for opt, arg in opts:
         if opt in ('-x', '--extended'):
@@ -335,7 +335,7 @@ def init():
             out = open(opfile, "w")
             sys.stdout = out
 
-        except:
+        except IOError:
             sys.stderr.write("Cannot open %s for writing\n" % opfile)
             sys.exit(1)
 
@@ -345,7 +345,7 @@ def calculate():
     global v
     global l2exist
 
-    v = {}
+    v = dict()
     v["time"] = time.strftime("%H:%M:%S", time.localtime())
     v["hits"] = d["hits"] / sint
     v["miss"] = d["misses"] / sint
@@ -398,7 +398,7 @@ def calculate():
         v["l2bytes"] = d["l2_read_bytes"] / sint
 
 
-def sighandler(*args):
+def sighandler():
     sys.exit(0)
 
 
index ebe034eedc03a113f9ec7aaf0ba1782c25a4a064..5f75376e47204c51b5886ce6f7dfbccd6c9ce7b7 100755 (executable)
@@ -184,7 +184,7 @@ def prettynum(sz, scale, num=0):
         return "%*s" % (sz, num)
 
     # Rounding error, return 0
-    elif num > 0 and num < 1:
+    elif 0 < num < 1:
         num = 0
 
     while num > scale and index < 5:
@@ -384,19 +384,21 @@ def update_dict(d, k, line, labels):
 
     return d
 
+
 def print_dict(d):
     print_header()
-    for pool in d.iterkeys():
-        for objset in d[pool].iterkeys():
-            for v in d[pool][objset].itervalues():
+    for pool in d.keys():
+        for objset in d[pool].keys():
+            for v in d[pool][objset].values():
                 print_values(v)
 
+
 def dnodes_build_dict(filehandle):
     labels = dict()
     dnodes = dict()
 
     # First 3 lines are header information, skip the first two
-    for i in range(0, 2):
+    for i in range(2):
         next(filehandle)
 
     # The third line contains the labels and index locations
@@ -409,12 +411,13 @@ def dnodes_build_dict(filehandle):
 
     return dnodes
 
+
 def types_build_dict(filehandle):
     labels = dict()
     types = dict()
 
     # First 3 lines are header information, skip the first two
-    for i in range(0, 2):
+    for i in range(2):
         next(filehandle)
 
     # The third line contains the labels and index locations
@@ -427,11 +430,12 @@ def types_build_dict(filehandle):
 
     return types
 
+
 def buffers_print_all(filehandle):
     labels = dict()
 
     # First 3 lines are header information, skip the first two
-    for i in range(0, 2):
+    for i in range(2):
         next(filehandle)
 
     # The third line contains the labels and index locations
@@ -479,6 +483,7 @@ def main():
         )
     except getopt.error:
         usage()
+        opts = None
 
     for opt, arg in opts:
         if opt in ('-b', '--buffers'):
@@ -560,7 +565,7 @@ def main():
         try:
             tmp = open(ifile, "r")
             sys.stdin = tmp
-        except:
+        except IOError:
             sys.stderr.write("Cannot open %s for reading\n" % ifile)
             sys.exit(1)