From 65353773d1c957f3a11ee937d23880c39aa10668 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 Jun 2014 06:43:52 +0200 Subject: [PATCH 1/3] First fix for :restart --- qutebrowser/app.py | 60 ++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 066f1151b..edcd39db2 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -21,6 +21,7 @@ import os import sys +import subprocess import faulthandler import configparser from bdb import BdbQuit @@ -84,7 +85,6 @@ class Application(QApplication): _timers: List of used QTimers so they don't get GCed. _shutting_down: True if we're currently shutting down. _quit_status: The current quitting status. - _opened_urls: List of opened URLs, string as passed to the application. _crashdlg: The crash dialog currently open. _crashlogfile: A file handler to the fatal crash logfile. """ @@ -109,7 +109,6 @@ class Application(QApplication): 'main': False, } self._timers = [] - self._opened_urls = [] self._shutting_down = False self._keyparsers = None self._crashdlg = None @@ -312,7 +311,6 @@ class Application(QApplication): self.commandmanager.run_safely_init(cmd.lstrip(':')) else: log.init.debug("Startup URL {}".format(cmd)) - self._opened_urls.append(cmd) try: url = urlutils.fuzzy_url(cmd) except urlutils.FuzzyUrlError as e: @@ -582,32 +580,36 @@ class Application(QApplication): log.destroy.debug("maybe_quit quitting.") self.quit() - #@cmdutils.register(instance='', nargs=0) - #def restart(self, shutdown=True, pages=None): - # """Restart qutebrowser while keeping existing tabs open.""" - # # We don't use _recover_pages here as it's too forgiving when - # # exceptions occur. - # if pages is None: - # pages = [] - # for tab in self.mainwindow.tabs.widgets: - # urlstr = tab.url().toString() - # if urlstr: - # pages.append(urlstr) - # pythonpath = os.pathsep.join(sys.path) - # os.environ['PYTHONPATH'] = pythonpath - # argv = sys.argv[:] - # for page in self._opened_urls: - # try: - # argv.remove(page) - # except ValueError as e: - # logger.destroy.debug("Error while removing page: {}: " - # "{}".format(e.__class__.__name__, e)) - # argv = [sys.executable] + argv + pages - # log.procs.debug("Running {} with args {} (PYTHONPATH={})".format( - # sys.executable, argv, pythonpath)) - # subprocess.Popen(argv) - # if shutdown: - # self.shutdown() + @cmdutils.register(instance='', nargs=0) + def restart(self, shutdown=True, pages=None): + """Restart qutebrowser while keeping existing tabs open.""" + # We don't use _recover_pages here as it's too forgiving when + # exceptions occur. + if pages is None: + pages = [] + for tab in self.mainwindow.tabs.widgets: + urlstr = tab.url().toString() + if urlstr: + pages.append(urlstr) + path = os.path.join(os.path.abspath(os.path.dirname( + qutebrowser.__file__)), '..') + log.destroy.debug("path: {}".format(path)) + log.destroy.debug("sys.executable: {}".format(sys.executable)) + log.destroy.debug("sys.path: {}".format(sys.path)) + log.destroy.debug("sys.argv: {}".format(sys.argv)) + log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen'))) + args = [sys.executable, '-m', 'qutebrowser'] + for arg in sys.argv[1:]: + if arg.startswith('-'): + # We only want to preserve options on a restart. + args.append(arg) + # Add all open pages so they get reopened. + args += pages + log.destroy.debug("final args: {}".format(args)) + # Open a new process and immediately shutdown the existing one + subprocess.Popen(args, cwd=path) + if shutdown: + self.shutdown() @cmdutils.register(instance='', split=False, debug=True) def debug_pyeval(self, s): From f3f04b6f21b47ccd2e84e88e44d14a1f08cd568f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 Jun 2014 06:52:49 +0200 Subject: [PATCH 2/3] Make restart work when frozen --- qutebrowser/app.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index edcd39db2..fd5b87ab9 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -591,23 +591,27 @@ class Application(QApplication): urlstr = tab.url().toString() if urlstr: pages.append(urlstr) - path = os.path.join(os.path.abspath(os.path.dirname( - qutebrowser.__file__)), '..') - log.destroy.debug("path: {}".format(path)) log.destroy.debug("sys.executable: {}".format(sys.executable)) log.destroy.debug("sys.path: {}".format(sys.path)) log.destroy.debug("sys.argv: {}".format(sys.argv)) log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen'))) - args = [sys.executable, '-m', 'qutebrowser'] + if hasattr(sys, 'frozen'): + args = [sys.executable] + cwd = os.path.abspath(os.path.dirname(sys.executable)) + else: + args = [sys.executable, '-m', 'qutebrowser'] + cwd = os.path.join(os.path.abspath(os.path.dirname( + qutebrowser.__file__)), '..') for arg in sys.argv[1:]: if arg.startswith('-'): # We only want to preserve options on a restart. args.append(arg) # Add all open pages so they get reopened. args += pages - log.destroy.debug("final args: {}".format(args)) + log.destroy.debug("args: {}".format(args)) + log.destroy.debug("cwd: {}".format(cwd)) # Open a new process and immediately shutdown the existing one - subprocess.Popen(args, cwd=path) + subprocess.Popen(args, cwd=cwd) if shutdown: self.shutdown() From b857f0bb06747fb1db6ca8a7204617769da36b5e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 24 Jun 2014 07:10:59 +0200 Subject: [PATCH 3/3] Update BUGS --- doc/BUGS | 6 ------ 1 file changed, 6 deletions(-) diff --git a/doc/BUGS b/doc/BUGS index 2e758abcf..b08de673c 100644 --- a/doc/BUGS +++ b/doc/BUGS @@ -34,12 +34,6 @@ Bugs - restart sometimes abort()s on QApplication __init__ (V155) -- restart is broken entirely since init refactoring (around af19e6d~1) - this - also breaks "restore tabs" in crash dialog. - -- qutebrowser :restart loops endlessly - We should refuse to do :restart when executing init commands - - Super key shows up as ៀ\udc53 in logs - Funky font rendering with tewi: