From 58f031630c6b04c0178f268bf5ad3803455d0c31 Mon Sep 17 00:00:00 2001 From: Lamar Pavel Date: Fri, 22 May 2015 14:44:04 +0200 Subject: [PATCH] user-stylesheet can be read from relative paths This ist just a first draft to approach issue622 (https://github.com/The-Compiler/qutebrowser/issues/622) and my very first babysteps with python. With this change it is possible to set a user-stylesheet with a relative path, eg.: :set ui user-stylesheet mystyle.css where mystyle.css is in the ~/.config/qutebrowser/. --- .gitignore | 2 ++ qutebrowser/config/configtypes.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.gitignore b/.gitignore index f3ff3652a..9552dc3c4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ __pycache__ /htmlcov /.tox /testresults.html +tags +*.swp diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index b9c760116..354c09598 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -34,6 +34,7 @@ from PyQt5.QtWidgets import QTabWidget, QTabBar from qutebrowser.commands import cmdutils from qutebrowser.config import configexc +from qutebrowser.utils import standarddir SYSTEM_PROXY = object() # Return value for Proxy type @@ -792,6 +793,9 @@ class RegexList(List): raise configexc.ValidationError(value, "items may not be empty!") +# TODO(lamar) Issue622, relative paths for some config files and directories +# should be implemented here in the base class for files and below in the base +# class for directories. class File(BaseType): """A file on the local filesystem.""" @@ -806,6 +810,10 @@ class File(BaseType): raise configexc.ValidationError(value, "may not be empty!") value = os.path.expanduser(value) try: + if not os.path.isabs(value): + relpath = os.path.join(standarddir.config(), value) + if os.path.isfile(relpath): + value = relpath if not os.path.isfile(value): raise configexc.ValidationError(value, "must be a valid file!") if not os.path.isabs(value): @@ -1160,6 +1168,10 @@ class UserStyleSheet(File): value = os.path.expandvars(value) value = os.path.expanduser(value) try: + if not os.path.isabs(value): + relpath = os.path.join(standarddir.config(), value) + if os.path.isfile(relpath): + value = relpath if not os.path.isabs(value): # probably a CSS, so we don't handle it as filename. # FIXME We just try if it is encodable, maybe we should