예제 #1
0
  def xmlDownloaded(self,nr,state):
    """ populate the plugins object with the fetched data """
    if not self.httpId.has_key(nr):
      return
    reposName = self.httpId[nr]
    if state:                             # fetching failed
      self.mRepositories[reposName]["state"] =  3
      self.mRepositories[reposName]["error"] = self.mRepositories[reposName]["QPHttp"].errorString()
    else:
      repoData = self.mRepositories[reposName]["xmlData"]
      reposXML = QDomDocument()
      reposXML.setContent(repoData.data())
      pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
      if pluginNodes.size():
        for i in range(pluginNodes.size()):
          fileName = pluginNodes.item(i).firstChildElement("file_name").text().simplified()
          if not fileName:
              fileName = QFileInfo(pluginNodes.item(i).firstChildElement("download_url").text().trimmed().split("?")[0]).fileName()
          name = fileName.section(".", 0, 0)
          name = unicode(name)
          experimental = False
          if pluginNodes.item(i).firstChildElement("experimental").text().simplified().toUpper() in ["TRUE","YES"]:
            experimental = True
          plugin = {
            "name"          : pluginNodes.item(i).toElement().attribute("name"),
            "version_avail" : pluginNodes.item(i).toElement().attribute("version"),
            "desc_repo"     : pluginNodes.item(i).firstChildElement("description").text().simplified(),
            "desc_local"    : "",
            "author"        : pluginNodes.item(i).firstChildElement("author_name").text().simplified(),
            "homepage"      : pluginNodes.item(i).firstChildElement("homepage").text().simplified(),
            "url"           : pluginNodes.item(i).firstChildElement("download_url").text().simplified(),
            "experimental"  : experimental,
            "filename"      : fileName,
            "status"        : "not installed",
            "error"         : "",
            "error_details" : "",
            "version_inst"  : "",
            "repository"    : reposName,
            "localdir"      : name,
            "read-only"     : False}
          qgisMinimumVersion = pluginNodes.item(i).firstChildElement("qgis_minimum_version").text().simplified()
          if not qgisMinimumVersion: qgisMinimumVersion = "1"
          qgisMaximumVersion = pluginNodes.item(i).firstChildElement("qgis_maximum_version").text().simplified()
          if not qgisMaximumVersion: qgisMaximumVersion = qgisMinimumVersion[0] + ".99"
          #if compatible, add the plugin to the list
          if not pluginNodes.item(i).firstChildElement("disabled").text().simplified().toUpper() in ["TRUE","YES"]:
           if compareVersions(QGIS_VER, qgisMinimumVersion) < 2 and compareVersions(qgisMaximumVersion, QGIS_VER) < 2:
              #add the plugin to the cache
              plugins.addFromRepository(plugin)
      # set state=2, even if the repo is empty
      self.mRepositories[reposName]["state"] = 2

    self.emit(SIGNAL("repositoryFetched(QString)"), reposName )

    # is the checking done?
    if not self.fetchingInProgress():
      plugins.rebuild()
      self.saveCheckingOnStartLastDate()
      self.emit(SIGNAL("checkingDone()"))
