[virt-tools-list] [virt-manager] [PATCH 5/5] pycodestyle: Do not use bare 'except:'

Radostin Stoyanov rstoyanov1 at gmail.com
Mon Jul 24 08:26:48 UTC 2017


A bare 'except:' catches all exceptions [1], including SystemExit,
KeyboardInterrupt, and GeneratorExit (which is not an error and should
not normally be caught by user code). In situations where you need to
catch all “normal” errors, you can catch the base class for all normal
exceptions, Exception [2].

[1] https://docs.python.org/2/howto/doanddont.html#except
[2] https://docs.python.org/2/library/exceptions.html#Exception
---
 setup.py                     |  8 +++-----
 tests/interface.py           |  2 +-
 tests/pycodestyle.cfg        |  2 +-
 tests/test_inject.py         |  2 +-
 tests/test_urls.py           |  2 +-
 tests/utils.py               |  6 +++---
 virt-convert                 |  2 +-
 virt-install                 |  2 +-
 virtManager/addhardware.py   |  2 +-
 virtManager/addstorage.py    |  2 +-
 virtManager/baseclass.py     |  4 ++--
 virtManager/clone.py         |  2 +-
 virtManager/config.py        |  2 +-
 virtManager/connect.py       |  6 +++---
 virtManager/connectauth.py   |  6 +++---
 virtManager/connection.py    |  8 ++++----
 virtManager/create.py        | 10 +++++-----
 virtManager/createnet.py     |  2 +-
 virtManager/createvol.py     |  4 ++--
 virtManager/delete.py        |  2 +-
 virtManager/details.py       |  6 +++---
 virtManager/domain.py        |  2 +-
 virtManager/engine.py        | 10 +++++-----
 virtManager/host.py          |  4 ++--
 virtManager/inspection.py    |  8 ++++----
 virtManager/keyring.py       |  8 ++++----
 virtManager/libvirtobject.py |  6 +++---
 virtManager/manager.py       |  2 +-
 virtManager/mediacombo.py    |  2 +-
 virtManager/netlist.py       |  2 +-
 virtManager/packageutils.py  |  8 ++++----
 virtManager/preferences.py   |  2 +-
 virtManager/serialcon.py     | 12 ++++++------
 virtManager/snapshots.py     |  8 ++++----
 virtManager/sshtunnels.py    |  6 +++---
 virtManager/storagelist.py   |  8 ++++----
 virtManager/systray.py       |  2 +-
 virtManager/uiutil.py        |  2 +-
 virtManager/viewers.py       |  6 +++---
 virtconv/formats.py          |  2 +-
 virtconv/vmx.py              |  2 +-
 virtinst/__init__.py         |  2 +-
 virtinst/cli.py              |  4 ++--
 virtinst/devicedisk.py       |  6 +++---
 virtinst/devicehostdev.py    |  2 +-
 virtinst/deviceinterface.py  |  2 +-
 virtinst/diskbackend.py      |  4 ++--
 virtinst/distroinstaller.py  |  2 +-
 virtinst/domcapabilities.py  |  2 +-
 virtinst/guest.py            |  8 ++++----
 virtinst/initrdinject.py     |  2 +-
 virtinst/installer.py        |  2 +-
 virtinst/kernelupload.py     |  2 +-
 virtinst/network.py          |  2 +-
 virtinst/nodedev.py          |  4 ++--
 virtinst/osdict.py           |  2 +-
 virtinst/pollhelpers.py      |  6 +++---
 virtinst/storage.py          |  4 ++--
 virtinst/urlfetcher.py       | 10 +++++-----
 virtinst/xmlbuilder.py       |  2 +-
 60 files changed, 125 insertions(+), 127 deletions(-)

diff --git a/setup.py b/setup.py
index 10bf932..6f4b37b 100755
--- a/setup.py
+++ b/setup.py
@@ -422,7 +422,7 @@ class TestBaseCommand(distutils.core.Command):
         try:
             import coverage
             use_cov = True
-        except:
+        except ImportError:
             use_cov = False
             cov = None
 
@@ -439,10 +439,8 @@ class TestBaseCommand(distutils.core.Command):
         testsmodule.utils.REGENERATE_OUTPUT = bool(self.regenerate_output)
 
         if hasattr(unittest, "installHandler"):
-            try:
-                unittest.installHandler()
-            except:
-                print("installHandler hack failed")
+            # Install the control-c handler.
+            unittest.installHandler()
 
         tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
         if self.only:
diff --git a/tests/interface.py b/tests/interface.py
index dbc305c..bd5b7bb 100644
--- a/tests/interface.py
+++ b/tests/interface.py
@@ -192,7 +192,7 @@ class TestInterfaces(unittest.TestCase):
             assert(False)
         except ValueError:
             pass
-        except:
+        except Exception:
             assert(False)
 
     # protocol_xml test
diff --git a/tests/pycodestyle.cfg b/tests/pycodestyle.cfg
index b28011f..bc9fc0d 100644
--- a/tests/pycodestyle.cfg
+++ b/tests/pycodestyle.cfg
@@ -30,4 +30,4 @@ format = pylint
 # E741: Do not use variables named ‘l’, ‘O’, or ‘I’
 
 
-ignore = E122, E123, E124, E125, E126, E127, E128, E129, E131, E203, E221, E241, E301, E303, E305, E306, E402, E501, E722, E741
+ignore = E122, E123, E124, E125, E126, E127, E128, E129, E131, E203, E221, E241, E301, E303, E305, E306, E402, E501, E741
diff --git a/tests/test_inject.py b/tests/test_inject.py
index 5107491..a9b939c 100755
--- a/tests/test_inject.py
+++ b/tests/test_inject.py
@@ -74,7 +74,7 @@ def exit_cleanup():
     for f in cleanup or []:
         try:
             os.unlink(f)
-        except:
+        except Exception:
             pass
 atexit.register(exit_cleanup)
 
