def install_lang(lang): """Install a single lang given by the argument.""" lang_url = API_URL + lang.remote_path + '?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) download_dictionary(lang_url, dest) print('Done.')
def install_lang(lang): """Install a single lang given by the argument.""" 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_filename) download_dictionary(lang_url, dest) print('Installed to {}.'.format(dest))
def install_lang(lang): """Install a single lang given by the argument.""" print('Installing {}: {}'.format(lang.code, lang.name)) lang_url = API_URL + lang.file_path + '?format=TEXT' if not os.path.isdir(spell.dictionary_dir()): warn_msg = '{} does not exist, creating the directory' print(warn_msg.format(spell.dictionary_dir())) os.makedirs(spell.dictionary_dir()) print('Downloading {}'.format(lang_url)) dest = os.path.join(spell.dictionary_dir(), lang.file_path) download_dictionary(lang_url, dest) print('Done.')
def remove_old(languages): """Remove old versions of languages.""" installed = [lang for lang in languages if lang.local_version is not None] for lang in installed: local_files = spell.local_files(lang.code) for old_file in local_files[1:]: os.remove(os.path.join(spell.dictionary_dir(), old_file))
def test_dictionary_dir(monkeypatch, qt_version, old, subdir): monkeypatch.setattr(qtutils, 'qVersion', lambda: qt_version) monkeypatch.setattr(QLibraryInfo, 'location', lambda _: 'global_datapath') monkeypatch.setattr(standarddir, 'data', lambda: 'user_datapath') expected = os.path.join(subdir, 'qtwebengine_dictionaries') assert spell.dictionary_dir(old=old) == expected
def remove_old(languages): """Remove old versions of languages.""" installed = [lang for lang in languages if lang.local_version is not None] for lang in installed: local_files = spell.local_files(lang.code) for old_file in local_files[1:]: os.remove(os.path.join(spell.dictionary_dir(), old_file))
def test_dictionary_dir(monkeypatch, qt_version, old, subdir): monkeypatch.setattr(qtutils, 'qVersion', lambda: qt_version) monkeypatch.setattr(QLibraryInfo, 'location', lambda _: 'global_datapath') monkeypatch.setattr(standarddir, 'data', lambda: 'user_datapath') expected = os.path.join(subdir, 'qtwebengine_dictionaries') assert spell.dictionary_dir(old=old) == expected
def test_dictionary_dir(monkeypatch): monkeypatch.setattr(QLibraryInfo, 'location', lambda _: 'datapath') assert spell.dictionary_dir() == os.path.join('datapath', 'qtwebengine_dictionaries')