예제 #2
0
 def rebuild(self):
   """ build or rebuild the mPlugins from the caches """
   self.mPlugins = {}
   for i in self.localCache.keys():
     self.mPlugins[i] = self.localCache[i].copy()
   settings = QSettings()
   allowExperimental = settings.value(settingsGroup+"/allowExperimental", False, type=bool)
   for i in self.repoCache.values():
     for j in i:
       plugin=j.copy() # do not update repoCache elements!
       key = plugin["id"]
       # check if the plugin is allowed and if there isn't any better one added already.
       if (allowExperimental or not plugin["experimental"]) \
       and not (self.mPlugins.has_key(key) and self.mPlugins[key]["version_available"] and compareVersions(self.mPlugins[key]["version_available"], plugin["version_available"]) < 2):
         # The mPlugins dict contains now locally installed plugins.
         # Now, add the available one if not present yet or update it if present already.
         if not self.mPlugins.has_key(key):
           self.mPlugins[key] = plugin   # just add a new plugin
         else:
           # update local plugin with remote metadata
           # name, description, icon: only use remote data if local one is not available (because of i18n and to not download the icon)
           for attrib in translatableAttributes + ["icon"]:
               if not self.mPlugins[key][attrib] and plugin[attrib]:
                   self.mPlugins[key][attrib] = plugin[attrib]
           # other remote metadata is preffered:
           for attrib in ["name", "description", "category", "tags", "changelog", "author_name", "author_email", "homepage",
                          "tracker", "code_repository", "experimental", "version_available", "zip_repository",
                          "download_url", "filename", "downloads", "average_vote", "rating_votes"]:
             if not attrib in translatableAttributes:
               if plugin[attrib]:
                   self.mPlugins[key][attrib] = plugin[attrib]
         # set status
         #
         # installed   available   status
         # ---------------------------------------
         # none        any         "not installed" (will be later checked if is "new")
         # any         none        "orphan"
         # same        same        "installed"
         # less        greater     "upgradeable"
         # greater     less        "newer"
         if not self.mPlugins[key]["version_available"]:
           self.mPlugins[key]["status"] = "orphan"
         elif not self.mPlugins[key]["version_installed"]:
           self.mPlugins[key]["status"] = "not installed"
         elif self.mPlugins[key]["version_installed"] in ["?", "-1"]:
           self.mPlugins[key]["status"] = "installed"
         elif compareVersions(self.mPlugins[key]["version_available"],self.mPlugins[key]["version_installed"]) == 0:
           self.mPlugins[key]["status"] = "installed"
         elif compareVersions(self.mPlugins[key]["version_available"],self.mPlugins[key]["version_installed"]) == 1:
           self.mPlugins[key]["status"] = "upgradeable"
         else:
           self.mPlugins[key]["status"] = "newer"
         # debug: test if the status match the "installed" tag:
         if self.mPlugins[key]["status"] in ["not installed"] and self.mPlugins[key]["installed"]:
             raise Exception("Error: plugin status is ambiguous (1)")
         if self.mPlugins[key]["status"] in ["installed","orphan","upgradeable","newer"] and not self.mPlugins[key]["installed"]:
             raise Exception("Error: plugin status is ambiguous (2)")
   self.markNews()
예제 #3
0
  def xmlDownloaded(self,nr,state):
    """ populate the plugins object with the fetched data """
    if not self.httpId.has_key(nr):
      return
    reposName = self.httpId[nr]
    if state:                             # fetching failed
      self.mRepositories[reposName]["state"] =  3
      self.mRepositories[reposName]["error"] = self.mRepositories[reposName]["QPHttp"].errorString()
    else:
      repoData = self.mRepositories[reposName]["xmlData"]
      reposXML = QDomDocument()
      reposXML.setContent(repoData.data())
      pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
      if pluginNodes.size():
        for i in range(pluginNodes.size()):
          fileName = QFileInfo(pluginNodes.item(i).firstChildElement("download_url").text().trimmed()).fileName()
          name = fileName.section(".", 0, 0)
          name = str(name)
          plugin = {}
          plugin[name] = {
            "name"          : pluginNodes.item(i).toElement().attribute("name"),
            "version_avail" : pluginNodes.item(i).toElement().attribute("version"),
            "desc_repo"     : pluginNodes.item(i).firstChildElement("description").text().trimmed(),
            "desc_local"    : "",
            "author"        : pluginNodes.item(i).firstChildElement("author_name").text().trimmed(),
            "homepage"      : pluginNodes.item(i).firstChildElement("homepage").text().trimmed(),
            "url"           : pluginNodes.item(i).firstChildElement("download_url").text().trimmed(),
            "filename"      : fileName,
            "status"        : "not installed",
            "error"         : "",
            "error_details" : "",
            "version_inst"  : "",
            "repository"    : reposName,
            "localdir"      : name,
            "read-only"     : False}
          qgisMinimumVersion = pluginNodes.item(i).firstChildElement("qgis_minimum_version").text().trimmed()
          if not qgisMinimumVersion: qgisMinimumVersion = "0"
          # please use the tag below only if really needed! (for example if plugin development is abandoned)
          qgisMaximumVersion = pluginNodes.item(i).firstChildElement("qgis_maximum_version").text().trimmed()
          if not qgisMaximumVersion: qgisMaximumVersion = "2"
          #if compatible, add the plugin to the list
          if compareVersions(QGIS_VER, qgisMinimumVersion) < 2 and compareVersions(qgisMaximumVersion, QGIS_VER) < 2:
            if QGIS_VER[0]=="0" or qgisMinimumVersion[0]=="1" or name=="plugin_installer":
              plugins.addPlugin(plugin)
        plugins.workarounds()
        self.mRepositories[reposName]["state"] = 2
      else:
        #print "Repository parsing error"
        self.mRepositories[reposName]["state"] = 3
        self.mRepositories[reposName]["error"] = QCoreApplication.translate("QgsPluginInstaller","Couldn't parse output from the repository")

    self.emit(SIGNAL("repositoryFetched(QString)"), reposName )

    # is the checking done?
    if not self.fetchingInProgress():
      plugins.getAllInstalled()
      self.emit(SIGNAL("checkingDone()"))
