[elbe-devel] [PATCH 51/75] egpg: Fix Pylint

Olivier Dion dion at linutronix.de
Mon May 25 17:42:44 CEST 2020


32:0:   R0902: (too-many-instance-attributes)
32:0:   R0205: (useless-object-inheritance)
82:25:  W0621: (redefined-outer-name)
85:21:  E1101: (no-member)
93:21:  E1101: (no-member)
93:37:  E1101: (no-member)
105:21: E1101: (no-member)
105:43: E1101: (no-member)
109:21: E1101: (no-member)
109:43: E1101: (no-member)
113:21: E1101: (no-member)
113:43: E1101: (no-member)
117:21: E1101: (no-member)
117:35: E1101: (no-member)
120:21: E1101: (no-member)
120:43: E1101: (no-member)
123:21: E1101: (no-member)
123:43: E1101: (no-member)
126:21: E1101: (no-member)
126:42: E1101: (no-member)
129:21: E1101: (no-member)
129:41: E1101: (no-member)
160:20: W0621: (redefined-outer-name)
171:11: W0703: (broad-except)
197:11: W0703: (broad-except)
212:11: W0703: (broad-except)
207:37: E1101: (no-member)
221:11: W0703: (broad-except)

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/egpg.py | 65 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/elbepack/egpg.py b/elbepack/egpg.py
index 7cfc881f..2c94fc7b 100644
--- a/elbepack/egpg.py
+++ b/elbepack/egpg.py
@@ -28,7 +28,9 @@ elbe_internal_key_param = """
 </GnupgKeyParms>
 """
 
-
+# TODO:py3 Remove object inheritance
+# pylint: disable=useless-object-inheritance
+# pylint: disable=too-many-instance-attributes
 class OverallStatus(object):
 
     def __init__(self):
@@ -79,54 +81,63 @@ class OverallStatus(object):
         return 0
 
 
-def check_signature(ctx, sig):
+def check_signature(ctx, signature):
     status = OverallStatus()
-
-    if sig.summary & sigsum.KEY_MISSING:
-        print("Signature with unknown key: %s" % sig.fpr)
+    # pylint: disable=no-member
+    if signature.summary & sigsum.KEY_MISSING:
+        print("Signature with unknown key: %s" % signature.fpr)
         status.key_missing = 1
         return status
 
     # there should be a key
-    key = ctx.get_key(sig.fpr, 0)
-    print("%s <%s> (%s):" % (key.uids[0].name, key.uids[0].email, sig.fpr))
-    if sig.summary & sigsum.VALID == sigsum.VALID:
+    key = ctx.get_key(signature.fpr, 0)
+    print("%s <%s> (%s):" % (key.uids[0].name, key.uids[0].email, signature.fpr))
+    # pylint: disable=no-member
+    if signature.summary & sigsum.VALID == sigsum.VALID:
         # signature fully valid and trusted
         print("VALID (Trusted)")
         status.valid = 1
         return status
 
     # print detailed status in case it's not fully valid and trusted
-    if sig.summary == 0:
+    if signature.summary == 0:
         # Signature is valid, but the key is not ultimately trusted,
         # see: http://www.gossamer-threads.com/lists/gnupg/users/52350
         print("VALID (Untrusted).")
         status.valid = 1
-    if sig.summary & sigsum.SIG_EXPIRED == sigsum.SIG_EXPIRED:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.SIG_EXPIRED == sigsum.SIG_EXPIRED:
         print("SIGNATURE EXPIRED!")
         status.sig_expired = 1
         status.valid_threshold = 1
-    if sig.summary & sigsum.KEY_EXPIRED == sigsum.KEY_EXPIRED:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.KEY_EXPIRED == sigsum.KEY_EXPIRED:
         print("KEY EXPIRED!")
         status.key_expired = 1
         status.valid_threshold = 1
-    if sig.summary & sigsum.KEY_REVOKED == sigsum.KEY_REVOKED:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.KEY_REVOKED == sigsum.KEY_REVOKED:
         print("KEY REVOKED!")
         status.key_revoked = 1
         status.valid_threshold = 1
-    if sig.summary & sigsum.RED == sigsum.RED:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.RED == sigsum.RED:
         print("INVALID SIGNATURE!")
         status.invalid = 1
-    if sig.summary & sigsum.CRL_MISSING == sigsum.CRL_MISSING:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.CRL_MISSING == sigsum.CRL_MISSING:
         print("CRL MISSING!")
         status.gpg_error = 1
-    if sig.summary & sigsum.CRL_TOO_OLD == sigsum.CRL_TOO_OLD:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.CRL_TOO_OLD == sigsum.CRL_TOO_OLD:
         print("CRL TOO OLD!")
         status.gpg_error = 1
-    if sig.summary & sigsum.BAD_POLICY == sigsum.BAD_POLICY:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.BAD_POLICY == sigsum.BAD_POLICY:
         print("UNMET POLICY REQUIREMENT!")
         status.gpg_error = 1
-    if sig.summary & sigsum.SYS_ERROR == sigsum.SYS_ERROR:
+    # pylint: disable=no-member
+    if signature.summary & sigsum.SYS_ERROR == sigsum.SYS_ERROR:
         print("SYSTEM ERROR!'")
         status.gpg_error = 1
 
@@ -157,8 +168,8 @@ def unsign_file(fname):
                 ctx.op_verify(infile, None, outfile)
                 vres = ctx.op_verify_result()
 
-                for sig in vres.signatures:
-                    status = check_signature(ctx, sig)
+                for signature in vres.signatures:
+                    status = check_signature(ctx, signature)
                     overall_status.add(status)
 
         if overall_status.to_exitcode():
@@ -166,10 +177,12 @@ def unsign_file(fname):
 
         return outfilename
 
-    except IOError as ex:
-        print(str(ex))
-    except Exception as ex:
-        print("Error checking the file %s: %s" % (fname, str(ex)))
+    except IOError as E:
+        print(E)
+    # For some odd reason, I need to put the pylint directive along
+    # the exception.  Otherwise it doesn't disable it ...
+    except Exception as E:    # pylint: disable=broad-except
+        print("Error checking the file %s: %s" % (fname, E))
 
     return None
 
@@ -194,6 +207,7 @@ def sign(infile, outfile, fingerprint):
 
     try:
         key = ctx.get_key(fingerprint, 0)
+    # pylint: disable=broad-except
     except Exception as ex:
         print("no key with fingerprint %s: %s" % (fingerprint, str(ex)))
 
@@ -204,11 +218,15 @@ def sign(infile, outfile, fingerprint):
     try:
         indata = core.Data(file=infile)
         outdata = core.Data()
+        # sig.mode.NORMA is probably define lazily and the static
+        # analyzer gets confuse
+        # pylint: disable=no-member
         ctx.op_sign(indata, outdata, sig.mode.NORMAL)
         outdata.seek(0, os.SEEK_SET)
         signature = outdata.read()
         with open(outfile, 'w') as fd:
             fd.write(signature)
+    # pylint: disable=broad-except
     except Exception as ex:
         print("Error signing file %s" % str(ex))
 
@@ -218,6 +236,7 @@ def sign_file(fname, fingerprint):
 
     try:
         sign(fname, outfilename, fingerprint)
+    # pylint: disable=broad-except
     except Exception as ex:
         print("Error signing file %s" % str(ex))
 
-- 
2.26.2




More information about the elbe-devel mailing list