Ensure version info only gets pasted once

This commit is contained in:
George Edward Bulmer 2018-02-07 19:21:53 +00:00
parent 9128afa01d
commit 682c3462f1
2 changed files with 16 additions and 5 deletions

View File

@ -39,6 +39,7 @@ from qutebrowser.utils import log, objreg, usertypes, message, debug, utils
from qutebrowser.commands import cmdutils, runners, cmdexc
from qutebrowser.config import config, configdata
from qutebrowser.misc import consolewidget
from qutebrowser.utils.version import pastebin_version
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@ -380,4 +381,4 @@ def version(win_id, paste=False):
tabbed_browser.openurl(QUrl('qute://version'), newtab=True)
if paste:
utils.version.pastebin_version()
pastebin_version()

View File

@ -65,6 +65,7 @@ class DistributionInfo:
pretty = attr.ib()
PASTEBIN_URL = None
Distribution = enum.Enum(
'Distribution', ['unknown', 'ubuntu', 'debian', 'void', 'arch',
'gentoo', 'fedora', 'opensuse', 'linuxmint', 'manjaro'])
@ -453,22 +454,31 @@ def opengl_vendor(): # pragma: no cover
def pastebin_version():
"""Pastebin the version and log the url to messages."""
app = QApplication.instance()
http_client = httpclient.HTTPClient()
def _get_paste_title():
return "qute version info {}".format(qutebrowser.__version__)
def _on_paste_version_success(url):
def _yank_url(url):
utils.set_clipboard(url)
message.info("Version url {} yanked to clipboard.".format(url))
def _on_paste_version_success(url):
global PASTEBIN_URL
_yank_url(url)
pbclient.deleteLater()
PASTEBIN_URL = url
def _on_paste_version_err(text):
message.error("Failed to pastebin version"
" info: {}".format(text))
pbclient.deleteLater()
if PASTEBIN_URL:
_yank_url(PASTEBIN_URL)
return
app = QApplication.instance()
http_client = httpclient.HTTPClient()
misc_api = pastebin.PastebinClient.MISC_API_URL
pbclient = pastebin.PastebinClient(http_client, parent=app,
api_url=misc_api)