Exemple #1
0
# structure is odd and awkward.
# TODO: write tests for this file

"""Common elements to all dictionary formats."""

from os.path import splitext
import shutil
import threading

import plover.dictionary.json_dict as json_dict
import plover.dictionary.rtfcre_dict as rtfcre_dict
from plover.config import JSON_EXTENSION, RTF_EXTENSION, CONFIG_DIR
from plover.exception import DictionaryLoaderException

dictionaries = {
    JSON_EXTENSION.lower(): json_dict,
    RTF_EXTENSION.lower(): rtfcre_dict,
}

def load_dictionary(filename):
    """Load a dictionary from a file."""
    extension = splitext(filename)[1].lower()
    
    try:
        dict_type = dictionaries[extension]
    except KeyError:
        raise DictionaryLoaderException(
            'Unsupported extension for dictionary: %s. Supported extensions: %s' %
            (extension, ', '.join(dictionaries.keys())))

    loader = dict_type.load_dictionary
Exemple #2
0
# TODO: maybe move this code into the StenoDictionary itself. The current saver
# structure is odd and awkward.
# TODO: write tests for this file
"""Common elements to all dictionary formats."""

from os.path import splitext
import shutil
import threading

import plover.dictionary.json_dict as json_dict
import plover.dictionary.rtfcre_dict as rtfcre_dict
from plover.config import JSON_EXTENSION, RTF_EXTENSION, CONFIG_DIR
from plover.exception import DictionaryLoaderException

dictionaries = {
    JSON_EXTENSION.lower(): json_dict,
    RTF_EXTENSION.lower(): rtfcre_dict,
}


def load_dictionary(filename):
    """Load a dictionary from a file."""
    extension = splitext(filename)[1].lower()

    try:
        dict_type = dictionaries[extension]
    except KeyError:
        raise DictionaryLoaderException(
            'Unsupported extension for dictionary: %s. Supported extensions: %s'
            % (extension, ', '.join(dictionaries.keys())))