Skip to content

Commit

Permalink
allow config files to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Van der Jeugt committed Jan 5, 2016
1 parent 32de5b7 commit e28c1bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions qutebrowser/browser/hints.py
Expand Up @@ -51,6 +51,7 @@


class WordHintingError(Exception):

"""Exception raised on errors during word hinting."""


Expand Down Expand Up @@ -985,6 +986,7 @@ class WordHinter:
Attributes:
"""

FIRST_ALPHABETIC = re.compile('[A-Za-z]{3,}')

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion qutebrowser/config/configdata.py
Expand Up @@ -891,7 +891,7 @@ def data(readonly=False):
"Make chars in hint strings uppercase."),

('dictionary',
SettingValue(typ.File(), '/usr/share/dict/words'),
SettingValue(typ.File(required=False), '/usr/share/dict/words'),
"The dictionary file to be used by the word hints."),

('auto-follow',
Expand Down
24 changes: 14 additions & 10 deletions qutebrowser/config/configtypes.py
Expand Up @@ -891,6 +891,10 @@ class File(BaseType):

"""A file on the local filesystem."""

def __init__(self, required=True, **kwargs):
super().__init__(**kwargs)
self.required = required

def transform(self, value):
if not value:
return None
Expand All @@ -899,7 +903,9 @@ def transform(self, value):
if not os.path.isabs(value):
cfgdir = standarddir.config()
assert cfgdir is not None
return os.path.join(cfgdir, value)
value = os.path.join(cfgdir, value)
#if not self.required and not os.access(value, os.F_OK | os.R_OK):
# return None
return value

def validate(self, value):
Expand All @@ -915,15 +921,13 @@ def validate(self, value):
raise configexc.ValidationError(
value, "must be an absolute path when not using a "
"config directory!")
elif not os.path.isfile(os.path.join(cfgdir, value)):
raise configexc.ValidationError(
value, "must be a valid path relative to the config "
"directory!")
else:
return
elif not os.path.isfile(value):
raise configexc.ValidationError(
value, "must be a valid file!")
value = os.path.join(cfgdir, value)
not_isfile_message = ("must be a valid path relative to the "
"config directory!")
else:
not_isfile_message = "must be a valid file!"
if self.required and not os.path.isfile(value):
raise configexc.ValidationError(value, not_isfile_message)
except UnicodeEncodeError as e:
raise configexc.ValidationError(value, e)

Expand Down

0 comments on commit e28c1bf

Please sign in to comment.