diff --git a/tests/test_urls.py b/tests/test_urls.py
index c0fa0a5..01baa07 100644
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -229,7 +229,7 @@ def _testURL(fetcher, distname, arch, distroobj):
         xenstore = None
         if distroobj.hasxen:
             xenstore = _storeForDistro(fetcher, xenguest)
-    except:
+    except Exception:
         raise AssertionError("\nFailed to detect URLDistro class:\n"
             "name   = %s\n"
             "url    = %s\n\n%s" %
diff --git a/tests/utils.py b/tests/utils.py
index bee38a9..4c8547b 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -147,14 +147,14 @@ def test_create(testconn, xml, define_func="defineXML"):
         obj.create()
         obj.destroy()
         obj.undefine()
-    except:
+    except Exception:
         try:
             obj.destroy()
-        except:
+        except Exception:
             pass
         try:
             obj.undefine()
-        except:
+        except Exception:
             pass
 
 
diff --git a/virt-convert b/virt-convert
index 9a44d5f..c42f2ef 100755
--- a/virt-convert
+++ b/virt-convert
@@ -123,7 +123,7 @@ def main(conn=None):
             print_stdout(_("Creating guest '%s'.") % guest.name)
             guest.start_install()
             cli.connect_console(guest, conscb, True)
-    except:
+    except Exception:
         converter.cleanup()
         raise
 
diff --git a/virt-install b/virt-install
index b4b8ee9..0c7f9fe 100755
--- a/virt-install
+++ b/virt-install
@@ -73,7 +73,7 @@ def supports_pxe(guest):
             xmlobj = virtinst.Network(nic.conn, parsexml=netobj.XMLDesc(0))
             if xmlobj.can_pxe():
                 return True
-        except:
+        except Exception:
             logging.debug("Error checking if PXE supported", exc_info=True)
             return True
 
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 00a57f8..6ab2d4c 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1285,7 +1285,7 @@ class vmmAddHardware(vmmGObjectUI):
             try:
                 pool = self.conn.get_pool(poolname)
                 self.idle_add(pool.refresh)
-            except:
+            except Exception:
                 logging.debug("Error looking up pool=%s for refresh after "
                     "storage creation.", poolname, exc_info=True)
 
diff --git a/virtManager/addstorage.py b/virtManager/addstorage.py
index 81827c1..cdfd78e 100644
--- a/virtManager/addstorage.py
+++ b/virtManager/addstorage.py
@@ -90,7 +90,7 @@ class vmmAddStorage(vmmGObjectUI):
         widget = self.widget("phys-hd-label")
         try:
             max_storage = self._host_disk_space()
-        except:
+        except Exception:
             logging.exception("Error determining host disk space")
             widget.set_markup("")
             return
diff --git a/virtManager/baseclass.py b/virtManager/baseclass.py
index 9edf308..f8bff2b 100644
--- a/virtManager/baseclass.py
+++ b/virtManager/baseclass.py
@@ -74,7 +74,7 @@ class vmmGObject(GObject.GObject):
                 self.remove_gobject_timeout(h)
 
             self._cleanup()
-        except:
+        except Exception:
             logging.exception("Error cleaning up %s", self)
 
     def _cleanup(self):
@@ -84,7 +84,7 @@ class vmmGObject(GObject.GObject):
         try:
             if self.config and self._leak_check:
                 self.config.remove_object(self.object_key)
-        except:
+        except Exception:
             logging.exception("Error removing %s", self.object_key)
 
     # pylint: disable=arguments-differ
diff --git a/virtManager/clone.py b/virtManager/clone.py
index 8b8ce60..4623473 100644
--- a/virtManager/clone.py
+++ b/virtManager/clone.py
@@ -858,7 +858,7 @@ class vmmCloneVM(vmmGObjectUI):
                 try:
                     pool = self.conn.get_pool(poolname)
                     self.idle_add(pool.refresh)
-                except:
+                except Exception:
                     logging.debug("Error looking up pool=%s for refresh after "
                         "VM clone.", poolname, exc_info=True)
 
diff --git a/virtManager/config.py b/virtManager/config.py
index 6fd6530..38291a2 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -199,7 +199,7 @@ class vmmConfig(object):
             from guestfs import GuestFS  # pylint: disable=import-error
             g = GuestFS(close_on_exit=False)
             return bool(getattr(g, "add_libvirt_dom", None))
-        except:
+        except Exception:
             return False
 
     # General app wide helpers (gsettings agnostic)
diff --git a/virtManager/connect.py b/virtManager/connect.py
index 3fc1d4e..1dc9a2a 100644
--- a/virtManager/connect.py
+++ b/virtManager/connect.py
@@ -47,7 +47,7 @@ def current_user():
     try:
         import getpass
         return getpass.getuser()
-    except:
+    except Exception:
         return ""
 
 
@@ -472,7 +472,7 @@ class vmmConnect(vmmGObjectUI):
             elif self.can_resolve_local is None:
                 try:
                     socket.getaddrinfo(host, None)
-                except:
+                except Exception:
                     logging.debug("Couldn't resolve host '%s'. Stripping "
                                   "'.local' and retrying.", host)
                     self.can_resolve_local = False
@@ -486,7 +486,7 @@ class vmmConnect(vmmGObjectUI):
             elif self.can_resolve_hostname is None:
                 try:
                     socket.getaddrinfo(host, None)
-                except:
+                except Exception:
                     logging.debug("Couldn't resolve host '%s'. Disabling "
                                   "host name resolution, only using IP addr",
                                   host)
diff --git a/virtManager/connectauth.py b/virtManager/connectauth.py
index 3d8fd3c..50047ac 100644
--- a/virtManager/connectauth.py
+++ b/virtManager/connectauth.py
@@ -32,7 +32,7 @@ def do_we_have_session():
     pid = os.getpid()
     try:
         bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
-    except:
+    except Exception:
         logging.exception("Error getting system bus handle")
         return
 
@@ -46,7 +46,7 @@ def do_we_have_session():
         ret = manager.GetSessionByPID("(u)", pid)
         logging.debug("Found login1 session=%s", ret)
         return True
-    except:
+    except Exception:
         logging.exception("Couldn't connect to logind")
 
     return False
@@ -62,7 +62,7 @@ def creds_dialog(conn, creds):
     def wrapper(fn, conn, creds):
         try:
             ret = fn(conn, creds)
-        except:
+        except Exception:
             logging.exception("Error from creds dialog")
             ret = -1
         retipc.append(ret)
diff --git a/virtManager/connection.py b/virtManager/connection.py
index df4c51d..3464484 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -65,7 +65,7 @@ class _ObjectList(vmmGObject):
             for obj in self._objects:
                 try:
                     obj.cleanup()
-                except:
+                except Exception:
                     logging.debug("Failed to cleanup %s", exc_info=True)
             self._objects = []
         finally:
@@ -968,7 +968,7 @@ class vmmConnection(vmmGObject):
                     self._backend.storagePoolEventDeregisterAny(eid)
                 for eid in self._node_device_cb_ids:
                     self._backend.nodeDeviceEventDeregisterAny(eid)
-        except:
+        except Exception:
             logging.debug("Failed to deregister events in conn cleanup",
                 exc_info=True)
         finally:
@@ -1012,7 +1012,7 @@ class vmmConnection(vmmGObject):
     def _do_creds_password(self, creds):
         try:
             return connectauth.creds_dialog(self, creds)
-        except:
+        except Exception:
             logging.debug("Launching creds dialog failed", exc_info=True)
             return -1
 
@@ -1136,7 +1136,7 @@ class vmmConnection(vmmGObject):
             class_name = obj.class_name()
             try:
                 name = obj.get_name()
-            except:
+            except Exception:
                 name = str(obj)
 
             if not self._objects.remove(obj):
diff --git a/virtManager/create.py b/virtManager/create.py
index 10948cd..ef9c298 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -1611,7 +1611,7 @@ class vmmCreate(vmmGObjectUI):
         try:
             path, ignore = self._get_storage_path(newname, do_log=False)
             self._populate_summary_storage(path=path)
-        except:
+        except Exception:
             logging.debug("Error generating storage path on name change "
                 "for name=%s", newname, exc_info=True)
 
@@ -1862,7 +1862,7 @@ class vmmCreate(vmmGObjectUI):
         if guest.os.is_arm64():
             try:
                 guest.set_uefi_default()
-            except:
+            except Exception:
                 # If this errors we will have already informed the user
                 # on page 1.
                 pass
@@ -2365,7 +2365,7 @@ class vmmCreate(vmmGObjectUI):
 
             distro = installer.detect_distro(self._guest)
             thread_results.set_distro(distro)
-        except:
+        except Exception:
             logging.exception("Error detecting distro.")
             thread_results.set_failed()
 
@@ -2394,7 +2394,7 @@ class vmmCreate(vmmGObjectUI):
                 return
 
             distro = thread_results.get_distro()
-        except:
+        except Exception:
             distro = None
             logging.exception("Error in distro detect timeout")
 
@@ -2583,7 +2583,7 @@ class vmmCreate(vmmGObjectUI):
             try:
                 pool = self.conn.get_pool(poolname)
                 self.idle_add(pool.refresh)
-            except:
+            except Exception:
                 logging.debug("Error looking up pool=%s for refresh after "
                     "VM creation.", poolname, exc_info=True)
 
diff --git a/virtManager/createnet.py b/virtManager/createnet.py
index 585e45a..cbd9f59 100644
--- a/virtManager/createnet.py
+++ b/virtManager/createnet.py
@@ -50,7 +50,7 @@ def _make_ipaddr(addrstr):
         return None
     try:
         return ipaddr.IPNetwork(addrstr)
-    except:
+    except Exception:
         return None
 
 
diff --git a/virtManager/createvol.py b/virtManager/createvol.py
index 4928536..01edf4b 100644
--- a/virtManager/createvol.py
+++ b/virtManager/createvol.py
@@ -66,7 +66,7 @@ class vmmCreateVolume(vmmGObjectUI):
     def show(self, parent):
         try:
             parent_xml = self.parent_pool.xmlobj.get_xml_config()
-        except:
+        except Exception:
             logging.debug("Error getting parent_pool xml", exc_info=True)
             parent_xml = None
 
@@ -112,7 +112,7 @@ class vmmCreateVolume(vmmGObjectUI):
         try:
             ret = StorageVolume.find_free_name(
                 self.parent_pool.get_backend(), self.name_hint, suffix=suffix)
-        except:
+        except Exception:
             logging.exception("Error finding a default vol name")
 
         return ret
diff --git a/virtManager/delete.py b/virtManager/delete.py
index d564d72..c08f21c 100644
--- a/virtManager/delete.py
+++ b/virtManager/delete.py
@@ -217,7 +217,7 @@ class vmmDeleteDialog(vmmGObjectUI):
 
         try:
             vol = conn.storageVolLookupByPath(path)
-        except:
+        except Exception:
             logging.debug("Path '%s' is not managed. Deleting locally", path)
 
         if vol:
diff --git a/virtManager/details.py b/virtManager/details.py
index 267aa59..b102994 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -696,7 +696,7 @@ class vmmDetails(vmmGObjectUI):
         if self.console.details_viewer_is_visible():
             try:
                 self.console.details_close_viewer()
-            except:
+            except Exception:
                 logging.error("Failure when disconnecting from desktop server")
 
         self.emit("details-closed")
@@ -827,7 +827,7 @@ class vmmDetails(vmmGObjectUI):
                 machine=self.vm.get_machtype())
 
             machines = capsinfo.machines[:]