예제 #4
0
 def rebuild(self):
   """ build or rebuild the mPlugins from the caches """
   self.mPlugins = {}
   for i in self.localCache.keys():
     self.mPlugins[i] = self.localCache[i].copy()
   settings = QSettings()
   allowExperimental = settings.value(settingsGroup+"/allowExperimental", False, type=bool)
   for i in self.repoCache.values():
     for j in i:
       plugin=j.copy() # do not update repoCache elements!
       key = plugin["id"]
       # check if the plugin is allowed and if there isn't any better one added already.
       if (allowExperimental or not plugin["experimental"]) \
       and not (self.mPlugins.has_key(key) and self.mPlugins[key]["version_available"] and compareVersions(self.mPlugins[key]["version_available"], plugin["version_available"]) < 2):
         # The mPlugins dict contains now locally installed plugins.
         # Now, add the available one if not present yet or update it if present already.
         if not self.mPlugins.has_key(key):
           self.mPlugins[key] = plugin   # just add a new plugin
         else:
           # update local plugin with remote metadata
           # only use remote icon if local one is not available
           if self.mPlugins[key]["icon"] == key and plugin["icon"]:
               self.mPlugins[key]["icon"] = plugin["icon"]
           # other remote metadata is preffered:
           for attrib in ["name", "description", "category", "tags", "changelog", "author_name", "author_email", "homepage",
                          "tracker", "code_repository", "experimental", "version_available", "zip_repository",
                          "download_url", "filename", "downloads", "average_vote", "rating_votes"]:
               if plugin[attrib]:
                   self.mPlugins[key][attrib] = plugin[attrib]
         # set status
         #
         # installed   available   status
         # ---------------------------------------
         # none        any         "not installed" (will be later checked if is "new")
         # any         none        "orphan"
         # same        same        "installed"
         # less        greater     "upgradeable"
         # greater     less        "newer"
         if not self.mPlugins[key]["version_available"]:
           self.mPlugins[key]["status"] = "orphan"
         elif not self.mPlugins[key]["version_installed"]:
           self.mPlugins[key]["status"] = "not installed"
         elif self.mPlugins[key]["version_installed"] in ["?", "-1"]:
           self.mPlugins[key]["status"] = "installed"
         elif compareVersions(self.mPlugins[key]["version_available"],self.mPlugins[key]["version_installed"]) == 0:
           self.mPlugins[key]["status"] = "installed"
         elif compareVersions(self.mPlugins[key]["version_available"],self.mPlugins[key]["version_installed"]) == 1:
           self.mPlugins[key]["status"] = "upgradeable"
         else:
           self.mPlugins[key]["status"] = "newer"
         # debug: test if the status match the "installed" tag:
         if self.mPlugins[key]["status"] in ["not installed"] and self.mPlugins[key]["installed"]:
             raise Exception("Error: plugin status is ambiguous (1)")
         if self.mPlugins[key]["status"] in ["installed","orphan","upgradeable","newer"] and not self.mPlugins[key]["installed"]:
             raise Exception("Error: plugin status is ambiguous (2)")
   self.markNews()
 def rebuild(self):
   """ build or rebuild the mPlugins from the caches """
   self.mPlugins = {}
   for i in self.localCache.keys():
     self.mPlugins[i] = self.localCache[i].copy()
   settings = QSettings()
   (allowed, ok) = settings.value(settingsGroup+"/allowedPluginType", QVariant(2)).toInt()
   for i in self.repoCache.values():
     for plugin in i:
       key = plugin["localdir"]
       # check if the plugin is allowed and if there isn't any better one added already.
       if (allowed != 1 or plugin["repository"] == officialRepo[0]) and (allowed == 3 or not plugin["experimental"]) \
       and not (self.mPlugins.has_key(key) and self.mPlugins[key]["version_avail"] and compareVersions(self.mPlugins[key]["version_avail"], plugin["version_avail"]) < 2):
         # The mPlugins doct contains now locally installed plugins. 
         # Now, add the available one if not present yet or update it if present already.
         if not self.mPlugins.has_key(key):
           self.mPlugins[key] = plugin   # just add a new plugin
         else:
           self.mPlugins[key]["version_avail"] = plugin["version_avail"]
           self.mPlugins[key]["desc_repo"] = plugin["desc_repo"]
           self.mPlugins[key]["filename"] = plugin["filename"]
           self.mPlugins[key]["repository"] = plugin["repository"]
           self.mPlugins[key]["experimental"] = plugin["experimental"]
           # use remote name if local one is not available
           if self.mPlugins[key]["name"] == key and plugin["name"]:
             self.mPlugins[key]["name"] = plugin["name"]
           # those metadata has higher priority for their remote instances:
           if plugin["author"]:
             self.mPlugins[key]["author"] = plugin["author"]
           if plugin["homepage"]:
             self.mPlugins[key]["homepage"] = plugin["homepage"]
           if plugin["url"]:
             self.mPlugins[key]["url"] = plugin["url"]
         # set status
         #
         # installed   available   status
         # ---------------------------------------
         # none        any         "not installed" (will be later checked if is "new")
         # any         none        "orphan"
         # same        same        "installed"
         # less        greater     "upgradeable"
         # greater     less        "newer"
         if not self.mPlugins[key]["version_avail"]:
           self.mPlugins[key]["status"] = "orphan"
         elif self.mPlugins[key]["error"] in ["broken","dependent"]:
           self.mPlugins[key]["status"] = "installed"
         elif not self.mPlugins[key]["version_inst"]:
           self.mPlugins[key]["status"] = "not installed"
         elif compareVersions(self.mPlugins[key]["version_avail"],self.mPlugins[key]["version_inst"]) == 0:
           self.mPlugins[key]["status"] = "installed"
         elif compareVersions(self.mPlugins[key]["version_avail"],self.mPlugins[key]["version_inst"]) == 1:
           self.mPlugins[key]["status"] = "upgradeable"
         else:
           self.mPlugins[key]["status"] = "newer"
   self.markNews()
 def getAllInstalled(self):
   """ Build the localCache """
   self.localCache = {}
   # first, try to add the read-only plugins...
   pluginsPath = unicode(QDir.convertSeparators(QDir.cleanPath(QgsApplication.pkgDataPath() + "/python/plugins")))
   #  temporarily add the system path as the first element to force loading the read-only plugins, even if masked by user ones.
   sys.path = [pluginsPath] + sys.path
   try:
     pluginDir = QDir(pluginsPath)
     pluginDir.setFilter(QDir.AllDirs)
     for key in pluginDir.entryList():
       key = unicode(key)
       if not key in [".",".."]:
         self.localCache[key] = self.getInstalledPlugin(key, True)
   except:
     # return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the system plugin directory")
     pass # it's not necessary to stop due to this error
   # remove the temporarily added path
   sys.path.remove(pluginsPath)
   # ...then try to add locally installed ones
   try:
     pluginDir = QDir.convertSeparators(QDir.cleanPath(QgsApplication.qgisSettingsDirPath() + "/python/plugins"))
     pluginDir = QDir(pluginDir)
     pluginDir.setFilter(QDir.AllDirs)
   except:
     return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the local plugin directory")
   for key in pluginDir.entryList():
     key = unicode(key)
     if not key in [".",".."]:
       plugin = self.getInstalledPlugin(key, False)
       if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_inst"],plugin["version_inst"]) == 1:
         # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
         self.obsoletePlugins += [key]
       self.localCache[key] = plugin
