[PATCH anaconda-storage] Code fixes of errors shown by pylint

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

 



---
 storage/__init__.py          |   10 +++++-----
 storage/deviceaction.py      |    7 ++-----
 storage/devicelibs/crypto.py |    1 -
 storage/devicelibs/lvm.py    |   26 +++++++++++++-------------
 storage/devicelibs/mdraid.py |    5 ++++-
 storage/devicelibs/swap.py   |    7 ++++---
 storage/devicetree.py        |    1 -
 storage/errors.py            |    3 ---
 storage/formats/__init__.py  |    1 -
 storage/formats/dmraid.py    |    2 --
 storage/formats/fs.py        |    7 +++----
 storage/formats/lvmpv.py     |    7 +++----
 storage/formats/mdraid.py    |    2 +-
 storage/formats/swap.py      |    4 +---
 storage/iscsi.py             |   39 +++++++++++++++++----------------------
 storage/miscutils.py         |    1 -
 storage/partitioning.py      |    1 -
 storage/udev.py              |    8 +++-----
 storage/zfcp.py              |    7 ++-----
 19 files changed, 58 insertions(+), 81 deletions(-)

diff --git a/storage/__init__.py b/storage/__init__.py
index fd9f289..58f12be 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -75,7 +75,7 @@ def storageInitialize(anaconda):
 
         device = storage.devicetree.resolveDevice(devspec)
         if device is None:
