[jhbuild] flake8: remove all bare excepts (E722)



commit 466380f8fe1ead5c8bd24b3e725acd93beda78cf
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sun Sep 22 21:31:32 2019 +0200

    flake8: remove all bare excepts (E722)
    
    Use Exception in case it's not clear what the errors could be
    and exact errors everywhere else.

 .flake8                         |  2 +-
 jhbuild/commands/goalreport.py  | 17 +++++++++--------
 jhbuild/commands/sanitycheck.py | 12 ++++++------
 jhbuild/config.py               |  6 +++---
 jhbuild/frontends/autobuild.py  |  2 +-
 jhbuild/frontends/gtkui.py      |  2 +-
 jhbuild/frontends/terminal.py   | 20 ++++++++++----------
 jhbuild/modtypes/__init__.py    |  2 +-
 jhbuild/modtypes/autotools.py   |  2 +-
 jhbuild/modtypes/cmake.py       |  2 +-
 jhbuild/modtypes/testmodule.py  |  2 +-
 jhbuild/utils/cmds.py           |  2 +-
 jhbuild/utils/httpcache.py      |  4 ++--
 jhbuild/utils/sysid.py          | 12 ++++++------
 jhbuild/utils/systeminstall.py  | 15 +++++++--------
 jhbuild/utils/trayicon.py       |  2 +-
 jhbuild/utils/unpack.py         |  2 +-
 jhbuild/versioncontrol/bzr.py   |  6 +++---
 jhbuild/versioncontrol/git.py   |  8 ++++----
 jhbuild/versioncontrol/svn.py   |  2 +-
 20 files changed, 61 insertions(+), 61 deletions(-)
---
diff --git a/.flake8 b/.flake8
index 4c5ca664..2585131a 100644
--- a/.flake8
+++ b/.flake8
@@ -1,4 +1,4 @@
 [flake8]
-ignore=E122,E402,E126,E128,E401,W504,W503,E201,E302,E305,E251,E203,E124,E231,W293,E261,E221,E211,E502,E722,W391,E301,E202,E225,E227,W291,E303,E226,E131,E123,E241,W292
+ignore=E122,E402,E126,E128,E401,W504,W503,E201,E302,E305,E251,E203,E124,E231,W293,E261,E221,E211,E502,W391,E301,E202,E225,E227,W291,E303,E226,E131,E123,E241,W292
 max-line-length=160
 builtins=SRCDIR,PKGDATADIR,DATADIR
\ No newline at end of file
diff --git a/jhbuild/commands/goalreport.py b/jhbuild/commands/goalreport.py
index 8e0e9f2a..48e621bb 100644
--- a/jhbuild/commands/goalreport.py
+++ b/jhbuild/commands/goalreport.py
@@ -37,6 +37,7 @@ except ImportError:
     curses = None
 
 import jhbuild.moduleset
+from jhbuild.errors import CommandError
 from jhbuild.commands import Command, register_command
 from jhbuild.utils import httpcache, cmds, _
 from jhbuild.modtypes import MetaModule
@@ -44,18 +45,18 @@ from jhbuild.utils.compat import BytesIO
 
 try:
     t_bold = cmds.get_output(['tput', 'bold'])
-except:
+except CommandError:
     try:
         t_bold = cmds.get_output(['tput', 'md'])
-    except:
+    except CommandError:
         t_bold = ''
 
 try:
     t_reset = cmds.get_output(['tput', 'sgr0'])
-except:
+except CommandError:
     try:
         t_reset = cmds.get_output(['tput', 'me'])
