]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/ceph_argparse: PEP8 related cleanups
authorKefu Chai <kchai@redhat.com>
Thu, 24 Dec 2020 14:12:35 +0000 (22:12 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 1 Jan 2021 12:37:45 +0000 (20:37 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/ceph_argparse.py

index 7bb42aa26d5329137e8549c9867f965c2a9caec2..65420c9a40e96851d7bc560906881c22ee0ab19a 100644 (file)
@@ -11,7 +11,6 @@ LGPL-2.1 or LGPL-3.0.  See file COPYING.
 """
 from __future__ import print_function
 import copy
-import errno
 import math
 import json
 import os
@@ -31,10 +30,11 @@ class Flag:
     NOFORWARD = (1 << 0)
     OBSOLETE = (1 << 1)
     DEPRECATED = (1 << 2)
-    MGR = (1<<3)
+    MGR = (1 << 3)
     POLL = (1 << 4)
     HIDDEN = (1 << 5)
 
+
 KWARG_EQUALS = "--([^=]+)=(.+)"
 KWARG_SPACE = "--([^=]+)"
 
@@ -171,10 +171,10 @@ class CephInt(CephArgtype):
             raise ArgumentValid("{0} doesn't represent an int".format(s))
         if len(self.range) == 2:
             if val < self.range[0] or val > self.range[1]:
-                raise ArgumentValid("{0} not in range {1}".format(val, self.range))
+                raise ArgumentValid(f"{val} not in range {self.range}")
         elif len(self.range) == 1:
             if val < self.range[0]:
-                raise ArgumentValid("{0} not in range {1}".format(val, self.range))
+                raise ArgumentValid(f"{val} not in range {self.range}")
         self.val = val
 
     def __str__(self):
@@ -206,10 +206,10 @@ class CephFloat(CephArgtype):
             raise ArgumentValid("{0} doesn't represent a float".format(s))
         if len(self.range) == 2:
             if val < self.range[0] or val > self.range[1]:
-                raise ArgumentValid("{0} not in range {1}".format(val, self.range))
+                raise ArgumentValid(f"{val} not in range {self.range}")
         elif len(self.range) == 1:
             if val < self.range[0]:
-                raise ArgumentValid("{0} not in range {1}".format(val, self.range))
+                raise ArgumentValid(f"{val} not in range {self.range}")
         self.val = val
 
     def __str__(self):
@@ -229,7 +229,7 @@ class CephString(CephArgtype):
         from string import printable
         try:
             re.compile(goodchars)
-        except:
+        except re.error:
             raise ValueError('CephString(): "{0}" is not a valid RE'.
                              format(goodchars))
         self.goodchars = goodchars
@@ -294,7 +294,7 @@ class CephIPAddr(CephArgtype):
                 p = None
             try:
                 socket.inet_pton(socket.AF_INET, a)
-            except:
+            except OSError:
                 raise ArgumentValid('{0}: invalid IPv4 address'.format(a))
         else:
             # v6
@@ -305,7 +305,7 @@ class CephIPAddr(CephArgtype):
                 if s[end + 1] == ':':
                     try:
                         p = int(s[end + 2])
-                    except:
+                    except ValueError:
                         raise ArgumentValid('{0}: bad port number'.format(s))
                 a = s[1:end]
             else:
@@ -313,7 +313,7 @@ class CephIPAddr(CephArgtype):
                 p = None
             try:
                 socket.inet_pton(socket.AF_INET6, a)
-            except:
+            except OSError:
                 raise ArgumentValid('{0} not valid IPv6 address'.format(s))
         if p is not None and int(p) > 65535:
             raise ArgumentValid("{0} not a valid port number".format(p))
@@ -428,7 +428,7 @@ class CephName(CephArgtype):
                 if i != '*':
                     try:
                         i = int(i)
-                    except:
+                    except ValueError:
                         raise ArgumentFormat('osd id ' + i + ' not integer')
             self.nametype = t
         self.val = s
@@ -461,7 +461,7 @@ class CephOsdName(CephArgtype):
             i = s
         try:
             i = int(i)
-        except:
+        except ValueError:
             raise ArgumentFormat('osd id ' + i + ' not integer')
         if i < 0:
             raise ArgumentFormat('osd id {0} is less than 0'.format(i))
@@ -1119,7 +1119,7 @@ def validate(args: List[str],
         raise ArgumentError("unused arguments: " + str(myargs))
 
     if flags & Flag.MGR:
-        d['target'] = ('mon-mgr','')
+        d['target'] = ('mon-mgr', '')
 
     if flags & Flag.POLL:
         d['poll'] = True
@@ -1231,8 +1231,9 @@ def validate_command(sigdict: Dict[str, Dict[str, Any]],
     else:
         bestcmds = [c for c in bestcmds
                     if not c.get('flags', 0) & (Flag.DEPRECATED | Flag.HIDDEN)]
-        bestcmds = bestcmds[:10] # top 10
-        print('no valid command found; {0} closest matches:'.format(len(bestcmds)), file=sys.stderr)
+        bestcmds = bestcmds[:10]  # top 10
+        print('no valid command found; {0} closest matches:'.format(len(bestcmds)),
+              file=sys.stderr)
         for cmd in bestcmds:
             print(concise_sig(cmd['sig']), file=sys.stderr)
     return valid_dict
@@ -1324,7 +1325,7 @@ class RadosThread(threading.Thread):
 def run_in_thread(func: Callable[[Any, Any], int],
                   *args: Any, **kwargs: Any) -> int:
     timeout = kwargs.pop('timeout', 0)
-    if timeout == 0 or timeout == None:
+    if timeout == 0 or timeout is None:
         # python threading module will just get blocked if timeout is `None`,
         # otherwise it will keep polling until timeout or thread stops.
         # timeout in integer when converting it to nanoseconds, but since