-            if self.getUpgrade():
+            if anaconda.id.getUpgrade():
                 return
             else:
                 anaconda.intf.messageWindow(_("Unknown Device"),
@@ -458,7 +458,7 @@ class Storage(object):
                    part.fileSystemType in ("ext3", "ext2", "fat16", "fat32"):
                     dests.append(part.path, device.name)
 
-            if not parts:
+            if not disk.partitions:
                 dests.append(device.path, device.name)
 
         return dests
@@ -650,7 +650,7 @@ class Storage(object):
                             return False
                     return True
         elif device.format.type == "swap":
-                return True
+            return True
 
         # be safe for anything else and default to off
         return False
@@ -867,7 +867,7 @@ class Storage(object):
     def writeKS(self, f):
         log.warning("Storage.writeKS not completely implemented")
         self.iscsi.writeKS(f)
-        self.zfcp.writeFS(f)
+        self.zfcp.writeKS(f)
 
 
 def getReleaseString(mountpoint):
@@ -1062,7 +1062,6 @@ class CryptTab(object):
                     except Exception:
                         self.blkidTab = None
 
-                for line in lines:
                     (line, pound, comment) = line.partition("#")
                     fields = line.split()
                     if not 2 <= len(fields) <= 4:
@@ -1147,6 +1146,7 @@ class FSSet(object):
         self.devicetree = devicetree
         self.cryptTab = None
         self.blkidTab = None
+        self.origFStab = None
         self.active = False
         self._dev = None
         self._devpts = None
diff --git a/storage/deviceaction.py b/storage/deviceaction.py
index ba4456a..b462108 100644
--- a/storage/deviceaction.py
+++ b/storage/deviceaction.py
@@ -22,7 +22,6 @@
 #
 
 import copy
-from parted import PARTITION_BOOT
 
 from udev import *
 
@@ -37,10 +36,8 @@ import logging
 log = logging.getLogger("storage")
 
 
-""" The values are just hints as to the ordering.
-
-    Eg: fsmod and devmod ordering depends on the mod (shrink -v- grow)
-"""
+# The values are just hints as to the ordering.
+# Eg: fsmod and devmod ordering depends on the mod (shrink -v- grow)
 ACTION_TYPE_NONE = 0
 ACTION_TYPE_DESTROY = 1000
 ACTION_TYPE_RESIZE = 500
diff --git a/storage/devicelibs/crypto.py b/storage/devicelibs/crypto.py
index 28da47c..771798a 100644
--- a/storage/devicelibs/crypto.py
+++ b/storage/devicelibs/crypto.py
@@ -23,7 +23,6 @@
 import os
 from pycryptsetup import CryptSetup
 
-import iutil
 from ..errors import *
 
 import gettext
diff --git a/storage/devicelibs/lvm.py b/storage/devicelibs/lvm.py
index 52d9315..b43ef0a 100644
--- a/storage/devicelibs/lvm.py
+++ b/storage/devicelibs/lvm.py
@@ -27,6 +27,7 @@ import re
 import iutil
 
 from ..errors import *
+from constants import *
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -115,9 +116,9 @@ def getPossiblePhysicalExtents(floor=0):
     possiblePE = []
     curpe = 8
     while curpe <= 16384*1024:
-	if curpe >= floor:
-	    possiblePE.append(curpe)
-	curpe = curpe * 2
+        if curpe >= floor:
+            possiblePE.append(curpe)
+        curpe = curpe * 2
 
     return possiblePE
 
@@ -139,21 +140,20 @@ def safeLvmName(name):
 def getVGUsedSpace(vgreq, requests, diskset):
     vgused = 0
     for request in requests.requests:
-	if request.type == REQUEST_LV and request.volumeGroup == vgreq.uniqueID:
-	    size = int(request.getActualSize(requests, diskset))
-	    vgused = vgused + size
-
+        if request.type == REQUEST_LV and request.volumeGroup == vgreq.uniqueID:
+            size = int(request.getActualSize(requests, diskset))
+            vgused = vgused + size
 
     return vgused
 
 def getVGFreeSpace(vgreq, requests, diskset):
     raise NotImplementedError
-    used = getVGUsedSpace(vgreq, requests, diskset)
-    log.debug("used space is %s" % (used,))
-    
-    total = vgreq.getActualSize(requests, diskset)
-    log.debug("actual space is %s" % (total,))
-    return total - used
+    #used = getVGUsedSpace(vgreq, requests, diskset)
+    #log.debug("used space is %s" % (used,))
+    #
+    #total = vgreq.getActualSize(requests, diskset)
+    #log.debug("actual space is %s" % (total,))
+    #return total - used
 
 def clampSize(size, pesize, roundup=None):
     if roundup:
diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py
index d02b6ea..185aa14 100644
--- a/storage/devicelibs/mdraid.py
+++ b/storage/devicelibs/mdraid.py
@@ -28,6 +28,9 @@ from ..errors import *
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
 
+import logging
+log = logging.getLogger("storage")
+
 # raidlevels constants
 RAID10 = 10
 RAID6 = 6
@@ -39,7 +42,7 @@ def getRaidLevels():
     avail = []
     try:
         f = open("/proc/mdstat", "r")
-    except:
+    except IOError:
         pass
     else:
         for l in f.readlines():
diff --git a/storage/devicelibs/swap.py b/storage/devicelibs/swap.py
index 38000eb..dadeb0a 100644
--- a/storage/devicelibs/swap.py
+++ b/storage/devicelibs/swap.py
@@ -23,7 +23,7 @@
 import resource
 
 import iutil
-import resource
+import os
 
 from ..errors import *
 
@@ -52,15 +52,16 @@ def swapon(device, priority=None):
         num = pagesize
     else:
         num = 2048
+
     try:
         fd = os.open(device, os.O_RDONLY)
         buf = os.read(fd, num)
-    except:
+    except OSError:
         pass
     finally:
         try:
             os.close(fd)
-        except:
+        except (OSError, UnboundLocalError):
             pass
 
     if buf is not None and len(buf) == pagesize:
diff --git a/storage/devicetree.py b/storage/devicetree.py
index b9552bd..2025c20 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -1381,7 +1381,6 @@ class DeviceTree(object):
             except DeviceError:
                 # the pvremoves will finish the job.
                 log.debug("There was an error destroying the VG %s." % vg.name)
-                pass
 
             # remove VG device from list.
             self._removeDevice(vg)
diff --git a/storage/errors.py b/storage/errors.py
index 8fb57b1..d2d35ee 100644
--- a/storage/errors.py
+++ b/storage/errors.py
@@ -18,9 +18,6 @@ class DeviceSetupError(DeviceError):
 class DeviceTeardownError(DeviceError):
     pass
 
-class DeviceResizeError(DeviceError):
-    pass
-
 class DeviceUserDeniedFormatError(DeviceError):
     pass
 
diff --git a/storage/formats/__init__.py b/storage/formats/__init__.py
index 9ec0999..784bb1c 100644
--- a/storage/formats/__init__.py
+++ b/storage/formats/__init__.py
@@ -284,7 +284,6 @@ class DeviceFormat(object):
     def teardown(self, *args, **kwargs):
         log_method_call(self, device=self.device,
                         type=self.type, status=self.status)
-        pass
 
     @property
     def status(self):
diff --git a/storage/formats/dmraid.py b/storage/formats/dmraid.py
index f5f2808..4ebd41c 100644
--- a/storage/formats/dmraid.py
+++ b/storage/formats/dmraid.py
@@ -20,8 +20,6 @@
 # Red Hat Author(s): Dave Lehman <dlehman@xxxxxxxxxx>
 #
 
-import block
-
 from iutil import log_method_call
 from ..errors import *
 from . import DeviceFormat, register_device_format
diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index 8864b3a..36e3691 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -663,10 +663,9 @@ class FS(DeviceFormat):
 
         return _type
 
-    """ These methods just wrap filesystem-specific methods in more
-        generically named methods so filesystems and formatted devices
-        like swap and LVM physical volumes can have a common API.
-    """
+    # These methods just wrap filesystem-specific methods in more
+    # generically named methods so filesystems and formatted devices
+    # like swap and LVM physical volumes can have a common API.
     def create(self, *args, **kwargs):
         if self.exists:
             raise FSError("filesystem already exists")
diff --git a/storage/formats/lvmpv.py b/storage/formats/lvmpv.py
index c9cbe29..a111635 100644
--- a/storage/formats/lvmpv.py
+++ b/storage/formats/lvmpv.py
@@ -74,7 +74,6 @@ class LVMPhysicalVolume(DeviceFormat):
         if not self.exists:
             raise PhysicalVolumeError("format has not been created")
 
-        pass
         #info = lvm.pvinfo(self.device)
         #self.vgName = info['vg_name']
         #self.vgUuid = info['vg_uuid']
@@ -84,9 +83,9 @@ class LVMPhysicalVolume(DeviceFormat):
         log_method_call(self, device=self.device,
                         type=self.type, status=self.status)
         DeviceFormat.create(self, *args, **kwargs)
-        """ Consider use of -Z|--zero
-            -f|--force or -y|--yes may be required
-        """
+        # Consider use of -Z|--zero
+        # -f|--force or -y|--yes may be required
+
         # lvm has issues with persistence of metadata, so here comes the
         # hammer...
         DeviceFormat.destroy(self, *args, **kwargs)
diff --git a/storage/formats/mdraid.py b/storage/formats/mdraid.py
index 0871a2a..ec1a617 100644
--- a/storage/formats/mdraid.py
+++ b/storage/formats/mdraid.py
@@ -69,7 +69,7 @@ class MDRaidMember(DeviceFormat):
         log_method_call(self, device=self.device,
                         type=self.type, status=self.status)
         if not self.exists:
-            raise MDRaidMemberError("format does not exist")
+            raise MDMemberError("format does not exist")
 
         info = mdraid.mdexamine(self.device)
         if self.uuid is None:
diff --git a/storage/formats/swap.py b/storage/formats/swap.py
index e5dd8ef..bc5dbd9 100644
--- a/storage/formats/swap.py
+++ b/storage/formats/swap.py
@@ -20,9 +20,7 @@
 # Red Hat Author(s): Dave Lehman <dlehman@xxxxxxxxxx>
 #
 
-import os
-
-from iutil import log_method_call
+from iutil import log_method_call, numeric_type
 from parted import PARTITION_SWAP
 from ..errors import *
 from ..devicelibs import swap
diff --git a/storage/iscsi.py b/storage/iscsi.py
index b9f975e..3e6dc0a 100644
--- a/storage/iscsi.py
+++ b/storage/iscsi.py
@@ -20,11 +20,7 @@
 
 from constants import *
 import os
-import errno
-import string
-import signal
 import iutil
-import isys
 from flags import flags
 import logging
 import shutil
@@ -39,11 +35,10 @@ _ = lambda x: gettext.ldgettext("anaconda", x)
 has_libiscsi = True
 try:
     import libiscsi
-except:
+except ImportError:
     has_libiscsi = False
 
 # Note that stage2 copies all files under /sbin to /usr/sbin
-global ISCSID
 ISCSID=""
 INITIATOR_FILE="/etc/iscsi/initiatorname.iscsi"
 
@@ -141,19 +136,19 @@ class iscsi(object):
             return
 
         try:
-             found_nodes = libiscsi.discover_firmware()
+            found_nodes = libiscsi.discover_firmware()
         except:
-             # an exception here means there is no ibft firmware, just return
-             return
+            # an exception here means there is no ibft firmware, just return
+            return
 
         for node in found_nodes:
             try:
-                 node.login()
-                 self.nodes.append(node)
+                node.login()
+                self.nodes.append(node)
             except:
-                 # FIXME, what to do when we cannot log in to a firmware
-                 # provided node ??
-                 pass
+                # FIXME, what to do when we cannot log in to a firmware
+                # provided node ??
+                pass
 
         stabilize(intf)
 
@@ -234,14 +229,14 @@ class iscsi(object):
 
             found = found + 1
             try:
-                 if (authinfo):
-                     node.setAuth(authinfo)
-                 node.login()
-                 self.nodes.append(node)
-                 logged_in = logged_in + 1
+                if (authinfo):
+                    node.setAuth(authinfo)
+                node.login()
+                self.nodes.append(node)
+                logged_in = logged_in + 1
             except:
-                 # some nodes may require different credentials
-                 pass
+                # some nodes may require different credentials
+                pass
 
         if intf:
             w.pop()
@@ -287,7 +282,7 @@ class iscsi(object):
                     if node.name    == disk.iscsi_name and \
                        node.address == disk.iscsi_address and \
                        node.port    == disk.iscsi_port:
-                        node.setParameter("node.startup", "automatic");
+                        node.setParameter("node.startup", "automatic")
                         break
 
             if not os.path.isdir(instPath + "/etc/iscsi"):
diff --git a/storage/miscutils.py b/storage/miscutils.py
index b9c9740..e577497 100644
--- a/storage/miscutils.py
+++ b/storage/miscutils.py
@@ -1,5 +1,4 @@
 # iutil.py stubs
-import sys
 import os
 
 import logging
diff --git a/storage/partitioning.py b/storage/partitioning.py
index 9f42a72..6af4e8d 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -22,7 +22,6 @@
 
 import sys
 import os
-import copy
 from operator import add, sub
 
 import parted
diff --git a/storage/udev.py b/storage/udev.py
index 11df629..a1b2e1f 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -21,7 +21,6 @@
 #
 
 import os
-import re
 import stat
 
 import iutil
@@ -170,9 +169,8 @@ def udev_trigger(subsystem=None):
     iutil.execWithRedirect("udevadm", argv, stderr="/dev/null", searchPath=1)
 
 
-""" These are functions for retrieving specific pieces of information from
-    udev database entries.
-"""
+# These are functions for retrieving specific pieces of information from
+# udev database entries.
 def udev_device_get_name(udev_info):
     """ Return the best name for a device based on the udev db data. """
     return udev_info.get("DM_NAME", udev_info["name"])
@@ -313,7 +311,7 @@ def udev_device_is_dmraid(info):
 def udev_device_get_dmraid_partition_disk(info):
     try:
         p_index = info["DM_NAME"].rindex("p")
-    except:
+    except (KeyError, AttributeError, ValueError):
         return None
 
     if not info["DM_NAME"][p_index+1:].isdigit():
diff --git a/storage/zfcp.py b/storage/zfcp.py
index e38b818..2584268 100644
--- a/storage/zfcp.py
+++ b/storage/zfcp.py
@@ -21,9 +21,6 @@
 
 import string
 import os
-import iutil
-import isys
-import shutil
 from constants import *
 
 import gettext
@@ -94,7 +91,7 @@ class ZFCPDevice:
         try:
             int(hex, 16)
             return True
-        except:
+        except TypeError:
             return False
 
     def checkValidDevice(self, id):
@@ -184,7 +181,7 @@ class ZFCP:
     def readConfig(self):
         try:
             f = open("/tmp/fcpconfig", "r")
-        except:
+        except IOError:
             log.info("no /tmp/fcpconfig; not configuring zfcp")
             return
 
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux