コード例 #1
0
ファイル: installer.py プロジェクト: idiles/opendict
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, e:
        print "ERROR Unable to create dicrectories, aborted (%s)" % e
        try:
            shutil.rmtree(dictDir)
        except Exception, e:
            print "ERROR Unable to remove directories (%s)" % e
コード例 #2
0
ファイル: installer.py プロジェクト: nerijus/opendict
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, e:
        print "ERROR Unable to create dicrectories, aborted (%s)" % e
        try:
            shutil.rmtree(dictDir)
        except Exception, e:
            print "ERROR Unable to remove directories (%s)" % e
コード例 #3
0
ファイル: installer.py プロジェクト: nerijus/opendict
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

    # Check if it is ZIP archive
    if os.path.splitext(filePath)[1].lower()[1:] != "zip":
        raise Exception, _("%s is not OpenDict dictionary plugin") % filePath

    util.makeDirectories()

    try:
        zipFile = zipfile.ZipFile(filePath, 'r')
    except Exception, e:
        raise Exception, _("File \"%s\" is not valid ZIP file") % \
              os.path.basename(filePath)
コード例 #4
0
ファイル: installer.py プロジェクト: idiles/opendict
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

    # Check if it is ZIP archive
    if os.path.splitext(filePath)[1].lower()[1:] != "zip":
        raise Exception, _("%s is not OpenDict dictionary plugin") % filePath

    util.makeDirectories()

    try:
        zipFile = zipfile.ZipFile(filePath, 'r')
    except Exception, e:
        raise Exception, _("File \"%s\" is not valid ZIP file") % \
              os.path.basename(filePath)
コード例 #5
0
class OpenDictApp(wx.App):
    """Top-level class of wxWidgets application"""

    locale = wx.Locale()

    def OnInit(self):

        _ = wx.GetTranslation
        _start = time.time()

        wx.Version = []
        try:
            wx.Version = wx.__version__
        except Exception, e:
            try:
                wx.Version = wx.Python.__version__
            except:
                pass

        if wx.Version.split('.') < ['2', '8']:
            from lib.gui import errorwin

            title = _("wxPython Version Error")
            msg = _("wxPython %s is installed on this system.\n\n"
                    "OpenDict %s requires wxPython 2.8 or newer to run smoothly.\n\n"
                    "You can find wxPython at "
                    "http://www.wxpython.org or you can "
                    "install it using your system package manager.") \
                    % (wx.Version, info.VERSION)
            errorwin.showErrorMessage(title, msg)
            return False

        util.makeDirectories()

        systemLog(DEBUG, "Unicode version: %s" % wx.USE_UNICODE)

        # Init gettext support
        wx.Locale_AddCatalogLookupPathPrefix(
            os.path.join(info.GLOBAL_HOME, 'po'))
        self.locale.Init(wx.LANGUAGE_DEFAULT)
        self.locale.AddCatalog('opendict')

        # Data cache instance
        self.cache = {}

        # Dictionaries container
        # Mapping: name -> object
        self.dictionaries = {}

        # Failed dictionaries.
        # For error message that may be shown after creating main window
        self.invalidDictionaries = []

        self.config = Configuration()
        self.config.load()

        self.agreements = util.AgreementsManager(
            os.path.join(info.LOCAL_HOME, 'agreements.txt'))

        # Set unique ids
        for plugin in newplugin.loadDictionaryPlugins(
                self.dictionaries, self.invalidDictionaries):
            self.config.ids[wx.NewId()] = plugin.getName()

        for plain in plaindict.loadPlainDictionaries(self.dictionaries):
            self.config.ids[wx.NewId()] = plain.getName()

        for d in self.dictionaries.values():
            if not self.config.activedict.init:
                if not self.config.activedict.enabled(d.getName()):
                    d.setActive(active=False)
            else:
                # Fill up with names if not initialized yet
                self.config.activedict.add(d.getName())

        windowPos = (int(self.config.get('windowPosX')),
                     int(self.config.get('windowPosY')))
        windowSize = (int(self.config.get('windowWidth')),
                      int(self.config.get('windowHeight')))

        self.window = MainWindow(None,
                                 -1,
                                 "OpenDict",
                                 windowPos,
                                 windowSize,
                                 style=wx.DEFAULT_FRAME_STYLE)

        try:
            systemLog(INFO, "OpenDict %s" % info.VERSION)
            systemLog(INFO, "wxPython %s" % wx.Version)
            systemLog(INFO, "Global home: %s:" % info.GLOBAL_HOME)
            systemLog(INFO, "Local home: %s" % info.LOCAL_HOME)
            systemLog(DEBUG, "Loaded in %f seconds" % (time.time() - _start))
        except Exception, e:
            print "Logger Error: Unable to write to log (%s)" % e
コード例 #6
0
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)

    # Check if it is ZIP archive
    if os.path.splitext(filePath)[1].lower()[1:] != "zip":
        raise Exception(_("%s is not OpenDict dictionary plugin") % filePath)

    util.makeDirectories()

    try:
        zipFile = zipfile.ZipFile(filePath, 'r')
    except Exception as e:
        raise Exception(_("File \"%s\" is not valid ZIP file") % \
              os.path.basename(filePath))

    # Test CRC
    if zipFile.testzip():
        raise Exception(_("Dictionary plugin file is corrupted"))

    # Check if empty
    try:
        topDirectory = zipFile.namelist()[0]
    except Exception as e:
        raise Exception(_("Plugin file is empty (%s)") % e)

    configFileExists = False
    pluginConfigExists = False
    plainConfigExists = False
    topLevelDirExists = False

    # Check for validity
    for fileInZip in zipFile.namelist():
        dirName = os.path.dirname(fileInZip)
        fileName = os.path.basename(fileInZip)

        if fileName == "plugin.xml":
            pluginConfigExists = True

        if fileName == 'config.xml':
            plainConfigExists = True

        if len(fileName) == 0 \
           and len(dirName.split('/')) == 1:
            topLevelDirExists = True

    if ((not plainConfigExists) and (not pluginConfigExists)) \
       or (not topLevelDirExists):
        raise Exception(_("Selected file is not valid OpenDict plugin"))

    dtype = None
    if plainConfigExists:
        directory = _installPlainPlugin(filePath)
        dtype = 'plain'
    elif pluginConfigExists:
        directory = _installNormalPlugin(filePath)
        dtype = 'plugin'

    return (directory, dtype)
コード例 #7
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