-        except:
+        except Exception:
             logging.exception("Error determining machine list")
 
         show_machine = (arch not in ["i686", "x86_64"])
@@ -2979,7 +2979,7 @@ class vmmDetails(vmmGObjectUI):
         heads = vid.heads
         try:
             ramlabel = ram and "%d MiB" % (int(ram) / 1024) or "-"
-        except:
+        except Exception:
             ramlabel = "-"
 
         self.widget("video-ram").set_text(ramlabel)
diff --git a/virtManager/domain.py b/virtManager/domain.py
index aedf3b2..fd70f9f 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -134,7 +134,7 @@ def start_job_progress_thread(vm, meter, progtext):
 
                 progress = data_total - data_remaining
                 meter.update(progress)
-            except:
+            except Exception:
                 logging.exception("Error calling jobinfo")
                 return False
 
diff --git a/virtManager/engine.py b/virtManager/engine.py
index 686f6f5..263acef 100644
--- a/virtManager/engine.py
+++ b/virtManager/engine.py
@@ -230,7 +230,7 @@ class vmmEngine(vmmGObject):
             packages = self.config.hv_packages + libvirt_packages
 
             ret = packageutils.check_packagekit(manager, manager.err, packages)
-        except:
+        except Exception:
             logging.exception("Error talking to PackageKit")
 
         if ret:
@@ -573,7 +573,7 @@ class vmmEngine(vmmGObject):
             else:
                 try:
                     conn.open()
-                except:
+                except Exception:
                     return None
             return conn
         except Exception:
@@ -593,7 +593,7 @@ class vmmEngine(vmmGObject):
                 win.cleanup()
 
             self.conns[uri]["conn"].cleanup()
-        except:
+        except Exception:
             logging.exception("Error cleaning up conn in engine")
 
 
@@ -1021,7 +1021,7 @@ class vmmEngine(vmmGObject):
                 return True
 
             return False
-        except:
+        except Exception:
             # In case of cli error, we may need to exit the app
             logging.debug("Error in cli connection callback", exc_info=True)
             self._exit_app_if_no_windows()
@@ -1065,7 +1065,7 @@ class vmmEngine(vmmGObject):
     def _handle_cli_command(self, actionobj, variant):
         try:
             return self._do_handle_cli_command(actionobj, variant)
-        except:
+        except Exception:
             # In case of cli error, we may need to exit the app
             logging.debug("Error handling cli command", exc_info=True)
             self._exit_app_if_no_windows()
diff --git a/virtManager/host.py b/virtManager/host.py
index 537febf..d24bc85 100644
--- a/virtManager/host.py
+++ b/virtManager/host.py
@@ -686,7 +686,7 @@ class vmmHost(vmmGObjectUI):
             for net in self.conn.list_nets():
                 try:
                     net.disconnect_by_func(self.refresh_network)