예제 #7
0
  def getAllInstalled(self, testLoad=True):
    """ Build the localCache """
    self.localCache = {}

    # reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
    pluginPaths = list(plugin_paths)
    pluginPaths.reverse()

    for pluginsPath in pluginPaths:
      isTheSystemDir = (pluginPaths.index(pluginsPath)==0)  # The curent dir is the system plugins dir
      if isTheSystemDir:
        # temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
        sys.path = [pluginsPath] + sys.path
      try:
        pluginDir = QDir(pluginsPath)
        pluginDir.setFilter(QDir.AllDirs)
        for key in pluginDir.entryList():
          if not key in [".",".."]:
            path = QDir.convertSeparators( pluginsPath + "/" + key )
            # readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
            readOnly = isTheSystemDir                            # Assume only the system plugins are not writable.
            # only test those not yet loaded. Loaded plugins already proved they're o.k.
            testLoadThis = testLoad and not qgis.utils.plugins.has_key(key)
            plugin = self.getInstalledPlugin(key, path=path, readOnly=readOnly, testLoad=testLoadThis)
            self.localCache[key] = plugin
            if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"],plugin["version_installed"]) == 1:
              # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
              self.obsoletePlugins += [key]
      except:
        # it's not necessary to stop if one of the dirs is inaccessible
        pass

      if isTheSystemDir:
        # remove the temporarily added path
        sys.path.remove(pluginsPath)
