Example #1
0
def savePlainConfiguration(dictionary):
    """Write configuration to disk"""

    from lib import dicttype

    if not dictionary.getType() in dicttype.plainTypes:
        systemLog(ERROR, "Request to write configuration to %s of type %s" \
            % (dictionary.getName(), dictionary.getType()))
        return

    md5sum = util.getMD5Sum(dictionary.getPath())
    dictDir = dictionary.getConfigDir()

    doc = xmltools.generatePlainDictConfig(
        name=dictionary.getName(),
        format=dictionary.getType().getIdName(),
        version=dictionary.getVersion(),
        authors=dictionary.getAuthors(),
        path=dictionary.getPath(),
        md5=md5sum,
        encoding=dictionary.getEncoding(),
        description=dictionary.getDescription(),
        licence=dictionary.getLicenceFile())

    xmltools.writePlainDictConfig(doc,
                                  os.path.join(dictDir, 'conf', 'config.xml'))
Example #2
0
def savePlainConfiguration(dictionary):
    """Write configuration to disk"""

    from lib import dicttype

    if not dictionary.getType() in dicttype.plainTypes:
       systemLog(ERROR, "Request to write configuration to %s of type %s" \
           % (dictionary.getName(), dictionary.getType()))
       return

    md5sum = util.getMD5Sum(dictionary.getPath())
    dictDir = dictionary.getConfigDir()

    doc = xmltools.generatePlainDictConfig(name=dictionary.getName(),
                                           format=dictionary.getType().getIdName(),
                                           version=dictionary.getVersion(),
                                           authors=dictionary.getAuthors(),
                                           path=dictionary.getPath(),
                                           md5=md5sum,
                                           encoding=dictionary.getEncoding(),
                                           description=dictionary.getDescription(),
                                           licence=dictionary.getLicenceFile())

    xmltools.writePlainDictConfig(doc, os.path.join(dictDir,
                                                    'conf',
                                                    'config.xml'))
Example #3
0
    # Determine info
    dictFormat = dictType.getIdName()
    md5sum = util.getMD5Sum(filePath)

    # Write configuration
    doc = xmltools.generatePlainDictConfig(name=dictionaryName,
                                           format=dictFormat,
                                           version=None,
                                           authors={},
                                           path=filePath,
                                           md5=md5sum,
                                           encoding='UTF-8',
                                           description=None)

    xmltools.writePlainDictConfig(doc,
                                  os.path.join(dictDir, 'conf', 'config.xml'))

    return dictDir


def installPlugin(filePath):
    """Install dictionary plugin and return directory path"""

    # Check if file exists
    if not os.path.exists(filePath):
        raise Exception, _("File %s does not exist") % filePath

    # Check if it is file
    if not os.path.isfile(filePath):
        raise Exception, _("%s is not a file") % filePath
Example #4
0
    # Determine info
    dictFormat = dictType.getIdName()
    md5sum = util.getMD5Sum(filePath)

    # Write configuration
    doc = xmltools.generatePlainDictConfig(name=dictionaryName,
                                           format=dictFormat,
                                           version=None,
                                           authors={},
                                           path=filePath,
                                           md5=md5sum,
                                           encoding='UTF-8',
                                           description=None)

    xmltools.writePlainDictConfig(doc, os.path.join(dictDir,
                                                    'conf',
                                                    'config.xml'))


    return dictDir


def installPlugin(filePath):
    """Install dictionary plugin and return directory path"""

    # Check if file exists
    if not os.path.exists(filePath):
        raise Exception, _("File %s does not exist") % filePath

    # Check if it is file
    if not os.path.isfile(filePath):
Example #5
0
def installPlainDictionary(filePath):
    """Install plain dictionary and return directory path"""

    if not os.path.exists(filePath):
        raise Exception(_("File %s does not exist") % filePath)

    if not os.path.isfile(filePath):
        raise Exception(_("%s is not a file") % filePath)

    util.makeDirectories()

    fileName = os.path.basename(filePath)
    dictionaryName = os.path.splitext(fileName)[0]

    dictDir = os.path.join(info.LOCAL_HOME, info.__DICT_DIR,
                           info.__PLAIN_DICT_DIR, fileName)

    # Check existance
    if os.path.exists(dictDir):
        raise Exception(_("Dictionary \"%s\" is already installed") \
            % dictionaryName)

    extention = os.path.splitext(fileName)[1][1:]
    dictType = None

    # Determine type
    for t in dicttype.supportedTypes:
        for ext in t.getFileExtentions():
            if ext.lower() == extention.lower():
                dictType = t
                break

    if not dictType:
        raise Exception("Dictionary type for '%s' still unknown! " \
              "This may be internal error." % fileName)

    # Create directories
    try:
        os.mkdir(dictDir)
        os.mkdir(os.path.join(dictDir, info.__PLAIN_DICT_CONFIG_DIR))
        os.mkdir(os.path.join(dictDir, info.__PLAIN_DICT_FILE_DIR))
        os.mkdir(os.path.join(dictDir, info._PLAIN_DICT_DATA_DIR))
    except Exception as e:
        print("ERROR Unable to create dicrectories, aborted (%s)" % e)
        try:
            shutil.rmtree(dictDir)
        except Exception as e:
            print("ERROR Unable to remove directories (%s)" % e)

    # Determine info
    dictFormat = dictType.getIdName()
    md5sum = util.getMD5Sum(filePath)

    # Write configuration
    doc = xmltools.generatePlainDictConfig(name=dictionaryName,
                                           format=dictFormat,
                                           version=None,
                                           authors={},
                                           path=filePath,
                                           md5=md5sum,
                                           encoding='UTF-8',
                                           description=None)

    xmltools.writePlainDictConfig(doc,
                                  os.path.join(dictDir, 'conf', 'config.xml'))

    return dictDir