-                except:
+                except Exception:
                     pass
                 net.connect("state-changed", self.refresh_network)
                 model.append([net.get_connkey(), net.get_name(), "network-idle",
@@ -936,7 +936,7 @@ class vmmHost(vmmGObjectUI):
             for iface in self.conn.list_interfaces():
                 try:
                     iface.disconnect_by_func(self.refresh_interface)
-                except:
+                except Exception:
                     pass
                 iface.connect("state-changed", self.refresh_interface)
                 model.append([iface.get_connkey(), iface.get_name(),
diff --git a/virtManager/inspection.py b/virtManager/inspection.py
index b40de2e..f522e25 100644
--- a/virtManager/inspection.py
+++ b/virtManager/inspection.py
@@ -162,10 +162,10 @@ class vmmInspection(vmmGObject):
                     self._set_vm_inspection_data(vm, data)
                 else:
                     set_inspection_error(vm)
-            except:
+            except Exception:
                 set_inspection_error(vm)
                 raise
-        except:
+        except Exception:
             logging.exception("%s: exception while processing", prettyvm)
 
     def _inspect_vm(self, conn, vm):
@@ -217,13 +217,13 @@ class vmmInspection(vmmGObject):
             for mp_dev in mps:
                 try:
                     g.mount_ro(mp_dev[1], mp_dev[0])
-                except:
+                except Exception:
                     logging.exception("%s: exception mounting %s on %s "
                                       "(ignored)",
                                       prettyvm, mp_dev[1], mp_dev[0])
 
             filesystems_mounted = True
-        except:
+        except Exception:
             logging.exception("%s: exception while mounting disks (ignored)",
                               prettyvm)
 
diff --git a/virtManager/keyring.py b/virtManager/keyring.py
index d3a300a..385dfde 100644
--- a/virtManager/keyring.py
+++ b/virtManager/keyring.py
@@ -57,7 +57,7 @@ class vmmKeyring(object):
                                 "org.freedesktop.Secret.Collection", None)
 
             logging.debug("Using keyring session %s", self._session)
-        except:
+        except Exception:
             logging.exception("Error determining keyring")
 
 
@@ -83,7 +83,7 @@ class vmmKeyring(object):
             _id = self._collection.CreateItem("(a{sv}(oayays)b)",
                                               props, params, replace)[0]
             ret = int(_id.rsplit("/")[-1])
-        except:
+        except Exception:
             logging.exception("Failed to add keyring secret")
 
         return ret
@@ -95,7 +95,7 @@ class vmmKeyring(object):
                                            "org.freedesktop.secrets", path,
                                            "org.freedesktop.Secret.Item", None)
             iface.Delete("(s)", "/")
-        except:
+        except Exception:
             logging.exception("Failed to delete keyring secret")
 
     def get_secret(self, _id):
@@ -119,7 +119,7 @@ class vmmKeyring(object):
                 attrs["%s" % key] = "%s" % val
 
             ret = vmmSecret(label, secret, attrs)
-        except:
+        except Exception:
             logging.exception("Failed to get keyring secret id=%s", _id)
 
         return ret
diff --git a/virtManager/libvirtobject.py b/virtManager/libvirtobject.py
index c9be477..f55e0ce 100644
--- a/virtManager/libvirtobject.py
+++ b/virtManager/libvirtobject.py
@@ -96,7 +96,7 @@ class vmmLibvirtObject(vmmGObject):
     def __repr__(self):
         try:
             name = self.get_name()
-        except:
+        except Exception:
             name = ""
         return "<%s name=%s id=%s>" % (
                 self.__class__.__name__, name, hex(id(self)))
@@ -135,7 +135,7 @@ class vmmLibvirtObject(vmmGObject):
         try:
             self._key = newname
             self.conn.rename_object(self, origxml, newxml, oldconnkey)
-        except:
+        except Exception:
             self._key = oldname
             raise
         finally:
@@ -196,7 +196,7 @@ class vmmLibvirtObject(vmmGObject):
         initialize_failed = False
         try:
             self._init_libvirt_state()
-        except:
+        except Exception:
             logging.debug("Error initializing libvirt state for %s", self,
                 exc_info=True)
             initialize_failed = True
diff --git a/virtManager/manager.py b/virtManager/manager.py
index 5f38157..d69f7d9 100644
--- a/virtManager/manager.py
+++ b/virtManager/manager.py
@@ -78,7 +78,7 @@ def _get_inspection_icon_pixbuf(vm, w, h):
         pb.write(png_data)
         pb.close()
         return pb.get_pixbuf()
-    except:
+    except Exception:
         logging.exception("Error loading inspection icon data")
         vm.inspection.icon = None
         return None
diff --git a/virtManager/mediacombo.py b/virtManager/mediacombo.py
index 9446dfb..00b4f69 100644
--- a/virtManager/mediacombo.py
+++ b/virtManager/mediacombo.py
@@ -163,7 +163,7 @@ class vmmMediaCombo(vmmGObjectUI):
     def reset_state(self):
         try:
             self._populate_media()
-        except:
+        except Exception:
             logging.debug("Error populating mediadev combo", exc_info=True)
 
     def get_path(self):
diff --git a/virtManager/netlist.py b/virtManager/netlist.py
index 0006d20..772e988 100644
--- a/virtManager/netlist.py
+++ b/virtManager/netlist.py
@@ -62,7 +62,7 @@ class vmmNetworkList(vmmGObjectUI):
             self.conn.disconnect_by_func(self._repopulate_network_list)
             self.conn.disconnect_by_func(self._repopulate_network_list)
             self.conn.disconnect_by_func(self._repopulate_network_list)
-        except:
+        except Exception:
             pass
 
         self.conn = None
diff --git a/virtManager/packageutils.py b/virtManager/packageutils.py
index ddb15f6..643e60f 100644
--- a/virtManager/packageutils.py
+++ b/virtManager/packageutils.py
@@ -110,7 +110,7 @@ def start_libvirtd():
 
     try:
         bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
-    except:
+    except Exception:
         logging.exception("Error getting system bus handle")
         return
 
@@ -119,7 +119,7 @@ def start_libvirtd():
                                  "org.freedesktop.systemd1",
                                  "/org/freedesktop/systemd1",
                                  "org.freedesktop.systemd1.Manager", None)
-    except:
+    except Exception:
         logging.exception("Couldn't connect to systemd")
         return
 
@@ -134,7 +134,7 @@ def start_libvirtd():
         if str(state).lower().strip("'") == "active":
             logging.debug("libvirtd already active, not starting")
             return True
-    except:
+    except Exception:
         logging.exception("Failed to lookup libvirtd status")
         return
 
@@ -150,5 +150,5 @@ def start_libvirtd():
         time.sleep(2)
         logging.debug("Starting libvirtd appeared to succeed")
         return True
-    except:
+    except Exception:
         logging.exception("Failed to talk to system-config-services")
diff --git a/virtManager/preferences.py b/virtManager/preferences.py
index 2818b68..1013b99 100644
--- a/virtManager/preferences.py
+++ b/virtManager/preferences.py
@@ -238,7 +238,7 @@ class vmmPreferences(vmmGObjectUI):
             for k in val.split(','):
                 try:
                     key = int(k)
-                except:
+                except Exception:
                     key = None
 
                 if key is not None:
diff --git a/virtManager/serialcon.py b/virtManager/serialcon.py
index 87ac810..7caf6db 100644
--- a/virtManager/serialcon.py
+++ b/virtManager/serialcon.py
@@ -110,7 +110,7 @@ class LocalConsoleConnection(ConsoleConnection):
         try:
             if self.origtermios:
                 termios.tcsetattr(self.fd, termios.TCSANOW, self.origtermios)
-        except:
+        except Exception:
             # domain may already have exited, destroying the pty, so ignore
             pass
 
@@ -165,7 +165,7 @@ class LibvirtConsoleConnection(ConsoleConnection):
         if events & libvirt.VIR_EVENT_HANDLE_READABLE:
             try:
                 got = self.stream.recv(1024 * 100)
-            except:
+            except Exception:
                 logging.exception("Error receiving stream data")
                 self.close()
                 return
@@ -188,7 +188,7 @@ class LibvirtConsoleConnection(ConsoleConnection):
 
             try:
                 done = self.stream.send(self.terminalToStream)
-            except:
+            except Exception:
                 logging.exception("Error sending stream data")
                 self.close()
                 return
@@ -233,11 +233,11 @@ class LibvirtConsoleConnection(ConsoleConnection):
         if self.stream:
             try:
                 self.stream.eventRemoveCallback()
-            except:
+            except Exception:
                 logging.exception("Error removing stream callback")
             try:
                 self.stream.finish()
-            except:
+            except Exception:
                 logging.exception("Error finishing stream")
 
         self.stream = None
@@ -416,7 +416,7 @@ class vmmSerialConsole(vmmGObject):
             self.show_error(_("Error connecting to text console: %s") % e)
             try:
                 self.console.close()
-            except:
+            except Exception:
                 pass
 
         return False
diff --git a/virtManager/snapshots.py b/virtManager/snapshots.py
index 6f5b350..5545e73 100644
--- a/virtManager/snapshots.py
+++ b/virtManager/snapshots.py
@@ -192,7 +192,7 @@ class vmmSnapshotPage(vmmGObjectUI):
                 for snap in self.vm.list_snapshots():
                     if name == snap.get_name():
                         snaps.append(snap)
-            except:
+            except Exception:
                 pass
 
         snaps = []
@@ -406,7 +406,7 @@ class vmmSnapshotPage(vmmGObjectUI):
             try:
                 if stream:
                     stream.finish()
-            except:
+            except Exception:
                 pass
 
     def _get_screenshot(self):
@@ -424,7 +424,7 @@ class vmmSnapshotPage(vmmGObjectUI):
             # https://bugs.launchpad.net/qemu/+bug/1314293
             self._take_screenshot()
             mime, sdata = self._take_screenshot()
-        except:
+        except Exception:
             logging.exception("Error taking screenshot")
             return
 
@@ -518,7 +518,7 @@ class vmmSnapshotPage(vmmGObjectUI):
             filename = basesn + "." + _mime_to_ext(mime)
             logging.debug("Writing screenshot to %s", filename)
             open(filename, "wb").write(sndata)
-        except:
+        except Exception:
             logging.exception("Error saving screenshot")
 
     def _create_new_snapshot(self):
diff --git a/virtManager/sshtunnels.py b/virtManager/sshtunnels.py
index 507eb55..12390a3 100644
--- a/virtManager/sshtunnels.py
+++ b/virtManager/sshtunnels.py
@@ -51,13 +51,13 @@ class ConnectionInfo(object):
     def _is_listen_localhost(self, host=None):
         try:
             return ipaddr.IPNetwork(host or self.gaddr).is_loopback
-        except:
+        except Exception:
             return False
 
     def _is_listen_any(self):
         try:
             return ipaddr.IPNetwork(self.gaddr).is_unspecified
-        except:
+        except Exception:
             return False
 
     def _is_listen_none(self):
@@ -180,7 +180,7 @@ class _Tunnel(object):
         while True:
             try:
                 new = self._errfd.recv(1024)
-            except:
+            except Exception:
                 break
 
             if not new:
diff --git a/virtManager/storagelist.py b/virtManager/storagelist.py
index eea64e5..dd2caad 100644
--- a/virtManager/storagelist.py
+++ b/virtManager/storagelist.py
@@ -123,7 +123,7 @@ class vmmStorageList(vmmGObjectUI):
             self.conn.disconnect_by_func(self._conn_pool_count_changed)
             self.conn.disconnect_by_func(self._conn_pool_count_changed)
             self.conn.disconnect_by_func(self._conn_state_changed)
-        except:
+        except Exception:
             pass
         self.conn = None
 
@@ -384,7 +384,7 @@ class vmmStorageList(vmmGObjectUI):
                 try:
                     pool.disconnect_by_func(self._pool_changed)
                     pool.disconnect_by_func(self._pool_changed)
-                except:
+                except Exception:
                     pass
                 pool.connect("state-changed", self._pool_changed)
                 pool.connect("refreshed", self._pool_changed)
@@ -426,7 +426,7 @@ class vmmStorageList(vmmGObjectUI):
                 cap = str(vol.get_capacity())
                 sizestr = vol.get_pretty_capacity()
                 fmt = vol.get_format() or ""
-            except:
+            except Exception:
                 logging.debug("Error getting volume info for '%s', "
                               "hiding it", key, exc_info=True)
                 continue
@@ -439,7 +439,7 @@ class vmmStorageList(vmmGObjectUI):
                     namestr = ", ".join(names)
                     if not namestr:
                         namestr = None
-            except:
+            except Exception:
                 logging.exception("Failed to determine if storage volume in "
                                   "use.")
 
diff --git a/virtManager/systray.py b/virtManager/systray.py
index 07bb6bc..bbe5119 100644
--- a/virtManager/systray.py
+++ b/virtManager/systray.py
@@ -31,7 +31,7 @@ try:
     # pylint: disable=no-name-in-module
     # pylint: disable=wrong-import-order
     from gi.repository import AppIndicator3
-except:
+except Exception:
     AppIndicator3 = None
 
 
diff --git a/virtManager/uiutil.py b/virtManager/uiutil.py
index 8b67fea..2965c51 100644
--- a/virtManager/uiutil.py
+++ b/virtManager/uiutil.py
@@ -35,7 +35,7 @@ def spin_get_helper(widget):
 
     try:
         return int(txt)
-    except:
+    except Exception:
         return adj.get_value()
 
 
diff --git a/virtManager/viewers.py b/virtManager/viewers.py
index 74c4539..80bdb08 100644
--- a/virtManager/viewers.py
+++ b/virtManager/viewers.py
@@ -412,7 +412,7 @@ class VNCViewer(Viewer):
 
             try:
                 keys = [int(k) for k in keys.split(',')]
-            except:
+            except Exception:
                 logging.debug("Error in grab_keys configuration in Gsettings",
                               exc_info=True)
                 return
@@ -551,7 +551,7 @@ class SpiceViewer(Viewer):
             autoredir = self.config.get_auto_redirection()
             if autoredir:
                 gtk_session.set_property("auto-usbredir", True)
-        except:
+        except Exception:
             self._usbdev_manager = None
             logging.debug("Error initializing spice usb device manager",
                 exc_info=True)
@@ -678,7 +678,7 @@ class SpiceViewer(Viewer):
 
             try:
                 keys = [int(k) for k in keys.split(',')]
-            except:
+            except Exception:
                 logging.debug("Error in grab_keys configuration in Gsettings",
                               exc_info=True)
                 return
diff --git a/virtconv/formats.py b/virtconv/formats.py
index e0dbfa9..ad78fd1 100644
--- a/virtconv/formats.py
+++ b/virtconv/formats.py
@@ -185,7 +185,7 @@ def _find_input(input_file, parser, print_cb):
                         return path, p, force_clean
 
         raise RuntimeError("Could not find parser for file %s" % input_file)
-    except:
+    except Exception:
         for f in force_clean:
             shutil.rmtree(f)
         raise
diff --git a/virtconv/vmx.py b/virtconv/vmx.py
index 0de7282..fc6a526 100644
--- a/virtconv/vmx.py
+++ b/virtconv/vmx.py
@@ -115,7 +115,7 @@ def parse_vmdk(filename):
 
     try:
         vmdkfile = _VMXFile(content)
-    except:
+    except Exception:
         logging.exception("%s looked like a vmdk file, but parsing failed",
                           filename)
         return
diff --git a/virtinst/__init__.py b/virtinst/__init__.py
index bf8043c..175303a 100644
--- a/virtinst/__init__.py
+++ b/virtinst/__init__.py
@@ -26,7 +26,7 @@ def _setup_i18n():
 
     try:
         locale.setlocale(locale.LC_ALL, '')
-    except:
+    except Exception:
         # Can happen if user passed a bogus LANG
         pass
 
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 3a779bd..74f2e2f 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -131,7 +131,7 @@ class VirtStreamHandler(logging.StreamHandler):
             self.flush()
         except (KeyboardInterrupt, SystemExit):
             raise
-        except:
+        except Exception:
             self.handleError(record)
 
 
@@ -158,7 +158,7 @@ class VirtHelpFormatter(argparse.RawDescriptionHelpFormatter):
             if "\n" in text:
                 return text.splitlines()
             return return_default()
-        except:
+        except Exception:
             return return_default()
 
 
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index ebf92d2..abd2be9 100644
--- a/virtinst/devicedisk.py
+++ b/virtinst/devicedisk.py
@@ -186,7 +186,7 @@ class VirtualDisk(VirtualDevice):
 
             if not conn.is_remote():
                 return os.path.exists(path)
-        except:
+        except Exception:
             pass
 
         return False
@@ -257,7 +257,7 @@ class VirtualDisk(VirtualDevice):
                     int(label.split(":")[0].replace("+", "")))
                 if pwuid:
                     user = pwuid[0]