예제 #8
0
  def getAllInstalled(self, testLoad=True):
    """ Build the localCache """
    self.localCache = {}

    # reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
    pluginPaths = list(plugin_paths)
    pluginPaths.reverse()

    for pluginsPath in pluginPaths:
      isTheSystemDir = (pluginPaths.index(pluginsPath)==0)  # The curent dir is the system plugins dir
      if isTheSystemDir:
        # temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
        sys.path = [pluginsPath] + sys.path
      try:
        pluginDir = QDir(pluginsPath)
        pluginDir.setFilter(QDir.AllDirs)
        for key in pluginDir.entryList():
          if key not in [".",".."]:
            path = QDir.convertSeparators( pluginsPath + "/" + key )
            # readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
            readOnly = isTheSystemDir                            # Assume only the system plugins are not writable.
            # only test those not yet loaded. Loaded plugins already proved they're o.k.
            testLoadThis = testLoad and key not in qgis.utils.plugins
            plugin = self.getInstalledPlugin(key, path=path, readOnly=readOnly, testLoad=testLoadThis)
            self.localCache[key] = plugin
            if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"],plugin["version_installed"]) == 1:
              # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
              self.obsoletePlugins += [key]
      except:
        # it's not necessary to stop if one of the dirs is inaccessible
        pass

      if isTheSystemDir:
        # remove the temporarily added path
        sys.path.remove(pluginsPath)
예제 #9
0
 def getAllInstalled(self, testLoad=True):
   """ Build the localCache """
   self.localCache = {}
   # first, try to add the readonly plugins...
   pluginsPath = unicode(QDir.convertSeparators(QDir.cleanPath(QgsApplication.pkgDataPath() + "/python/plugins")))
   #  temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
   sys.path = [pluginsPath] + sys.path
   try:
     pluginDir = QDir(pluginsPath)
     pluginDir.setFilter(QDir.AllDirs)
     for key in pluginDir.entryList():
       key = unicode(key)
       if not key in [".",".."]:
         self.localCache[key] = self.getInstalledPlugin(key, readOnly=True, testLoad=False)
   except:
     # return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the system plugin directory")
     pass # it's not necessary to stop due to this error
   # remove the temporarily added path
   sys.path.remove(pluginsPath)
   # ...then try to add locally installed ones
   try:
     pluginDir = QDir.convertSeparators(QDir.cleanPath(QgsApplication.qgisSettingsDirPath() + "/python/plugins"))
     pluginDir = QDir(pluginDir)
     pluginDir.setFilter(QDir.AllDirs)
   except:
     return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the local plugin directory")
   for key in pluginDir.entryList():
     key = unicode(key)
     if not key in [".",".."]:
       plugin = self.getInstalledPlugin(key, readOnly=False, testLoad=testLoad)
       if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"],plugin["version_installed"]) == 1:
         # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
         self.obsoletePlugins += [key]
       self.localCache[key] = plugin
