Move pastebin_version() to version.py

This also fixes the introduced cyclic dependencies
This commit is contained in:
George Edward Bulmer 2018-02-07 19:03:05 +00:00
parent a3d62c86df
commit 9128afa01d
4 changed files with 35 additions and 39 deletions

View File

@ -481,5 +481,5 @@ def qute_configdiff(url):
@add_handler('pastebin-version') @add_handler('pastebin-version')
def qute_pastebin_version(_url): def qute_pastebin_version(_url):
"""Handler that pastebins the version string.""" """Handler that pastebins the version string."""
utils.pastebin_version() version.pastebin_version()
return 'text/plain', b'Paste called.' return 'text/plain', b'Paste called.'

View File

@ -380,4 +380,4 @@ def version(win_id, paste=False):
tabbed_browser.openurl(QUrl('qute://version'), newtab=True) tabbed_browser.openurl(QUrl('qute://version'), newtab=True)
if paste: if paste:
utils.pastebin_version() utils.version.pastebin_version()

View File

@ -36,7 +36,7 @@ import shlex
import getpass import getpass
import attr import attr
from PyQt5.QtCore import Qt, QUrl, pyqtSlot from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QKeySequence, QColor, QClipboard, QDesktopServices from PyQt5.QtGui import QKeySequence, QColor, QClipboard, QDesktopServices
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
import pkg_resources import pkg_resources
@ -49,9 +49,7 @@ except ImportError: # pragma: no cover
YAML_C_EXT = False YAML_C_EXT = False
import qutebrowser import qutebrowser
from qutebrowser.utils import qtutils, log, debug, message, version from qutebrowser.utils import qtutils, log, debug
from qutebrowser.misc import httpclient, pastebin
fake_clipboard = None fake_clipboard = None
log_clipboard = False log_clipboard = False
@ -917,34 +915,3 @@ def yaml_dump(data, f=None):
return None return None
else: else:
return yaml_data.decode('utf-8') return yaml_data.decode('utf-8')
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__)
@pyqtSlot(str)
def _on_paste_version_success(url):
set_clipboard(url)
message.info("Version url {} yanked to clipboard.".format(url))
pbclient.deleteLater()
@pyqtSlot(str)
def _on_paste_version_err(text):
message.error("Failed to pastebin version"
" info: {}".format(text))
pbclient.deleteLater()
misc_api = pastebin.PastebinClient.MISC_API_URL
pbclient = pastebin.PastebinClient(http_client, parent=app,
api_url=misc_api)
pbclient.success.connect(_on_paste_version_success)
pbclient.error.connect(_on_paste_version_err)
pbclient.paste(getpass.getuser(), _get_paste_title(),
version.version())

View File

@ -49,8 +49,8 @@ except ImportError: # pragma: no cover
QWebEngineProfile = None QWebEngineProfile = None
import qutebrowser import qutebrowser
from qutebrowser.utils import log, utils, standarddir, usertypes from qutebrowser.utils import log, utils, standarddir, usertypes, message
from qutebrowser.misc import objects, earlyinit, sql from qutebrowser.misc import objects, earlyinit, sql, httpclient, pastebin
from qutebrowser.browser import pdfjs from qutebrowser.browser import pdfjs
@ -449,3 +449,32 @@ def opengl_vendor(): # pragma: no cover
ctx.doneCurrent() ctx.doneCurrent()
if old_context and old_surface: if old_context and old_surface:
old_context.makeCurrent(old_surface) old_context.makeCurrent(old_surface)
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):
utils.set_clipboard(url)
message.info("Version url {} yanked to clipboard.".format(url))
pbclient.deleteLater()
def _on_paste_version_err(text):
message.error("Failed to pastebin version"
" info: {}".format(text))
pbclient.deleteLater()
misc_api = pastebin.PastebinClient.MISC_API_URL
pbclient = pastebin.PastebinClient(http_client, parent=app,
api_url=misc_api)
pbclient.success.connect(_on_paste_version_success)
pbclient.error.connect(_on_paste_version_err)
pbclient.paste(utils.getpass.getuser(), _get_paste_title(),
version())