-        except:
+        except Exception:
             logging.debug("Exception grabbing qemu DAC user", exc_info=True)
             return None, []
 
@@ -308,7 +308,7 @@ class VirtualDisk(VirtualDevice):
             try:
                 try:
                     fix_perms(dirname, useacl)
-                except:
+                except Exception:
                     # If acl fails, fall back to chmod and retry
                     if not useacl:
                         raise
diff --git a/virtinst/devicehostdev.py b/virtinst/devicehostdev.py
index 34c00b0..ac544c8 100644
--- a/virtinst/devicehostdev.py
+++ b/virtinst/devicehostdev.py
@@ -90,7 +90,7 @@ class VirtualHostDevice(VirtualDevice):
         def safeint(val, fmt="%.3d"):
             try:
                 int(val)
-            except:
+            except Exception:
                 return str(val)
             return fmt % int(val)
 
diff --git a/virtinst/deviceinterface.py b/virtinst/deviceinterface.py
index 8575e6a..a1e696a 100644
--- a/virtinst/deviceinterface.py
+++ b/virtinst/deviceinterface.py
@@ -95,7 +95,7 @@ def _default_bridge(conn):
     # vif0.0 == netloop enslaved, eth0 == default route
     try:
         defn = int(dev[-1])
-    except:
+    except Exception:
         defn = -1
 
     if (defn >= 0 and
diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py
index 5a601bb..0a62332 100644
--- a/virtinst/diskbackend.py
+++ b/virtinst/diskbackend.py
@@ -89,7 +89,7 @@ def _stat_disk(path):
             # os.SEEK_END is not present on all systems
             size = os.lseek(fd, 0, 2)
             os.close(fd)
-        except:
+        except Exception:
             size = 0
         return False, size
     elif stat.S_ISREG(mode):
@@ -121,7 +121,7 @@ def check_if_path_managed(conn, path):
         if verr:
             try:
                 vol = _lookup_vol_by_basename(pool, path)
-            except:
+            except Exception:
                 pass
     except Exception as e:
         vol = None
diff --git a/virtinst/distroinstaller.py b/virtinst/distroinstaller.py
index a758f74..24f3538 100644
--- a/virtinst/distroinstaller.py
+++ b/virtinst/distroinstaller.py
@@ -277,7 +277,7 @@ class DistroInstaller(Installer):
                     "remote connection.")
             else:
                 distro = OSDB.lookup_os_by_media(self.location)