예제 #10
0
 def addPlugin(self, plugins):
   """ add a plugin (first from given) to the mPlugins dict """
   key = plugins.keys()[0]
   plugin = plugins[key]
   plugin["version_avail"] = normalizeVersion(plugin["version_avail"])
   plugin["version_inst"] = normalizeVersion(plugin["version_inst"])
   if not self.mPlugins.has_key(key) or compareVersions(self.mPlugins[key]["version_avail"],plugin["version_avail"]) == 2:
     self.mPlugins[key] = plugin # add the plugin if not present yet or if is newer than existing one
예제 #11
0
 def getInstalledPlugin(self, key, readOnly, testLoad=False):
   """ get the metadata of an installed plugin """
   if readOnly:
     path = QgsApplication.pkgDataPath()
   else:
     path = QgsApplication.qgisSettingsDirPath()
   path = QDir.cleanPath(path) + "/python/plugins/" + key
   if not QDir(path).exists():
     return
   nam   = ""
   ver   = ""
   desc  = ""
   auth  = ""
   homepage  = ""
   error = ""
   errorDetails = ""
   try:
     exec("import %s" % key)
     exec("reload (%s)" % key)
     try:
       exec("nam = %s.name()" % key)
     except:
       pass
     try:
       exec("ver = %s.version()" % key)
     except:
       pass
     try:
       exec("desc = %s.description()" % key)
     except:
       pass
     try:
       exec("auth = %s.author()" % key)
     except:
       # "authorName" was deprecated in QGis > 1.8,
       # you must use "author" instead
       try:
         exec("auth = %s.authorName()" % key)
       except:
         pass
     try:
       exec("homepage = %s.homepage()" % key)
     except:
       pass
     try:
       exec("qgisMinimumVersion = %s.qgisMinimumVersion()" % key)
       if compareVersions(QGIS_VER, qgisMinimumVersion) == 2:
         error = "incompatible"
         errorDetails = qgisMinimumVersion
     except:
       pass
     if testLoad:
       try:
         exec ("%s.classFactory(iface)" % key)
       except Exception, error:
         error = unicode(error.args[0])
   except Exception, error:
     error = unicode(error.args[0])
예제 #12
0
 def getInstalledPlugin(self, key, readOnly, testLoad=False):
     """ get the metadata of an installed plugin """
     if readOnly:
         path = QgsApplication.pkgDataPath()
     else:
         path = QgsApplication.qgisSettingsDirPath()
     path = QDir.cleanPath(path) + "/python/plugins/" + key
     if not QDir(path).exists():
         return
     nam = ""
     ver = ""
     desc = ""
     auth = ""
     homepage = ""
     error = ""
     errorDetails = ""
     try:
         exec("import %s" % key)
         exec("reload (%s)" % key)
         try:
             exec("nam = %s.name()" % key)
         except:
             pass
         try:
             exec("ver = %s.version()" % key)
         except:
             pass
         try:
             exec("desc = %s.description()" % key)
         except:
             pass
         try:
             exec("auth = %s.author()" % key)
         except:
             # "authorName" was deprecated in QGis > 1.8,
             # you must use "author" instead
             try:
                 exec("auth = %s.authorName()" % key)
             except:
                 pass
         try:
             exec("homepage = %s.homepage()" % key)
         except:
             pass
         try:
             exec("qgisMinimumVersion = %s.qgisMinimumVersion()" % key)
             if compareVersions(QGIS_VER, qgisMinimumVersion) == 2:
                 error = "incompatible"
                 errorDetails = qgisMinimumVersion
         except:
             pass
         if testLoad:
             try:
                 exec("%s.classFactory(iface)" % key)
             except Exception, error:
                 error = unicode(error.args[0])
     except Exception, error:
         error = unicode(error.args[0])
