Merge remote-tracking branch 'origin/pr/3567'
This commit is contained in:
commit
ab768d6f6a
@ -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.'
|
||||
|
@ -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() }}
|
||||
<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()">Yank Pastebin URL for Version Info</button>
|
||||
{% endblock %}
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user