-        except:
+        except Exception:
             logging.debug("Error attempting to detect distro.", exc_info=True)
 
         logging.debug("installer.detect_distro returned=%s", distro)
diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
index 874fa1e..3629afe 100644
--- a/virtinst/domcapabilities.py
+++ b/virtinst/domcapabilities.py
@@ -85,7 +85,7 @@ class DomainCapabilities(XMLBuilder):
             try:
                 xml = conn.getDomainCapabilities(emulator, arch,
                     machine, hvtype)
-            except:
+            except Exception:
                 logging.debug("Error fetching domcapabilities XML",
                     exc_info=True)
 
diff --git a/virtinst/guest.py b/virtinst/guest.py
index 8d85a46..529286f 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -98,7 +98,7 @@ class Guest(XMLBuilder):
 
         try:
             conn.lookupByName(name)
-        except:
+        except Exception:
             return
         raise ValueError(_("Guest name '%s' is already in use.") % name)
 
@@ -323,7 +323,7 @@ class Guest(XMLBuilder):
         data = (self.os, self.on_reboot)
         try:
             self._propstore["os"] = self.os.copy()
-        except:
+        except Exception:
             self._finish_get_xml(data)
             raise
         return data
@@ -397,12 +397,12 @@ class Guest(XMLBuilder):
         # Handle undefining the VM if the initial startup fails
         try:
             domain.create()
-        except:
+        except Exception:
             import sys
             exc_info = sys.exc_info()
             try:
                 domain.undefine()
-            except:
+            except Exception:
                 pass
             raise exc_info[0], exc_info[1], exc_info[2]
 
diff --git a/virtinst/initrdinject.py b/virtinst/initrdinject.py
index 9ae9df6..bf433c4 100644
--- a/virtinst/initrdinject.py
+++ b/virtinst/initrdinject.py
@@ -31,7 +31,7 @@ def _rhel4_initrd_inject(initrd, injections):
                                      stderr=subprocess.PIPE)
         if "ext2 filesystem" not in file_proc.communicate()[0]:
             return False