예제 #13
0
 def updatePlugin(self, key, readOnly):
   """ The mPlugins should contain available plugins first. Now, add installed one (add when not present, update if present) """
   if readOnly:
     path = QgsApplication.pkgDataPath()
   else:
     path = QgsApplication.qgisSettingsDirPath()
   path = QDir.cleanPath(path) + "/python/plugins/" + key
   if not QDir(path).exists():
     return
   nam   = ""
   ver   = ""
   desc  = ""
   auth  = ""
   homepage  = ""
   error = ""
   errorDetails = ""
   try:
     exec("import "+ key)
     try:
       exec("nam = %s.name()" % key)
     except:
       pass
     try:
       exec("ver = %s.version()" % key)
     except:
       pass
     try:
       exec("desc = %s.description()" % key)
     except:
       pass
     try:
       exec("auth = %s.authorName()" % key)
     except:
       pass
     try:
       exec("homepage = %s.homepage()" % key)
     except:
       pass
     try:
       exec("qgisMinimumVersion = %s.qgisMinimumVersion()" % key)
       if compareVersions(QGIS_VER, qgisMinimumVersion) == 2:
         error = "incompatible"
         errorDetails = qgisMinimumVersion
     except:
       pass
     try:
       exec ("%s.classFactory(iface)" % key)
     except Exception, error:
       error = error.message
   except Exception, error:
     error = error.message
예제 #14
0
 def rebuild(self):
     """ build or rebuild the mPlugins from the caches """
     self.mPlugins = {}
     for i in self.localCache.keys():
         self.mPlugins[i] = self.localCache[i].copy()
     settings = QSettings()
     (allowed, ok) = settings.value(settingsGroup + "/allowedPluginType",
                                    QVariant(2)).toInt()
     for i in self.repoCache.values():
         for plugin in i:
             key = plugin["localdir"]
             # check if the plugin is allowed and if there isn't any better one added already.
             if (allowed != 1 or plugin["repository"] == officialRepo[0]) and (allowed == 3 or not plugin["experimental"]) \
             and not (self.mPlugins.has_key(key) and self.mPlugins[key]["version_avail"] and compareVersions(self.mPlugins[key]["version_avail"], plugin["version_avail"]) < 2):
                 # The mPlugins dict contains now locally installed plugins.
                 # Now, add the available one if not present yet or update it if present already.
                 if not self.mPlugins.has_key(key):
                     self.mPlugins[key] = plugin  # just add a new plugin
                 else:
                     self.mPlugins[key]["version_avail"] = plugin[
                         "version_avail"]
                     self.mPlugins[key]["desc_repo"] = plugin["desc_repo"]
                     self.mPlugins[key]["filename"] = plugin["filename"]
                     self.mPlugins[key]["repository"] = plugin["repository"]
                     self.mPlugins[key]["experimental"] = plugin[
                         "experimental"]
                     # use remote name if local one is not available
                     if self.mPlugins[key]["name"] == key and plugin["name"]:
                         self.mPlugins[key]["name"] = plugin["name"]
                     # those metadata has higher priority for their remote instances:
                     if plugin["author"]:
                         self.mPlugins[key]["author"] = plugin["author"]
                     if plugin["homepage"]:
                         self.mPlugins[key]["homepage"] = plugin["homepage"]
                     if plugin["url"]:
                         self.mPlugins[key]["url"] = plugin["url"]
                 # set status
                 #
                 # installed   available   status
                 # ---------------------------------------
                 # none        any         "not installed" (will be later checked if is "new")
                 # any         none        "orphan"
                 # same        same        "installed"
                 # less        greater     "upgradeable"
                 # greater     less        "newer"
                 if not self.mPlugins[key]["version_avail"]:
                     self.mPlugins[key]["status"] = "orphan"
                 elif self.mPlugins[key]["error"] in [
                         "broken", "dependent"
                 ]:
                     self.mPlugins[key]["status"] = "installed"
                 elif not self.mPlugins[key]["version_inst"]:
                     self.mPlugins[key]["status"] = "not installed"
                 elif compareVersions(
                         self.mPlugins[key]["version_avail"],
                         self.mPlugins[key]["version_inst"]) == 0:
                     self.mPlugins[key]["status"] = "installed"
                 elif compareVersions(
                         self.mPlugins[key]["version_avail"],
                         self.mPlugins[key]["version_inst"]) == 1:
                     self.mPlugins[key]["status"] = "upgradeable"
                 else:
                     self.mPlugins[key]["status"] = "newer"
     self.markNews()
