Merge remote-tracking branch 'origin/pr/3567'

This commit is contained in:
Florian Bruhin 2018-02-11 11:11:41 +01:00
commit ab768d6f6a
5 changed files with 76 additions and 6 deletions

View File

@ -476,3 +476,10 @@ def qute_configdiff(url):
else: else:
data = config.instance.dump_userconfig().encode('utf-8') data = config.instance.dump_userconfig().encode('utf-8')
return 'text/plain', data 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.'

View File

@ -1,4 +1,17 @@
{% extends "base.html" %} {% 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 %} {% block content %}
{{ super() }} {{ super() }}
<h1>Version info</h1> <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/"> 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>. http://www.gnu.org/licenses/</a> or open <a href="qute://gpl">qute://gpl</a>.
</p> </p>
<button id="paste" onclick="paste_version()">Yank Pastebin URL for Version Info</button>
{% endblock %} {% endblock %}

View File

@ -42,20 +42,23 @@ class PastebinClient(QObject):
""" """
API_URL = 'https://crashes.qutebrowser.org/api/' API_URL = 'https://crashes.qutebrowser.org/api/'
MISC_API_URL = 'https://paste.the-compiler.org/api/'
success = pyqtSignal(str) success = pyqtSignal(str)
error = pyqtSignal(str) error = pyqtSignal(str)
def __init__(self, client, parent=None): def __init__(self, client, parent=None, api_url=API_URL):
"""Constructor. """Constructor.
Args: Args:
client: The HTTPClient to use. Will be reparented. client: The HTTPClient to use. Will be reparented.
api_url: The Stikked pastebin endpoint to use.
""" """
super().__init__(parent) super().__init__(parent)
client.setParent(self) client.setParent(self)
client.error.connect(self.error) client.error.connect(self.error)
client.success.connect(self.on_client_success) client.success.connect(self.on_client_success)
self._client = client self._client = client
self._api_url = api_url
def paste(self, name, title, text, parent=None): def paste(self, name, title, text, parent=None):
"""Paste the text into a pastebin and return the URL. """Paste the text into a pastebin and return the URL.
@ -74,7 +77,7 @@ class PastebinClient(QObject):
} }
if parent is not None: if parent is not None:
data['reply'] = parent 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) self._client.post(url, data)
@pyqtSlot(str) @pyqtSlot(str)

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.commands import cmdutils, runners, cmdexc
from qutebrowser.config import config, configdata from qutebrowser.config import config, configdata
from qutebrowser.misc import consolewidget from qutebrowser.misc import consolewidget
from qutebrowser.utils.version import pastebin_version
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@ -369,8 +370,15 @@ def nop():
@cmdutils.register() @cmdutils.register()
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
def version(win_id): def version(win_id, paste=False):
"""Show version information.""" """Show version information.
Args:
paste: Paste to pastebin.
"""
tabbed_browser = objreg.get('tabbed-browser', scope='window', tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id) window=win_id)
tabbed_browser.openurl(QUrl('qute://version'), newtab=True) tabbed_browser.openurl(QUrl('qute://version'), newtab=True)
if paste:
pastebin_version()

View File

@ -29,6 +29,7 @@ import importlib
import collections import collections
import enum import enum
import datetime import datetime
import getpass
import attr import attr
import pkg_resources import pkg_resources
@ -49,8 +50,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
@ -65,6 +66,7 @@ class DistributionInfo:
pretty = attr.ib() pretty = attr.ib()
pastebin_url = None
Distribution = enum.Enum( Distribution = enum.Enum(
'Distribution', ['unknown', 'ubuntu', 'debian', 'void', 'arch', 'Distribution', ['unknown', 'ubuntu', 'debian', 'void', 'arch',
'gentoo', 'fedora', 'opensuse', 'linuxmint', 'manjaro']) 'gentoo', 'fedora', 'opensuse', 'linuxmint', 'manjaro'])
@ -449,3 +451,39 @@ 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."""
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())