summaryrefslogtreecommitdiff
path: root/scripts/dictcli.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-08-27 09:44:51 +0200
committerFlorian Bruhin <me@the-compiler.org>2019-08-27 11:25:00 +0200
commita5fb23458b16b7de97afba2d76401e0506cebf58 (patch)
treec5d429cdaaba08f7b24bb083e852b0b87f5d0e8d /scripts/dictcli.py
parentcdf99da3e09152b32b12c4bdbc4eebfb62535399 (diff)
downloadqutebrowser-a5fb23458b16b7de97afba2d76401e0506cebf58.tar.gz
qutebrowser-a5fb23458b16b7de97afba2d76401e0506cebf58.zip
Clean up filename handling in dictcli/spell.py
Before this change, we sometimes assumed that a dictionary filename had a .bdic suffix, sometimes not, and sometimes we added it by hand. For some reason (probably some minor API change?) this currently breaks running dictcli.py. While the minimal fix in #4986 works, it only does so because we use re.match (not re.fullmatch) inside spell.py, so the .bdic suffix (which is present there) is ignored. This change instead refactors all dict handling so that the suffix is always included in the filename, and only stripped off in the last moment when passing it to QtWebEngine. Closes #4986
Diffstat (limited to 'scripts/dictcli.py')
-rwxr-xr-xscripts/dictcli.py27
1 files changed, 7 insertions, 20 deletions
diff --git a/scripts/dictcli.py b/scripts/dictcli.py
index 6864e9129..24ea523b4 100755
--- a/scripts/dictcli.py
+++ b/scripts/dictcli.py
@@ -61,36 +61,23 @@ class Language:
name = attr.ib()
remote_filename = attr.ib()
local_filename = attr.ib(default=None)
- _file_extension = attr.ib('bdic', init=False)
def __attrs_post_init__(self):
if self.local_filename is None:
self.local_filename = spell.local_filename(self.code)
@property
- def remote_path(self):
- """Resolve the filename with extension the remote dictionary."""
- return '.'.join([self.remote_filename, self._file_extension])
-
- @property
- def local_path(self):
- """Resolve the filename with extension the local dictionary."""
- if self.local_filename is None:
- return None
- return '.'.join([self.local_filename, self._file_extension])
-
- @property
def remote_version(self):
"""Resolve the version of the local dictionary."""
- return spell.version(self.remote_path)
+ return spell.version(self.remote_filename)
@property
def local_version(self):
"""Resolve the version of the local dictionary."""
- local_path = self.local_path
- if local_path is None:
+ local_filename = self.local_filename
+ if local_filename is None:
return None
- return spell.version(local_path)
+ return spell.version(local_filename)
def get_argparser():
@@ -143,7 +130,7 @@ def valid_languages():
def parse_entry(entry):
"""Parse an entry from the remote API."""
dict_re = re.compile(r"""
- (?P<filename>(?P<code>[a-z]{2}(-[A-Z]{2})?).*)\.bdic
+ (?P<filename>(?P<code>[a-z]{2}(-[A-Z]{2})?).*\.bdic)
""", re.VERBOSE)
match = dict_re.fullmatch(entry['name'])
if match is not None:
@@ -214,13 +201,13 @@ def filter_languages(languages, selected):
def install_lang(lang):
"""Install a single lang given by the argument."""
- lang_url = API_URL + lang.remote_path + '?format=TEXT'
+ lang_url = API_URL + lang.remote_filename + '?format=TEXT'
if not os.path.isdir(spell.dictionary_dir()):
msg = '{} does not exist, creating the directory'
print(msg.format(spell.dictionary_dir()))
os.makedirs(spell.dictionary_dir())
print('Downloading {}'.format(lang_url))
- dest = os.path.join(spell.dictionary_dir(), lang.remote_path)
+ dest = os.path.join(spell.dictionary_dir(), lang.remote_filename)
download_dictionary(lang_url, dest)
print('Installed to {}.'.format(dest))