[elbe-devel] [PATCH v2 40/66] hdimg: Fix Pylint

Olivier Dion dion at linutronix.de
Fri Jun 5 19:07:04 CEST 2020


266:42: W1401: (anomalous-backslash-in-string)
266:50: W1401: (anomalous-backslash-in-string)
148:0:  R0205: (useless-object-inheritance)
159:4:  R0201: (no-self-use)
215:15: W0703: (broad-except)
276:15: W0703: (broad-except)
267:30: W0631: (undefined-loop-variable)
269:26: W0631: (undefined-loop-variable)
293:0:  R0205: (useless-object-inheritance)
324:26: I1101: (c-extension-no-member)
332:22: I1101: (c-extension-no-member)
335:22: I1101: (c-extension-no-member)

Requires fix for undefined-loop-variable!

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/hdimg.py | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 5478cbda..9c516448 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -145,6 +145,8 @@ def build_image_mtd(mtd, target):
     return img_files
 
 
+# TODO:py3 Remove object inheritance
+# pylint: disable=useless-object-inheritance
 class grubinstaller_base(object):
     def __init__(self, fw_type=None):
         self.fs = mountpoint_dict()
@@ -156,7 +158,8 @@ class grubinstaller_base(object):
     def install(self, target):
         pass
 
-    def losetup(self, f):
+    @staticmethod
+    def losetup(f):
         loopdev = get_command_out('losetup --find --show "%s"' % f)
         return loopdev.rstrip('\n')
 
@@ -212,8 +215,8 @@ class grubinstaller202(grubinstaller_base):
                 do("chroot %s grub-install --no-floppy %s" %
                    (imagemnt, poopdev))
 
-        except Exception as E:
-            logging.exception(E)
+        except CommandError as E:
+            logging.error("Fail installing grub device: %s", E)
 
         finally:
             os.unlink(imagemntfs.fname("boot/grub/device.map"))
@@ -261,11 +264,16 @@ class grubinstaller97(grubinstaller_base):
 
             chroot(imagemnt, "update-initramfs -u -k all")
 
-            # Replace groot and kopt because
-            # else they will be given bad values
-            do('chroot %s sed -in "s/^# groot=.*$/# groot=\(hd0,%d\)/" %s' %
+            # Replace groot and kopt because else they will be given
+            # bad values
+            #
+            # FIXME - Pylint says: Using possibly undefined loop variable
+            # 'entry' (undefined-loop-variable).  entry is defined in
+            # the previous for-loop.
+            # # pylint: disable=undefined-loop-variable
+            do(r'chroot %s sed -in "s/^# groot=.*$/# groot=\(hd0,%d\)/" %s' %
                (imagemnt, int(entry.partnum) - 1, "/boot/grub/menu.lst"))
-            do('chroot %s sed -in "s/^# kopt=.*$/# kopt=root=LABEL=%s/" %s' %
+            do(r'chroot %s sed -in "s/^# kopt=.*$/# kopt=root=LABEL=%s/" %s' %
                (imagemnt, entry.label, "/boot/grub/menu.lst"))
 
             chroot(imagemnt, "update-grub")
@@ -273,8 +281,8 @@ class grubinstaller97(grubinstaller_base):
             do("chroot %s grub-install --no-floppy %s" %
                (imagemnt, poopdev))
 
-        except Exception as E:
-            logging.exception(E)
+        except CommandError as E:
+            logging.error("Fail installing grub device: %s", E)
 
         finally:
             os.unlink(imagemntfs.fname("boot/grub/device.map"))
@@ -289,7 +297,8 @@ class grubinstaller97(grubinstaller_base):
             do("kpartx -d %s" % poopdev, allow_fail=True)
             do("losetup -d %s" % poopdev, allow_fail=True)
 
-
+# TODO:py3 Remove object inheritance
+# pylint: disable=useless-object-inheritance
 class simple_fstype(object):
     def __init__(self, typ):
         self.type = typ
-- 
2.27.0




More information about the elbe-devel mailing list