-    except:
+    except Exception:
         logging.exception("Failed to file command for rhel4 initrd detection")
         return False
 
diff --git a/virtinst/installer.py b/virtinst/installer.py
index dd2a593..948f6ea 100644
--- a/virtinst/installer.py
+++ b/virtinst/installer.py
@@ -198,7 +198,7 @@ class Installer(object):
         self.cleanup()
         try:
             self._prepare(guest, meter)
-        except:
+        except Exception:
             self.cleanup()
             raise
 
diff --git a/virtinst/kernelupload.py b/virtinst/kernelupload.py
index ba24841..80bb9c6 100644
--- a/virtinst/kernelupload.py
+++ b/virtinst/kernelupload.py
@@ -113,7 +113,7 @@ def _upload_file(conn, meter, destpool, src):
         # Cleanup
         stream.finish()
         meter.end(size)
-    except:
+    except Exception:
         if vol:
             vol.delete(0)
         raise
diff --git a/virtinst/network.py b/virtinst/network.py
index dfc1436..a797154 100644
--- a/virtinst/network.py
+++ b/virtinst/network.py
@@ -276,7 +276,7 @@ class Network(XMLBuilder):
                 net.create()
             if autostart:
                 net.setAutostart(autostart)
-        except:
+        except Exception:
             net.undefine()
             raise
 
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
index c8f5adc..f29dda8 100644
--- a/virtinst/nodedev.py
+++ b/virtinst/nodedev.py
@@ -30,7 +30,7 @@ def _compare_int(nodedev_val, hostdev_val):
                 return int(val or '0x00', 16)
             else:
                 return int(val)
-        except:
+        except Exception:
             return -1
 
     nodedev_val = _intify(nodedev_val)
@@ -375,7 +375,7 @@ def _AddressStringToHostdev(conn, addrstr):
             hostdev.device = device
         else:
             raise RuntimeError("Unknown address type")
-    except:
+    except Exception:
         logging.debug("Error parsing node device string.", exc_info=True)
         raise
 
diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 854f59c..61c4061 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -351,7 +351,7 @@ class _OsVariant(object):
             for n in t:
                 new_version = new_version + ("%.4i" % int(n))
             version = new_version
-        except:
+        except Exception:
             pass
 
         return "%s-%s" % (self.distro, version)
diff --git a/virtinst/pollhelpers.py b/virtinst/pollhelpers.py
index b9a3d00..fd156bb 100644
--- a/virtinst/pollhelpers.py
+++ b/virtinst/pollhelpers.py
@@ -105,7 +105,7 @@ def _old_poll_helper(origmap, typename,
     for name in newActiveNames + newInactiveNames:
         try:
             check_obj(name)
-        except:
+        except Exception:
             logging.exception("Couldn't fetch %s '%s'", typename, name)
 
     return (origmap.values(), new.values(), current.values())
@@ -253,7 +253,7 @@ def _old_fetch_vms(backend, origmap, build_func):
                 connkey = vm.name()
 
                 check_new(vm, connkey)
-            except:
+            except Exception:
                 logging.exception("Couldn't fetch domain id '%s'", _id)
 
 
@@ -269,7 +269,7 @@ def _old_fetch_vms(backend, origmap, build_func):
                 connkey = name
 
                 check_new(vm, connkey)
-            except:
+            except Exception:
                 logging.exception("Couldn't fetch domain '%s'", name)
 
     return (origmap.values(), new.values(), current.values())
diff --git a/virtinst/storage.py b/virtinst/storage.py
index 3fc3ab9..e8e1479 100644
--- a/virtinst/storage.py
+++ b/virtinst/storage.py
@@ -262,7 +262,7 @@ class StoragePool(_StorageObject):
             for pool in conn.fetch_all_pools():
                 if pool.name == "default":
                     return pool.target_path
-        except:
+        except Exception:
             pass
 
         if build:
@@ -868,7 +868,7 @@ class StorageVolume(_StorageObject):
                     vol = self.pool.storageVolLookupByName(self.name)
                 vol.info()
                 break
-            except:
+            except Exception:
                 if time:  # pylint: disable=using-constant-test
                     # This 'if' check saves some noise from the test suite
                     time.sleep(.2)
diff --git a/virtinst/urlfetcher.py b/virtinst/urlfetcher.py
index 5e10bb5..1e944a4 100644
--- a/virtinst/urlfetcher.py
+++ b/virtinst/urlfetcher.py
@@ -195,7 +195,7 @@ class _HTTPURLFetcher(_URLFetcher):
         response.raise_for_status()
         try:
             size = int(response.headers.get('content-length'))
-        except:
+        except Exception:
             size = None
         return response, size
 
@@ -244,7 +244,7 @@ class _FTPURLFetcher(_URLFetcher):
 
         try:
             self._ftp.quit()
-        except:
+        except Exception:
             logging.debug("Error quitting ftp connection", exc_info=True)
 
         self._ftp = None
@@ -330,7 +330,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
                 subprocess.call(cmd)
                 try:
                     os.rmdir(self._srcdir)
-                except:
+                except Exception:
                     pass
         finally:
             self._mounted = False
@@ -664,7 +664,7 @@ class Distro(object):
         try:
             initrd = self.fetcher.acquireFile(initrdpath)
             return kernel, initrd, args
-        except:
+        except Exception:
             os.unlink(kernel)
             raise
 
@@ -874,7 +874,7 @@ class RHELDistro(RedHatDistro):
         def _safeint(c):
             try:
                 val = int(c)
-            except:
+            except Exception:
                 val = 0
             return val
 
diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py
index 5485cd7..9e234e9 100644
--- a/virtinst/xmlbuilder.py
+++ b/virtinst/xmlbuilder.py
@@ -721,7 +721,7 @@ class _XMLState(object):
 
         try:
             doc = libxml2.parseDoc(parsexml)
-        except:
+        except Exception:
             logging.debug("Error parsing xml=\n%s", parsexml)
             raise
 
-- 
2.9.4




More information about the virt-tools-list mailing list