Hide webbrowser output
On my terminal, opening a web browser link always produces the output "GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed" This is apparently a bug in mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=833117 However, the python webbrowser module could mask it by redirecting outputs. In fact, it does so for some types of browsers, but apparently not xdg-open. Create a new webbrowser subclass that redirects output and register it as the appropriate way to use xdg-open so that the message is hidden. Change-Id: I018673a2773a3bc21d7d7c1facccba91eafe1174
This commit is contained in:
parent
b10441866a
commit
db9b6407b6
@ -17,6 +17,7 @@ import argparse
|
||||
import logging
|
||||
import os
|
||||
import Queue
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import webbrowser
|
||||
@ -128,6 +129,30 @@ class SearchDialog(mywid.ButtonDialog):
|
||||
return None
|
||||
return r
|
||||
|
||||
# From: cpython/file/2.7/Lib/webbrowser.py with modification to
|
||||
# redirect stdin/out/err.
|
||||
class BackgroundBrowser(webbrowser.GenericBrowser):
|
||||
"""Class for all browsers which are to be started in the
|
||||
background."""
|
||||
|
||||
def open(self, url, new=0, autoraise=True):
|
||||
cmdline = [self.name] + [arg.replace("%s", url)
|
||||
for arg in self.args]
|
||||
inout = file(os.devnull, "r+")
|
||||
try:
|
||||
if sys.platform[:3] == 'win':
|
||||
p = subprocess.Popen(cmdline)
|
||||
else:
|
||||
setsid = getattr(os, 'setsid', None)
|
||||
if not setsid:
|
||||
setsid = getattr(os, 'setpgrp', None)
|
||||
p = subprocess.Popen(cmdline, close_fds=True,
|
||||
stdin=inout, stdout=inout,
|
||||
stderr=inout, preexec_fn=setsid)
|
||||
return (p.poll() is None)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
class App(object):
|
||||
def __init__(self, server=None, palette='default', keymap='default',
|
||||
debug=False, verbose=False, disable_sync=False,
|
||||
@ -157,6 +182,8 @@ class App(object):
|
||||
self.log = logging.getLogger('gertty.App')
|
||||
self.log.debug("Starting")
|
||||
|
||||
webbrowser.register('xdg-open', None, BackgroundBrowser("xdg-open"))
|
||||
|
||||
self.fetch_missing_refs = fetch_missing_refs
|
||||
self.config.keymap.updateCommandMap()
|
||||
self.search = search.SearchCompiler(self)
|
||||
|
Loading…
Reference in New Issue
Block a user