-    except:
+    except CommandError:
         t_reset = ''
 
 HTML_AT_TOP = '''<html>
@@ -316,7 +317,7 @@ class DeprecatedSymbolsCheck(SymbolsCheck):
             try:
                 devhelp_path = os.path.join(self.config.devhelp_dirname, devhelp_filename)
                 tree = ET.parse(devhelp_path)
-            except:
+            except Exception:
                 raise CouldNotPerformCheckException()
             for keyword in tree.findall('//{http://www.devhelp.net/book}keyword'):
                 if 'deprecated' not in keyword.attrib:
@@ -372,7 +373,7 @@ class cmd_goalreport(Command):
             if curses and config.progress_bar:
                 try:
                     curses.setupterm()
-                except:
+                except Exception:
                     curses = None
         else:
             output = sys.stdout
@@ -400,7 +401,7 @@ class cmd_goalreport(Command):
         if options.cache:
             try:
                 results = pickle.load(open(os.path.join(cachedir, options.cache)))
-            except:
+            except Exception:
                 pass
 
         self.repeat_row_header = 0
@@ -521,7 +522,7 @@ class cmd_goalreport(Command):
                 r = results[module_name].get('results')
                 try:
                     version = module_set.get_module(module_name).branch.version
-                except:
+                except Exception:
                     version = None
                 print(self.get_mod_line(module_name, r, version_number=version), file=output)
 
diff --git a/jhbuild/commands/sanitycheck.py b/jhbuild/commands/sanitycheck.py
index 71c6f29e..ed34c1be 100644
--- a/jhbuild/commands/sanitycheck.py
+++ b/jhbuild/commands/sanitycheck.py
@@ -84,7 +84,7 @@ class cmd_sanitycheck(Command):
         xmlcatalog = True
         try:
             get_output(['which', 'xmlcatalog'])
-        except:
+        except CommandError:
             xmlcatalog = False
             uprint(_('Could not find XML catalog (usually part of the package \'libxml2-utils\')'))
 
@@ -95,14 +95,14 @@ class cmd_sanitycheck(Command):
                                   'DocBook XSL Stylesheets')]:
                 try:
                     get_output(['xmlcatalog', '/etc/xml/catalog', item])
-                except:
+                except CommandError:
                     uprint(_('Could not find %s in XML catalog (usually part of package \'docbook-xsl\')') % 
name)
 
         # Perl module used by tools such as intltool:
         perlmod = 'XML::Parser'
         try:
             get_output(['perl', '-M%s' % perlmod, '-e', 'exit'])
-        except:
+        except CommandError:
             uprint(_('Could not find the Perl module %s (usually part of package \'libxml-parser-perl\' or 
\'perl-XML-Parser\')') % perlmod)
 
         # check for a downloading util:
@@ -122,7 +122,7 @@ class cmd_sanitycheck(Command):
                     if not check_version(['git', '--version'],
                                  r'git version ([\d.]+)', '1.5.6'):
                         uprint(_('%s not found') % 'git >= 1.5.6')
-            except:
+            except EnvironmentError:
                 uprint(_('Could not check git program'))
 
         # check for flex/bison:
@@ -137,12 +137,12 @@ class cmd_sanitycheck(Command):
         try:
             import glib
             glib
-        except:
+        except ImportError:
             uprint(_('%s not found') % 'python-gobject')
         try:
             import dbus.glib
             dbus.glib
-        except:
+        except ImportError:
             uprint(_('%s not found') % 'dbus-python')
 
     def check_m4(self):
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 49183bad..416b5a5a 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -109,7 +109,7 @@ class Config:
         env_prepends.clear()
         try:
             execfile(_defaults_file, self._config)
-        except:
+        except Exception:
             traceback.print_exc()
             raise FatalError(_('could not load config defaults'))
 
@@ -183,7 +183,7 @@ class Config:
         '''Read configuration variables from a file.'''
         try:
             execfile(filename, self._config)
-        except:
+        except Exception:
             traceback.print_exc()
             raise FatalError(_('Could not include config file (%s)') % filename)
 
@@ -300,7 +300,7 @@ class Config:
         if not os.path.exists(self.prefix):
             try:
                 os.makedirs(self.prefix)
-            except:
+            except EnvironmentError:
                 raise FatalError(_('install prefix (%s) can not be created') % self.prefix)
 
         if not os.path.exists(self.top_builddir):
diff --git a/jhbuild/frontends/autobuild.py b/jhbuild/frontends/autobuild.py
index c5b99b43..8b889c6f 100644
--- a/jhbuild/frontends/autobuild.py
+++ b/jhbuild/frontends/autobuild.py
@@ -48,7 +48,7 @@ def fix_encoding(string):
     for encoding in [charset, 'utf-8', 'iso-8859-15']:
         try:
             s = text_type(string, encoding)
-        except:
+        except ValueError:
             continue
         break
     return s.encode('us-ascii', 'xmlcharrefreplace')
diff --git a/jhbuild/frontends/gtkui.py b/jhbuild/frontends/gtkui.py
index 71e1e6e7..564d7d57 100644
--- a/jhbuild/frontends/gtkui.py
+++ b/jhbuild/frontends/gtkui.py
@@ -379,7 +379,7 @@ class AppWindow(gtk.Window, buildscript.BuildScript):
         try:
             error_message = error.args[0]
             self.message('%s: %s' % (summary, error_message))
-        except:
+        except Exception:
             error_message = None
             self.message(summary)
 
diff --git a/jhbuild/frontends/terminal.py b/jhbuild/frontends/terminal.py
index aab8b2c4..983cceef 100644
--- a/jhbuild/frontends/terminal.py
+++ b/jhbuild/frontends/terminal.py
@@ -40,18 +40,18 @@ del term
 
 try:
     t_bold = cmds.get_output(['tput', 'bold'])
-except:
+except CommandError:
     try:
         t_bold = cmds.get_output(['tput', 'md'])
-    except:
+    except CommandError:
         t_bold = u''
 
 try:
     t_reset = cmds.get_output(['tput', 'sgr0'])
-except:
+except CommandError:
     try:
         t_reset = cmds.get_output(['tput', 'me'])
-    except:
+    except CommandError:
         t_reset = u''
 
 t_colour = [u''] * 16
@@ -59,17 +59,17 @@ try:
     for i in range(8):
         t_colour[i] = cmds.get_output(['tput', 'setf', '%d' % i])
         t_colour[i+8] = t_bold + t_colour[i]
-except:
+except CommandError:
     try:
         for index, i in enumerate([0, 4, 2, 6, 1, 5, 3, 7]):
             t_colour[index] = cmds.get_output(['tput', 'setaf', '%d' % i])
             t_colour[index+8] = t_bold + t_colour[index]
-    except:
+    except CommandError:
         try:
             for index, i in enumerate([0, 4, 2, 6, 1, 5, 3, 7]):
                 t_colour[index] = cmds.get_output(['tput', 'AF', '%d' % i])
                 t_colour[index+8] = t_bold + t_colour[index]
-        except:
+        except CommandError:
             pass
 
 
@@ -82,7 +82,7 @@ except ImportError:
 else:
     try:
         curses.setupterm()
-    except:
+    except curses.error:
         pass
 
 # tray icon stuff ...
@@ -318,7 +318,7 @@ class TerminalBuildScript(buildscript.BuildScript):
         try:
             error_message = error.args[0]
             self.message('%s: %s' % (summary, error_message))
-        except:
+        except Exception:
             error_message = None
             self.message(summary)
         self.trayicon.set_icon(os.path.join(icondir, 'error.png'))
@@ -393,7 +393,7 @@ class TerminalBuildScript(buildscript.BuildScript):
                 try:
                     val = int(val)
                     selected_phase = altphases[val - nb_options]
-                except:
+                except (ValueError, IndexError):
                     uprint(_('invalid choice'))
                     continue
                 try:
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index f1cf35c3..16388592 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -636,7 +636,7 @@ class DownloadableModule:
             builddir = self.get_builddir(buildscript)
             if os.path.exists(builddir):
                 shutil.rmtree(builddir)
-        except:
+        except Exception:
             pass
         buildscript.set_action(_('Checking out'), self)
         self.branch.force_checkout(buildscript)
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index f90b4a3d..fd5625b6 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -226,7 +226,7 @@ class AutogenModule(MakeModule, DownloadableModule):
         try:
             if not (os.stat(os.path.join(srcdir, self.autogen_sh))[stat.ST_MODE] & 0o111):
                 os.chmod(os.path.join(srcdir, self.autogen_sh), 0o755)
-        except:
+        except EnvironmentError:
             pass
 
         if self.autogen_sh == 'autoreconf':
diff --git a/jhbuild/modtypes/cmake.py b/jhbuild/modtypes/cmake.py
index 112bba20..8ea59cf1 100644
--- a/jhbuild/modtypes/cmake.py
+++ b/jhbuild/modtypes/cmake.py
@@ -87,7 +87,7 @@ class CMakeModule(MakeModule, NinjaModule, DownloadableModule):
                 # Clear CMake files so we get a clean configure.
                 os.unlink(os.path.join(builddir, 'CMakeCache.txt'))
                 shutil.rmtree(os.path.join(builddir, 'CMakeFiles'))
-            except:
+            except EnvironmentError:
                 pass
         else:
             os.makedirs(builddir)
diff --git a/jhbuild/modtypes/testmodule.py b/jhbuild/modtypes/testmodule.py
index 2b012add..aa3b33fe 100644
--- a/jhbuild/modtypes/testmodule.py
+++ b/jhbuild/modtypes/testmodule.py
@@ -290,7 +290,7 @@ class TestModule(Package, DownloadableModule):
             flag, status = self.check_groups(groups)
             if flag:
                 raise BuildStateError(status)
-        except:
+        except Exception:
             raise BuildStateError('malformed log file')
 
     def do_dogtail_test(self, buildscript):
diff --git a/jhbuild/utils/cmds.py b/jhbuild/utils/cmds.py
index af96f7f5..1d9b17a5 100644
--- a/jhbuild/utils/cmds.py
+++ b/jhbuild/utils/cmds.py
@@ -259,7 +259,7 @@ def compare_version(version, minver):
 def check_version(cmd, regexp, minver, extra_env=None):
     try:
         data = get_output(cmd, extra_env=extra_env)
-    except:
+    except CommandError:
         return False
     match = re.match(regexp, data, re.MULTILINE)
     if not match:
diff --git a/jhbuild/utils/httpcache.py b/jhbuild/utils/httpcache.py
index a489630c..904d7ba7 100644
--- a/jhbuild/utils/httpcache.py
+++ b/jhbuild/utils/httpcache.py
@@ -83,7 +83,7 @@ class Cache:
         cindex = os.path.join(self.cachedir, 'index.xml')
         try:
             document = xml.dom.minidom.parse(cindex)
-        except:
+        except Exception:
             return # treat like an empty cache
         if document.documentElement.nodeName != 'cache':
             document.unlink()
@@ -197,7 +197,7 @@ class Cache:
             if response.headers.get('Content-Encoding', '') == 'gzip':
                 try:
                     data = gzip.GzipFile(fileobj=BytesIO(data)).read()
-                except:
+                except Exception:
                     data = ''
 
             expires = response.headers.get('Expires')
diff --git a/jhbuild/utils/sysid.py b/jhbuild/utils/sysid.py
index f6e1e09c..fc4390fe 100644
--- a/jhbuild/utils/sysid.py
+++ b/jhbuild/utils/sysid.py
@@ -34,10 +34,10 @@ def read_os_release():
 
     try:
         release_file = open('/etc/os-release')
-    except:
+    except EnvironmentError:
         try:
             release_file = open('/usr/lib/os-release')
-        except:
+        except EnvironmentError:
             return False
 
     fields = {}
@@ -55,7 +55,7 @@ def read_os_release():
         if value.startswith("'") or value.startswith('"'):
             try:
                 value = ast.literal_eval(value)
-            except:
+            except Exception:
                 continue
 
         fields[field] = value
@@ -91,7 +91,7 @@ def get_macos_info():
 
         return True
 
-    except:
+    except (EnvironmentError, subprocess.CalledProcessError):
         return False
 
 def get_freebsd_info():
@@ -103,7 +103,7 @@ def get_freebsd_info():
 
         sys_name = 'FreeBSD ' + ver
         return True
-    except:
+    except (EnvironmentError, subprocess.CalledProcessError):
         pass
 
     try:
@@ -111,7 +111,7 @@ def get_freebsd_info():
 
         sys_name = 'FreeBSD ' + ver
         return True
-    except:
+    except (EnvironmentError, subprocess.CalledProcessError):
         return False
 
 def ensure_loaded():
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index f7f16b0c..f2588185 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -131,7 +131,7 @@ def systemdependencies_met(module_name, sysdeps, config):
             return paths
         try:
             multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
-        except:
+        except (EnvironmentError, subprocess.CalledProcessError):
             multiarch = None
         # search /usr/include and its multiarch subdir (if any) by default
         paths = [ os.path.join(os.sep, 'usr', 'include')]
@@ -183,7 +183,7 @@ def systemdependencies_met(module_name, sysdeps, config):
         elif dep_type == 'python2':
             try:
                 imp.find_module(value)
-            except:
+            except Exception:
                 dep_met = False
 
         elif dep_type == 'python3':
@@ -212,8 +212,7 @@ def systemdependencies_met(module_name, sysdeps, config):
             try:
                 # no xmlcatalog installed will (correctly) fail the check
                 subprocess.check_output(['xmlcatalog', xml_catalog, value])
-
-            except:
+            except (EnvironmentError, subprocess.CalledProcessError):
                 dep_met = False
 
         # check alternative dependencies
@@ -273,16 +272,16 @@ class PKSystemInstall(SystemInstall):
         if self._loop is None:
             try:
                 import glib
-            except:
+            except ImportError:
                 try:
                     from gi.repository import GLib as glib
-                except:
+                except ImportError:
                     raise SystemExit(_('Error: python-gobject package not found.'))
             self._loop = glib.MainLoop()
         if self._sysbus is None:
             try:
                 import dbus.glib
-            except:
+            except ImportError:
                 raise SystemExit(_('Error: dbus-python package not found.'))
             import dbus
             self._dbus = dbus
@@ -540,7 +539,7 @@ class AptSystemInstall(SystemInstall):
         multiarch = None
         try:
             multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
-        except:
+        except (EnvironmentError, subprocess.CalledProcessError):
             # Really need GCC to continue. Yes, this is fragile.
             self._install_packages(['gcc'])
             multiarch = subprocess.check_output(['gcc', '-print-multiarch']).strip()
diff --git a/jhbuild/utils/trayicon.py b/jhbuild/utils/trayicon.py
index dba5f2a1..4e0900ee 100644
--- a/jhbuild/utils/trayicon.py
+++ b/jhbuild/utils/trayicon.py
@@ -46,7 +46,7 @@ class TrayIcon:
             for item in caps:
                 if item == "persistence":
                     return
-        except:
+        except Exception:
             pass
 
         try:
diff --git a/jhbuild/utils/unpack.py b/jhbuild/utils/unpack.py
index dea21d7c..15f74282 100644
--- a/jhbuild/utils/unpack.py
+++ b/jhbuild/utils/unpack.py
@@ -143,7 +143,7 @@ def unpack_archive(buildscript, localfile, target_directory, checkoutdir=None):
                 unpack_zip_file(localfile, target_directory)
             else:
                 raise CommandError(_('Failed to unpack %s (unknown archive type)') % localfile)
-        except:
+        except Exception:
             raise CommandError(_('Failed to unpack %s') % localfile)
 
     if checkoutdir:
diff --git a/jhbuild/versioncontrol/bzr.py b/jhbuild/versioncontrol/bzr.py
index 855aecd2..2bb05511 100644
--- a/jhbuild/versioncontrol/bzr.py
+++ b/jhbuild/versioncontrol/bzr.py
@@ -140,7 +140,7 @@ class BzrBranch(Branch):
     def branchname(self):
         try:
             return get_output(['bzr', 'nick', self.srcdir])
-        except:
+        except CommandError:
             return None
     branchname = property(branchname)
 
@@ -148,7 +148,7 @@ class BzrBranch(Branch):
         try:
             get_output(['bzr', 'ls', self.module])
             return True
-        except:
+        except CommandError:
             return False
 
     def create_mirror(self, buildscript):
@@ -174,7 +174,7 @@ class BzrBranch(Branch):
                 info = get_output(cmd, cwd=cwd)
                 if info.find('checkout of branch: %s' % self.checkoutdir) == -1:
                     raise NameError
-            except:
+            except (CommandError, NameError):
                 raise FatalError(_("""
 Path %s does not seem to be a checkout from dvcs_mirror_dir.
 Remove it or change your dvcs_mirror_dir settings.""") % self.srcdir)
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 7449cf7b..580baa1a 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -341,7 +341,7 @@ class GitBranch(Branch):
         try:
             get_output(['git', 'ls-remote', self.module],
                        extra_env=get_git_extra_env())
-        except:
+        except CommandError:
             return False
 
         # FIXME: Parse output from ls-remote to work out if tag/branch is present
@@ -373,7 +373,7 @@ class GitBranch(Branch):
                     cwd = self.get_checkoutdir(), get_stderr=False,
                     extra_env=get_git_extra_env())
             tag = output.strip()
-        except:
+        except CommandError:
             tag = 'unknown'
 
         filename = self.get_module_basename() + '-' + tag + '.zip'
@@ -621,7 +621,7 @@ class GitSvnBranch(GitBranch):
             fd.close()
             buildscript.execute(cmd, cwd=self.get_checkoutdir(copydir),
                     extra_env=get_git_extra_env())
-        except:
+        except (CommandError, EnvironmentError):
             pass
 
         # FIXME, git-svn should support externals
@@ -664,7 +664,7 @@ class GitSvnBranch(GitBranch):
                 # is known to fail on some versions
                 cmd = "git svn show-ignore >> .git/info/exclude"
                 buildscript.execute(cmd, **git_extra_args)
-            except:
+            except CommandError:
                 pass
 
         # FIXME, git-svn should support externals
diff --git a/jhbuild/versioncontrol/svn.py b/jhbuild/versioncontrol/svn.py
index 8d5d6b0b..c903f25f 100644
--- a/jhbuild/versioncontrol/svn.py
+++ b/jhbuild/versioncontrol/svn.py
@@ -209,7 +209,7 @@ class SubversionBranch(Branch):
                 'LD_LIBRARY_PATH': os.environ.get('UNMANGLED_LD_LIBRARY_PATH'),
                 })
             return True
-        except:
+        except CommandError:
             return False
 
     def _export(self, buildscript):


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