Merge branch 'Ram-Z-expandvars'
This commit is contained in:
commit
1268cbecf3
@ -146,6 +146,7 @@ Contributors, sorted by the number of commits in descending order:
|
||||
* Larry Hynes
|
||||
* Thorsten Wißmann
|
||||
* Thiago Barroso Perrotta
|
||||
* Samir Benmendil
|
||||
* Matthias Lisin
|
||||
* Helen Sherwood-Taylor
|
||||
* HalosGhost
|
||||
|
@ -34,7 +34,7 @@
|
||||
|<<ui-display-statusbar-messages,display-statusbar-messages>>|Whether to display javascript statusbar messages.
|
||||
|<<ui-zoom-text-only,zoom-text-only>>|Whether the zoom factor on a frame applies only to the text or to all content.
|
||||
|<<ui-frame-flattening,frame-flattening>>|Whether to expand each subframe to its contents.
|
||||
|<<ui-user-stylesheet,user-stylesheet>>|User stylesheet to use (absolute filename or CSS string).
|
||||
|<<ui-user-stylesheet,user-stylesheet>>|User stylesheet to use (absolute filename or CSS string). Will expand environment variables.
|
||||
|<<ui-css-media-type,css-media-type>>|Set the CSS media type.
|
||||
|<<ui-remove-finished-downloads,remove-finished-downloads>>|Whether to remove finished downloads automatically.
|
||||
|<<ui-hide-statusbar,hide-statusbar>>|Whether to hide the statusbar unless a message is shown.
|
||||
@ -105,7 +105,7 @@
|
||||
[options="header",width="75%",cols="25%,75%"]
|
||||
|==============
|
||||
|Setting|Description
|
||||
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default.
|
||||
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
||||
|<<storage-maximum-pages-in-cache,maximum-pages-in-cache>>|The maximum number of pages to hold in the memory page cache.
|
||||
|<<storage-object-cache-capacities,object-cache-capacities>>|The capacities for the memory cache for dead objects such as stylesheets or scripts. Syntax: cacheMinDeadCapacity, cacheMaxDead, totalCapacity.
|
||||
|<<storage-offline-storage-default-quota,offline-storage-default-quota>>|Default quota for new offline storage databases.
|
||||
@ -471,7 +471,7 @@ Default: +pass:[false]+
|
||||
|
||||
[[ui-user-stylesheet]]
|
||||
=== user-stylesheet
|
||||
User stylesheet to use (absolute filename or CSS string).
|
||||
User stylesheet to use (absolute filename or CSS string). Will expand environment variables.
|
||||
|
||||
Default: +pass:[::-webkit-scrollbar { width: 0px; height: 0px; }]+
|
||||
|
||||
@ -907,7 +907,7 @@ Settings related to cache and storage.
|
||||
|
||||
[[storage-download-directory]]
|
||||
=== download-directory
|
||||
The directory to save downloads to. An empty value selects a sensible os-specific default.
|
||||
The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
||||
|
||||
Default: empty
|
||||
|
||||
|
@ -51,6 +51,10 @@ FIRST_COMMENT = r"""
|
||||
# Interpolation looks like ${value} or ${section:value} and will be
|
||||
# replaced by the respective value.
|
||||
#
|
||||
# Some settings will expand environment variables. Note that, since
|
||||
# interpolation is run first, you will need to escape the $ char as
|
||||
# described below.
|
||||
#
|
||||
# This is the default config, so if you want to remove anything from
|
||||
# here (as opposed to change/add), for example a keybinding, set it to
|
||||
# an empty value.
|
||||
@ -235,7 +239,8 @@ DATA = collections.OrderedDict([
|
||||
('user-stylesheet',
|
||||
SettingValue(typ.UserStyleSheet(),
|
||||
'::-webkit-scrollbar { width: 0px; height: 0px; }'),
|
||||
"User stylesheet to use (absolute filename or CSS string)."),
|
||||
"User stylesheet to use (absolute filename or CSS string). Will "
|
||||
"expand environment variables."),
|
||||
|
||||
('css-media-type',
|
||||
SettingValue(typ.String(none_ok=True), ''),
|
||||
@ -444,7 +449,7 @@ DATA = collections.OrderedDict([
|
||||
('download-directory',
|
||||
SettingValue(typ.Directory(none_ok=True), ''),
|
||||
"The directory to save downloads to. An empty value selects a "
|
||||
"sensible os-specific default."),
|
||||
"sensible os-specific default. Will expand environment variables."),
|
||||
|
||||
('maximum-pages-in-cache',
|
||||
SettingValue(
|
||||
|
@ -837,6 +837,7 @@ class Directory(BaseType):
|
||||
return
|
||||
else:
|
||||
raise configexc.ValidationError(value, "may not be empty!")
|
||||
value = os.path.expandvars(value)
|
||||
value = os.path.expanduser(value)
|
||||
if not os.path.isdir(value):
|
||||
raise configexc.ValidationError(value, "must be a valid "
|
||||
@ -847,6 +848,7 @@ class Directory(BaseType):
|
||||
def transform(self, value):
|
||||
if not value:
|
||||
return None
|
||||
value = os.path.expandvars(value)
|
||||
return os.path.expanduser(value)
|
||||
|
||||
|
||||
@ -1132,6 +1134,7 @@ class UserStyleSheet(File):
|
||||
return
|
||||
else:
|
||||
raise configexc.ValidationError(value, "may not be empty!")
|
||||
value = os.path.expandvars(value)
|
||||
value = os.path.expanduser(value)
|
||||
if not os.path.isabs(value):
|
||||
# probably a CSS, so we don't handle it as filename.
|
||||
@ -1147,7 +1150,8 @@ class UserStyleSheet(File):
|
||||
raise configexc.ValidationError(value, "must be a valid file!")
|
||||
|
||||
def transform(self, value):
|
||||
path = os.path.expanduser(value)
|
||||
path = os.path.expandvars(value)
|
||||
path = os.path.expanduser(path)
|
||||
if not value:
|
||||
return None
|
||||
elif os.path.isabs(path):
|
||||
|
@ -26,7 +26,7 @@ import base64
|
||||
from unittest import mock
|
||||
|
||||
from qutebrowser.config import configtypes, configexc
|
||||
from qutebrowser.test import stubs
|
||||
from qutebrowser.test import stubs, helpers
|
||||
from qutebrowser.utils import debug, utils
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
@ -1377,14 +1377,27 @@ class DirectoryTests(unittest.TestCase):
|
||||
|
||||
def test_validate_expanduser(self, os_path):
|
||||
"""Test if validate expands the user correctly."""
|
||||
os_path.expandvars.side_effect = lambda x: x
|
||||
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
||||
os_path.isdir.side_effect = lambda path: path == '/home/foo/foobar'
|
||||
os_path.isabs.return_value = True
|
||||
self.t.validate('~/foobar')
|
||||
os_path.expanduser.assert_called_once_with('~/foobar')
|
||||
|
||||
def test_validate_expandvars(self, os_path):
|
||||
"""Test if validate expands the user correctly."""
|
||||
os_path.expandvars.side_effect = lambda x: x.replace('$BAR',
|
||||
'/home/foo/bar')
|
||||
os_path.expanduser.side_effect = lambda x: x
|
||||
os_path.isdir.side_effect = lambda path: path == '/home/foo/bar/foobar'
|
||||
os_path.isabs.return_value = True
|
||||
with helpers.environ_set_temp('bar', '/home/foo/bar'):
|
||||
self.t.validate('$BAR/foobar')
|
||||
os_path.expandvars.assert_called_once_with('$BAR/foobar')
|
||||
|
||||
def test_transform(self, os_path):
|
||||
"""Test transform."""
|
||||
os_path.expandvars.side_effect = lambda x: x
|
||||
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
||||
self.assertEqual(self.t.transform('~/foobar'), '/home/foo/foobar')
|
||||
os_path.expanduser.assert_called_once_with('~/foobar')
|
||||
@ -1780,6 +1793,12 @@ class UserStyleSheetTests(unittest.TestCase):
|
||||
path = os.path.join(os.path.sep, 'foo', 'bar')
|
||||
self.assertEqual(self.t.transform(path), QUrl("file:///foo/bar"))
|
||||
|
||||
def test_transform_file_expandvars(self):
|
||||
"""Test transform with a filename (expandvars)."""
|
||||
with helpers.environ_set_temp('FOO', 'foo'):
|
||||
path = os.path.join(os.path.sep, '$FOO', 'bar')
|
||||
self.assertEqual(self.t.transform(path), QUrl("file:///foo/bar"))
|
||||
|
||||
def test_transform_base64(self):
|
||||
"""Test transform with a data string."""
|
||||
b64 = base64.b64encode(b"test").decode('ascii')
|
||||
|
Loading…
Reference in New Issue
Block a user