summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.asciidoc4
-rw-r--r--qutebrowser/utils/version.py2
-rwxr-xr-xscripts/asciidoc2html.py11
-rwxr-xr-xscripts/dev/build_release.py4
-rwxr-xr-xscripts/dictcli.py9
-rw-r--r--scripts/mkvenv.py23
-rw-r--r--scripts/utils.py11
-rw-r--r--tests/unit/mainwindow/test_messageview.py2
-rw-r--r--tests/unit/utils/test_version.py9
9 files changed, 50 insertions, 25 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index 94623ce0a..bbb166eeb 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -60,6 +60,10 @@ Fixed
match the original Greasemonkey implementation.
- The `--output-messages` (`-m`) flag added in v1.9.0 now also works correctly
when using `:spawn --userscript`.
+- `:version` and `--version` now don't crash if there's an (invalid)
+ `/etc/os-release` file which has non-comment lines without a `=` character.
+- Scripts in `scripts/` now report errors to `stderr` correctly, instead of
+ using `stdout`.
v1.10.2 (2020-04-17)
--------------------
diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py
index 1a870f572..d10c57411 100644
--- a/qutebrowser/utils/version.py
+++ b/qutebrowser/utils/version.py
@@ -90,7 +90,7 @@ def distribution() -> typing.Optional[DistributionInfo]:
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
- if (not line) or line.startswith('#'):
+ if (not line) or line.startswith('#') or '=' not in line:
continue
k, v = line.split("=", maxsplit=1)
info[k] = v.strip('"')
diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py
index ceac1ff41..d43531ca3 100755
--- a/scripts/asciidoc2html.py
+++ b/scripts/asciidoc2html.py
@@ -263,8 +263,9 @@ class AsciiDoc:
subprocess.run(cmdline, check=True, env=env)
except (subprocess.CalledProcessError, OSError) as e:
self._failed = True
- utils.print_col(str(e), 'red')
- print("Keeping modified sources in {}.".format(self._homedir))
+ utils.print_error(str(e))
+ print("Keeping modified sources in {}.".format(self._homedir),
+ file=sys.stderr)
sys.exit(1)
@@ -291,9 +292,9 @@ def run(**kwargs):
try:
asciidoc.prepare()
except FileNotFoundError:
- utils.print_col("Could not find asciidoc! Please install it, or use "
- "the --asciidoc argument to point this script to the "
- "correct python/asciidoc.py location!", 'red')
+ utils.print_error("Could not find asciidoc! Please install it, or use "
+ "the --asciidoc argument to point this script to "
+ "the correct python/asciidoc.py location!")
sys.exit(1)
try:
diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py
index 5167c60aa..68befff65 100755
--- a/scripts/dev/build_release.py
+++ b/scripts/dev/build_release.py
@@ -423,8 +423,8 @@ def github_upload(artifacts, tag):
with open(filename, 'rb') as f:
release.upload_asset(mimetype, basename, f, description)
except github3.exceptions.ConnectionError as e:
- utils.print_col('Failed to upload: {}'.format(e), 'red')
- print("Press Enter to retry...")
+ utils.print_error('Failed to upload: {}'.format(e))
+ print("Press Enter to retry...", file=sys.stderr)
input()
print("Retrying!")
diff --git a/scripts/dictcli.py b/scripts/dictcli.py
index 3676506e1..ebe4e285c 100755
--- a/scripts/dictcli.py
+++ b/scripts/dictcli.py
@@ -38,6 +38,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
from qutebrowser.browser.webengine import spell
from qutebrowser.config import configdata
from qutebrowser.utils import standarddir, utils
+from scripts import utils as scriptutils
API_URL = 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git/+/master/'
@@ -219,7 +220,13 @@ def install(languages):
print('Installing {}: {}'.format(lang.code, lang.name))
install_lang(lang)
except PermissionError as e:
- sys.exit(str(e))
+ msg = ("\n{}\n\nWith Qt < 5.10, you will need to run this script "
+ "as root, as dictionaries need to be installed "
+ "system-wide. If your qutebrowser uses a newer Qt version "
+ "via a virtualenv, make sure you start this script with "
+ "the virtualenv's Python.".format(e))
+ scriptutils.print_error(msg)
+ sys.exit(1)
def update(languages):
diff --git a/scripts/mkvenv.py b/scripts/mkvenv.py
index 3d2079435..04cf0e8c0 100644
--- a/scripts/mkvenv.py
+++ b/scripts/mkvenv.py
@@ -101,7 +101,7 @@ def run_venv(venv_dir: pathlib.Path, executable, *args: str) -> None:
subprocess.run([str(venv_dir / subdir / executable)] +
[str(arg) for arg in args], check=True)
except subprocess.CalledProcessError as e:
- utils.print_col("Subprocess failed, exiting", 'red')
+ utils.print_error("Subprocess failed, exiting")
sys.exit(e.returncode)
@@ -124,9 +124,9 @@ def show_tox_error(pyqt_type: str) -> None:
raise AssertionError
print()
- utils.print_col('tox -e {} is deprecated. '
- 'Please use "python3 scripts/mkvenv.py{}" instead.'
- .format(env, args), 'red')
+ utils.print_error('tox -e {} is deprecated. '
+ 'Please use "python3 scripts/mkvenv.py{}" instead.'
+ .format(env, args))
print()
@@ -143,9 +143,8 @@ def delete_old_venv(venv_dir: pathlib.Path) -> None:
]
if not any(m.exists() for m in markers):
- utils.print_col('{} does not look like a virtualenv, '
- 'cowardly refusing to remove it.'.format(venv_dir),
- 'red')
+ utils.print_error('{} does not look like a virtualenv, '
+ 'cowardly refusing to remove it.'.format(venv_dir))
sys.exit(1)
utils.print_col('$ rm -r {}'.format(venv_dir), 'blue')
@@ -160,7 +159,7 @@ def create_venv(venv_dir: pathlib.Path, use_virtualenv: bool = False) -> None:
subprocess.run([sys.executable, '-m', 'virtualenv', venv_dir],
check=True)
except subprocess.CalledProcessError as e:
- utils.print_col("virtualenv failed, exiting", 'red')
+ utils.print_error("virtualenv failed, exiting")
sys.exit(e.returncode)
else:
utils.print_col('$ python3 -m venv {}'.format(venv_dir), 'blue')
@@ -269,12 +268,12 @@ def main() -> None:
sys.exit(1)
elif (args.pyqt_version != 'auto' and
args.pyqt_type not in ['binary', 'source']):
- utils.print_col('The --pyqt-version option is only available when '
- 'installing PyQt from binary or source', 'red')
+ utils.print_error('The --pyqt-version option is only available when '
+ 'installing PyQt from binary or source')
sys.exit(1)
elif args.pyqt_wheels_dir != 'wheels' and args.pyqt_type != 'wheels':
- utils.print_col('The --pyqt-wheels-dir option is only available when '
- 'installing PyQt from wheels', 'red')
+ utils.print_error('The --pyqt-wheels-dir option is only available '
+ 'when installing PyQt from wheels')
sys.exit(1)
if not args.keep:
diff --git a/scripts/utils.py b/scripts/utils.py
index 0d405c8a6..bdf3f96fc 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -21,6 +21,7 @@
import os
import os.path
+import sys
# Import side-effects are an evil thing, but here it's okay so scripts using
@@ -58,14 +59,18 @@ def _esc(code):
return '\033[{}m'.format(code)
-def print_col(text, color):
+def print_col(text, color, file=sys.stdout):
"""Print a colorized text."""
if use_color:
fg = _esc(fg_colors[color.lower()])
reset = _esc(fg_colors['reset'])
- print(''.join([fg, text, reset]))
+ print(''.join([fg, text, reset]), file=file)
else:
- print(text)
+ print(text, file=file)
+
+
+def print_error(text):
+ print_col(text, 'red', file=sys.stderr)
def print_title(text):
diff --git a/tests/unit/mainwindow/test_messageview.py b/tests/unit/mainwindow/test_messageview.py
index 68d3b2c56..8691bf07f 100644
--- a/tests/unit/mainwindow/test_messageview.py
+++ b/tests/unit/mainwindow/test_messageview.py
@@ -36,7 +36,7 @@ def view(qtbot, config_stub):
usertypes.MessageLevel.warning,
usertypes.MessageLevel.error])
def test_single_message(qtbot, view, level):
- with qtbot.waitExposed(view):
+ with qtbot.waitExposed(view, timeout=5000):
view.show_message(level, 'test')
assert view._messages[0].isVisible()
diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py
index 42a6332e2..0a3c5e4aa 100644
--- a/tests/unit/utils/test_version.py
+++ b/tests/unit/utils/test_version.py
@@ -196,6 +196,15 @@ from qutebrowser.browser import pdfjs
version.DistributionInfo(
id='tux', parsed=version.Distribution.unknown,
version=None, pretty='Tux')),
+ # Invalid multi-line value
+ ("""
+ ID=tux
+ PRETTY_NAME="Multiline
+ Text"
+ """,
+ version.DistributionInfo(
+ id='tux', parsed=version.Distribution.unknown,
+ version=None, pretty='Multiline')),
])
def test_distribution(tmpdir, monkeypatch, os_release, expected):
os_release_file = tmpdir / 'os-release'