Fix lints/bugs

This commit is contained in:
Florian Bruhin 2014-09-29 20:36:53 +02:00
parent 686f82c5c6
commit 6aeecb3803
4 changed files with 18 additions and 24 deletions

View File

@ -250,7 +250,7 @@ class Application(QApplication):
url = urlutils.fuzzy_url(urlstr) url = urlutils.fuzzy_url(urlstr)
except urlutils.FuzzyUrlError as e: except urlutils.FuzzyUrlError as e:
message.error(0, "Error when opening startpage: " message.error(0, "Error when opening startpage: "
"{}".format(e)) "{}".format(e))
tabbed_browser.tabopen(QUrl('about:blank')) tabbed_browser.tabopen(QUrl('about:blank'))
else: else:
tabbed_browser.tabopen(url) tabbed_browser.tabopen(url)
@ -319,11 +319,14 @@ class Application(QApplication):
output += self._get_registered_objects() output += self._get_registered_objects()
return '\n'.join(output) return '\n'.join(output)
def _recover_pages(self): def _recover_pages(self, forgiving=False):
"""Try to recover all open pages. """Try to recover all open pages.
Called from _exception_hook, so as forgiving as possible. Called from _exception_hook, so as forgiving as possible.
Args:
forgiving: Whether to ignore exceptions.
Return: Return:
A list of open pages, or an empty list. A list of open pages, or an empty list.
""" """
@ -333,12 +336,15 @@ class Application(QApplication):
window=win_id) window=win_id)
for tab in tabbed_browser.widgets(): for tab in tabbed_browser.widgets():
try: try:
url = tab.cur_url.toString( urlstr = tab.cur_url.toString(
QUrl.RemovePassword | QUrl.FullyEncoded) QUrl.RemovePassword | QUrl.FullyEncoded)
if url: if urlstr:
pages.append(url) pages.append(urlstr)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
log.destroy.exception("Error while recovering tab") if forgiving:
log.destroy.exception("Error while recovering tab")
else:
raise
return pages return pages
def _save_geometry(self): def _save_geometry(self):
@ -396,7 +402,7 @@ class Application(QApplication):
self._quit_status['crash'] = False self._quit_status['crash'] = False
try: try:
pages = self._recover_pages() pages = self._recover_pages(forgiving=True)
except Exception: except Exception:
log.destroy.exception("Error while recovering pages") log.destroy.exception("Error while recovering pages")
pages = [] pages = []
@ -438,19 +444,9 @@ class Application(QApplication):
@cmdutils.register(instance='app', ignore_args=True) @cmdutils.register(instance='app', ignore_args=True)
def restart(self, shutdown=True, pages=None): def restart(self, shutdown=True, pages=None):
"""Restart qutebrowser while keeping existing tabs open.""" """Restart qutebrowser while keeping existing tabs open."""
# We don't use _recover_pages here as it's too forgiving when
# exceptions occur.
# FIXME handle multiple windows correctly here # FIXME handle multiple windows correctly here
if pages is None: if pages is None:
pages = [] pages = self._recover_pages()
for win_id in objreg.window_registry:
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
for tab in tabbed_browser.widgets():
urlstr = tab.cur_url.toString(
QUrl.RemovePassword | QUrl.FullyEncoded)
if urlstr:
pages.append(urlstr)
log.destroy.debug("sys.executable: {}".format(sys.executable)) log.destroy.debug("sys.executable: {}".format(sys.executable))
log.destroy.debug("sys.path: {}".format(sys.path)) log.destroy.debug("sys.path: {}".format(sys.path))
log.destroy.debug("sys.argv: {}".format(sys.argv)) log.destroy.debug("sys.argv: {}".format(sys.argv))

View File

@ -23,12 +23,11 @@ import os
import os.path import os.path
import tempfile import tempfile
import select import select
import functools
from PyQt5.QtCore import (pyqtSignal, QObject, QThread, QStandardPaths, from PyQt5.QtCore import (pyqtSignal, QObject, QThread, QStandardPaths,
QProcessEnvironment, QProcess, QUrl) QProcessEnvironment, QProcess, QUrl)
from qutebrowser.utils import message, log, utils from qutebrowser.utils import message, log, utils, objreg
from qutebrowser.commands import runners, cmdexc from qutebrowser.commands import runners, cmdexc

View File

@ -87,7 +87,6 @@ class ObjectRegistry(collections.UserDict):
except KeyError: except KeyError:
pass pass
def dump_objects(self): def dump_objects(self):
"""Dump all objects as a list of strings.""" """Dump all objects as a list of strings."""
lines = [] lines = []

View File

@ -25,7 +25,7 @@ import types
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from qutebrowser.utils import log, objreg, usertypes from qutebrowser.utils import log, objreg, usertypes
from qutebrowser.commands import cmdutils, runners from qutebrowser.commands import cmdutils, runners, cmdexc
from qutebrowser.config import style from qutebrowser.config import style
@ -45,8 +45,8 @@ def later(ms: int, *command, win_id):
try: try:
timer.setInterval(ms) timer.setInterval(ms)
except OverflowError: except OverflowError:
raise cmdexc.CommandError("Numeric argument is too large for " raise cmdexc.CommandError("Numeric argument is too large for internal "
"internal int representation.") "int representation.")
cmdline = ' '.join(command) cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id) commandrunner = runners.CommandRunner(win_id)
timer.timeout.connect( timer.timeout.connect(