Add feature to pastebin version string

Added a --paste flag to the :version command and a JS button with corresponding qutescheme URL in the Version debug page to enable pastebinning version.
This commit is contained in:
Bryan Kok 2018-01-11 05:59:42 +08:00 committed by George Edward Bulmer
parent e874db9ce3
commit 1d568a5cf4
5 changed files with 62 additions and 4 deletions

View File

@ -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): # transfusion: pylint: disable=unused-argument
"""Handler that pastebins the version string."""
utils.pastebin_version()
return 'text/plain', b'Paste called.'

View File

@ -1,4 +1,17 @@
{% extends "base.html" %}
{% block script %}
var paste_version = function(){
xhr = new XMLHttpRequest();
xhr.open("GET", "qute://pastebin-version");
xhr.send();
}
{% endblock %}
{% block style %}
#paste { margin: auto; display: block; }
{% endblock %}
{% block content %}
{{ super() }}
<h1>Version info</h1>
@ -23,4 +36,5 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <a href="http://www.gnu.org/licenses/">
http://www.gnu.org/licenses/</a> or open <a href="qute://gpl">qute://gpl</a>.
</p>
<button id="paste" onclick="paste_version()">Pastebin Version Info</button>
{% endblock %}

View File

@ -42,20 +42,23 @@ class PastebinClient(QObject):
"""
API_URL = 'https://crashes.qutebrowser.org/api/'
MISC_API_URL = 'http://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)

View File

@ -369,8 +369,11 @@ def nop():
@cmdutils.register()
@cmdutils.argument('win_id', win_id=True)
def version(win_id):
def version(win_id, paste=False):
"""Show version information."""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
tabbed_browser.openurl(QUrl('qute://version'), newtab=True)
if paste:
utils.pastebin_version()

View File

@ -33,9 +33,10 @@ import functools
import contextlib
import socket
import shlex
import getpass
import attr
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtCore import Qt, QUrl, pyqtSlot
from PyQt5.QtGui import QKeySequence, QColor, QClipboard, QDesktopServices
from PyQt5.QtWidgets import QApplication
import pkg_resources
@ -49,6 +50,7 @@ except ImportError: # pragma: no cover
import qutebrowser
from qutebrowser.utils import qtutils, log, debug
from qutebrowser.misc import httpclient, pastebin
fake_clipboard = None
@ -915,3 +917,32 @@ def yaml_dump(data, f=None):
return None
else:
return yaml_data.decode('utf-8')
def pastebin_version():
"""Pastebins version and logs to messages"""
app = qutebrowser.utils.objreg.get('app')
http_client = httpclient.HTTPClient()
def _get_paste_title():
return "qute version info {}".format(qutebrowser.__version__)
@pyqtSlot(str)
def _on_paste_version_success(url):
qutebrowser.utils.message.info("Version info pastebinned"
" to: {}".format(url))
@pyqtSlot(str)
def _on_paste_version_err(text):
qutebrowser.utils.message.info("Failed to pastebin version"
" info: {}".format(text))
pbclient = pastebin.PastebinClient(http_client, parent=app,
api_url=
pastebin.PastebinClient.MISC_API_URL)
pbclient.success.connect(_on_paste_version_success)
pbclient.error.connect(_on_paste_version_err)
pbclient.paste(getpass.getuser(), _get_paste_title(),
qutebrowser.utils.version.version())