예제 #15
0
    def xmlDownloaded(self, nr, state):
        """ populate the plugins object with the fetched data """
        if not self.httpId.has_key(nr):
            return
        reposName = self.httpId[nr]
        if state:  # fetching failed
            self.mRepositories[reposName]["state"] = 3
            self.mRepositories[reposName]["error"] = self.mRepositories[
                reposName]["QPHttp"].errorString()
        else:
            repoData = self.mRepositories[reposName]["xmlData"]
            reposXML = QDomDocument()
            reposXML.setContent(repoData.data())
            pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
            if pluginNodes.size():
                for i in range(pluginNodes.size()):
                    fileName = pluginNodes.item(i).firstChildElement(
                        "file_name").text().simplified()
                    if not fileName:
                        fileName = QFileInfo(
                            pluginNodes.item(i).firstChildElement(
                                "download_url").text().trimmed().split("?")
                            [0]).fileName()
                    name = fileName.section(".", 0, 0)
                    name = unicode(name)
                    experimental = False
                    if pluginNodes.item(i).firstChildElement(
                            "experimental").text().simplified().toUpper() in [
                                "TRUE", "YES"
                            ]:
                        experimental = True
                    plugin = {
                        "name":
                        pluginNodes.item(i).toElement().attribute("name"),
                        "version_avail":
                        pluginNodes.item(i).toElement().attribute("version"),
                        "desc_repo":
                        pluginNodes.item(i).firstChildElement(
                            "description").text().simplified(),
                        "desc_local":
                        "",
                        "author":
                        pluginNodes.item(i).firstChildElement(
                            "author_name").text().simplified(),
                        "homepage":
                        pluginNodes.item(i).firstChildElement(
                            "homepage").text().simplified(),
                        "url":
                        pluginNodes.item(i).firstChildElement(
                            "download_url").text().simplified(),
                        "experimental":
                        experimental,
                        "filename":
                        fileName,
                        "status":
                        "not installed",
                        "error":
                        "",
                        "error_details":
                        "",
                        "version_inst":
                        "",
                        "repository":
                        reposName,
                        "localdir":
                        name,
                        "read-only":
                        False
                    }
                    qgisMinimumVersion = pluginNodes.item(i).firstChildElement(
                        "qgis_minimum_version").text().simplified()
                    if not qgisMinimumVersion: qgisMinimumVersion = "0"
                    # please use the tag below only if really needed! (for example if plugin development is abandoned)
                    qgisMaximumVersion = pluginNodes.item(i).firstChildElement(
                        "qgis_maximum_version").text().simplified()
                    if not qgisMaximumVersion: qgisMaximumVersion = "2"
                    #if compatible, add the plugin to the list
                    if not pluginNodes.item(i).firstChildElement(
                            "disabled").text().simplified().toUpper() in [
                                "TRUE", "YES"
                            ]:
                        if compareVersions(
                                QGIS_VER,
                                qgisMinimumVersion) < 2 and compareVersions(
                                    qgisMaximumVersion, QGIS_VER) < 2:
                            if QGIS_VER[0] == qgisMinimumVersion[0] or (
                                    qgisMinimumVersion != "0"
                                    and qgisMaximumVersion != "2"
                            ):  # to be deleted
                                #add the plugin to the cache
                                plugins.addFromRepository(plugin)
            # set state=2, even if the repo is empty
            self.mRepositories[reposName]["state"] = 2

        self.emit(SIGNAL("repositoryFetched(QString)"), reposName)

        # is the checking done?
        if not self.fetchingInProgress():
            plugins.rebuild()
            self.saveCheckingOnStartLastDate()
            self.emit(SIGNAL("checkingDone()"))