diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 320e7873a..cca74cb63 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -476,3 +476,10 @@ def qute_configdiff(url): else: data = config.instance.dump_userconfig().encode('utf-8') return 'text/plain', data + + +@add_handler('pastebin-version') +def qute_pastebin_version(_url): + """Handler that pastebins the version string.""" + version.pastebin_version() + return 'text/plain', b'Paste called.' diff --git a/qutebrowser/html/version.html b/qutebrowser/html/version.html index 736eb7547..a69e6f9de 100644 --- a/qutebrowser/html/version.html +++ b/qutebrowser/html/version.html @@ -1,4 +1,17 @@ {% extends "base.html" %} + +{% block script %} +function paste_version() { + const xhr = new XMLHttpRequest(); + xhr.open("GET", "qute://pastebin-version"); + xhr.send(); +} +{% endblock %} + +{% block style %} +#paste { margin: auto; display: block; } +{% endblock %} + {% block content %} {{ super() }}

Version info

@@ -23,4 +36,5 @@ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/ or open qute://gpl.

+ {% endblock %} diff --git a/qutebrowser/misc/pastebin.py b/qutebrowser/misc/pastebin.py index d022fc526..0f2ed8ce4 100644 --- a/qutebrowser/misc/pastebin.py +++ b/qutebrowser/misc/pastebin.py @@ -42,20 +42,23 @@ class PastebinClient(QObject): """ API_URL = 'https://crashes.qutebrowser.org/api/' + MISC_API_URL = 'https://paste.the-compiler.org/api/' success = pyqtSignal(str) error = pyqtSignal(str) - def __init__(self, client, parent=None): + def __init__(self, client, parent=None, api_url=API_URL): """Constructor. Args: client: The HTTPClient to use. Will be reparented. + api_url: The Stikked pastebin endpoint to use. """ super().__init__(parent) client.setParent(self) client.error.connect(self.error) client.success.connect(self.on_client_success) self._client = client + self._api_url = api_url def paste(self, name, title, text, parent=None): """Paste the text into a pastebin and return the URL. @@ -74,7 +77,7 @@ class PastebinClient(QObject): } if parent is not None: data['reply'] = parent - url = QUrl(urllib.parse.urljoin(self.API_URL, 'create')) + url = QUrl(urllib.parse.urljoin(self._api_url, 'create')) self._client.post(url, data) @pyqtSlot(str) diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index c0d83b7eb..d2743d56e 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -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) @@ -369,8 +370,15 @@ def nop(): @cmdutils.register() @cmdutils.argument('win_id', win_id=True) -def version(win_id): - """Show version information.""" +def version(win_id, paste=False): + """Show version information. + + Args: + paste: Paste to pastebin. + """ tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) tabbed_browser.openurl(QUrl('qute://version'), newtab=True) + + if paste: + pastebin_version() diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index aff7ed07b..09a1a6efa 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -29,6 +29,7 @@ import importlib import collections import enum import datetime +import getpass import attr import pkg_resources @@ -49,8 +50,8 @@ except ImportError: # pragma: no cover QWebEngineProfile = None import qutebrowser -from qutebrowser.utils import log, utils, standarddir, usertypes -from qutebrowser.misc import objects, earlyinit, sql +from qutebrowser.utils import log, utils, standarddir, usertypes, message +from qutebrowser.misc import objects, earlyinit, sql, httpclient, pastebin from qutebrowser.browser import pdfjs @@ -65,6 +66,7 @@ class DistributionInfo: pretty = attr.ib() +pastebin_url = None Distribution = enum.Enum( 'Distribution', ['unknown', 'ubuntu', 'debian', 'void', 'arch', 'gentoo', 'fedora', 'opensuse', 'linuxmint', 'manjaro']) @@ -449,3 +451,39 @@ def opengl_vendor(): # pragma: no cover ctx.doneCurrent() if old_context and old_surface: old_context.makeCurrent(old_surface) + + +def pastebin_version(): + """Pastebin the version and log the url to messages.""" + 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) + + pbclient.success.connect(_on_paste_version_success) + pbclient.error.connect(_on_paste_version_err) + + pbclient.paste(getpass.getuser(), + "qute version info {}".format(qutebrowser.__version__), + version())