Exemple #1
0
def _loadPlainDictionary(directory):
    """Load one dictionary and returns dictionary object"""

    from lib import dicttype
    dictionary = None

    try:
        config = xmltools.parsePlainDictConfig(\
                os.path.join(directory,
                             info.__PLAIN_DICT_CONFIG_DIR,
                             'config.xml'))

        for t in dicttype.supportedTypes:
            if t.getIdName() == config.get('format'):
                Parser = t.getClass()

        if not Parser:
            raise Exception, "This is internal error and should not happen: " \
                  "no parser class found for dictionary in %s" % directory

        filePath = config.get('path')
        fileName = os.path.basename(filePath)
        home = info.LOCAL_HOME
        if directory.startswith(info.GLOBAL_HOME):
            home = info.GLOBAL_HOME

        if not os.path.exists(filePath):
            newPath = os.path.join(home, info.PLAIN_DICT_DIR,
                                   fileName, info.__PLAIN_DICT_FILE_DIR,
                                   fileName)
            if os.path.exists(newPath):
                filePath = newPath
            else:
                filePath = None

            
        if not filePath:
            raise Exception, "Dictionary file not found: %s" % fileName

        dictionary = Parser(filePath)
        dictionary.setEncoding(config.get('encoding'))
        dictionary.setName(config.get('name'))
        dictionary.setVersion(config.get('version'))
        dictionary.setAuthors(config.get('authors'))
        dictionary.setChecksum(config.get('md5'))
        dictionary.setLicenceFile(config.get('licence'))
        dictionary.setDescription(config.get('description'))

    except Exception, e:
        traceback.print_exc()
Exemple #2
0
def _loadPlainDictionary(directory):
    """Load one dictionary and returns dictionary object"""

    from lib import dicttype
    dictionary = None
    Parser = None

    try:
        config = xmltools.parsePlainDictConfig(\
                os.path.join(directory,
                             info.__PLAIN_DICT_CONFIG_DIR,
                             'config.xml'))

        for t in dicttype.supportedTypes:
            if t.getIdName() == config.get('format'):
                Parser = t.getClass()

        if not Parser:
            raise Exception, "This is internal error and should not happen: " \
                  "no parser class found for dictionary in %s" % directory

        filePath = config.get('path')
        fileName = os.path.basename(filePath)
        home = info.LOCAL_HOME
        if directory.startswith(info.GLOBAL_HOME):
            home = info.GLOBAL_HOME

        if not os.path.exists(filePath):
            newPath = os.path.join(home, info.PLAIN_DICT_DIR, fileName,
                                   info.__PLAIN_DICT_FILE_DIR, fileName)
            if os.path.exists(newPath):
                filePath = newPath
            else:
                filePath = None

        if not filePath:
            raise Exception, "Dictionary file not found: %s" % fileName

        dictionary = Parser(filePath)
        dictionary.setEncoding(config.get('encoding'))
        dictionary.setName(config.get('name'))
        dictionary.setVersion(config.get('version'))
        dictionary.setAuthors(config.get('authors'))
        dictionary.setChecksum(config.get('md5'))
        dictionary.setLicenceFile(config.get('licence'))
        dictionary.setDescription(config.get('description'))

    except Exception, e:
        traceback.print_exc()
Exemple #3
0
    def __init__(self, directory):
        """Store configuration data"""

        raise Exception, "PlainDictInfo is deprecated"

        self.config = xmltools.parsePlainDictConfig(\
                os.path.join(directory,
                             info.__PLAIN_DICT_CONFIG_DIR,
                             'config.xml'))

        self.directory = directory

        self.name = config.get('name')
        self.formatString = config.get('format')
        self.version = config.get('version')
        self.author = config.get('author')
        self.path = config.get('path')
        self.checksum = config.get('md5')
        self.encoding = config.get('encoding')
Exemple #4
0
    def __init__(self, directory):
        """Store configuration data"""

        raise Exception, "PlainDictInfo is deprecated"

        self.config = xmltools.parsePlainDictConfig(\
                os.path.join(directory,
                             info.__PLAIN_DICT_CONFIG_DIR,
                             'config.xml'))

        self.directory = directory

        self.name = config.get('name')
        self.formatString = config.get('format')
        self.version = config.get('version')
        self.author = config.get('author')
        self.path = config.get('path')
        self.checksum = config.get('md5')
        self.encoding = config.get('encoding')