pycodestyle: Do not use bare 'except:'

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
This commit is contained in:
Radostin Stoyanov 2017-07-24 09:26:48 +01:00 committed by Cole Robinson
parent 2fd6d9aa32
commit b93cc3bbc9
60 changed files with 125 additions and 127 deletions

View File

@ -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:

View File

@ -192,7 +192,7 @@ class TestInterfaces(unittest.TestCase):
assert(False)
except ValueError:
pass
except:
except Exception:
assert(False)
# protocol_xml test

View File

@ -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

View File

@ -74,7 +74,7 @@ def exit_cleanup():
for f in cleanup or []:
try:
os.unlink(f)
except:
except Exception:
pass
atexit.register(exit_cleanup)

View File

@ -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" %

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -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")
@ -2582,7 +2582,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)

View File

@ -50,7 +50,7 @@ def _make_ipaddr(addrstr):
return None
try:
return ipaddr.IPNetwork(addrstr)
except:
except Exception:
return None

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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(),

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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")

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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:

View File

@ -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.")

View File

@ -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

View File

@ -35,7 +35,7 @@ def spin_get_helper(widget):
try:
return int(txt)
except:
except Exception:
return adj.get_value()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -198,7 +198,7 @@ class Installer(object):
self.cleanup()
try:
self._prepare(guest, meter)
except:
except Exception:
self.cleanup()
raise

View File

@ -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

View File

@ -276,7 +276,7 @@ class Network(XMLBuilder):
net.create()
if autostart:
net.setAutostart(autostart)
except:
except Exception:
net.undefine()
raise

View File

@ -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

View File

@ -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)

View File

@ -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())

View File

@ -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)

View File

@ -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

View File

@ -721,7 +721,7 @@ class _XMLState(object):
try:
doc = libxml2.parseDoc(parsexml)
except:
except Exception:
logging.debug("Error parsing xml=\n%s", parsexml)
raise