[QGIS Commit] r9634 - trunk/qgis/python/plugins/plugin_installer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Nov 13 16:14:53 EST 2008


Author: borysiasty
Date: 2008-11-13 16:14:53 -0500 (Thu, 13 Nov 2008)
New Revision: 9634

Modified:
   trunk/qgis/python/plugins/plugin_installer/__init__.py
   trunk/qgis/python/plugins/plugin_installer/i18n.cpp
   trunk/qgis/python/plugins/plugin_installer/installer_data.py
   trunk/qgis/python/plugins/plugin_installer/installer_gui.py
Log:
Plugin Installer update: cleaning and smarter error handling

Modified: trunk/qgis/python/plugins/plugin_installer/__init__.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/__init__.py	2008-11-13 11:19:01 UTC (rev 9633)
+++ trunk/qgis/python/plugins/plugin_installer/__init__.py	2008-11-13 21:14:53 UTC (rev 9634)
@@ -13,14 +13,20 @@
 def name():
   return "Plugin Installer"
 
+def version():
+  return "Version 0.9.2"
+
 def description():
   return "Downloads and installs QGIS python plugins"
 
-def author_name():
+def qgisMinimumVersion():
+  return "0.9"
+
+def authorName():
   return "perrygeo, borysiasty"
 
-def version():
-  return "Version 0.9.1"
+def homepage():
+  return "http://bwj.aster.net.pl/qgis/"
 
 def classFactory(iface):
   from installer_plugin import InstallerPlugin

Modified: trunk/qgis/python/plugins/plugin_installer/i18n.cpp
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/i18n.cpp	2008-11-13 11:19:01 UTC (rev 9633)
+++ trunk/qgis/python/plugins/plugin_installer/i18n.cpp	2008-11-13 21:14:53 UTC (rev 9634)
@@ -141,8 +141,10 @@
   tr("This plugin is installed, but I can't find it in any enabled repository")
   tr("This plugin is not installed and is seen for the first time")
   tr("This plugin is installed and is newer than its version available in a repository")
-  tr("This plugin is incompatible and probably won't work with your Quantum GIS version")
-  tr("This plugin probably depends on some components missing in your system\nIt has been installed, but can't be loaded")
+  tr("This plugin is incompatible with your Quantum GIS version and probably won't work")
+  tr("The Python module is missing on your system.\nFor more information, please visit its homepage")
+  tr("This plugin seems to be broken\nIt has been installed, but can't be loaded")
+
   tr("not installed", "singular")
   tr("installed", "singular")
   tr("upgradeable", "singular")
@@ -158,8 +160,9 @@
   tr("That's the newest available version")
   tr("installed version")
   tr("There is no version available for download")
-  tr("This plugin is invalid or has unfulfilled dependencies")
-  tr("This plugin is designed for a higher version of Quantum GIS")
+  tr("This plugin is broken")
+  tr("This plugin requires a newer version of Quantum GIS")
+  tr("This plugin requires a missing module")
   tr("only locally available")
 
  // def treeClicked
@@ -180,8 +183,11 @@
   tr("The plugin seems to have been installed but I don't know where. Probably the plugin package contained a wrong named directory.\nPlease search the list of installed plugins. I'm nearly sure you'll find the plugin there, but I just can't determine which of them it is. It also means that I won't be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue.")
   tr("Plugin installed successfully")
   tr("Python plugin installed.\nYou have to enable it in the Plugin Manager.")
-  tr("Plugin installed successfully")
+  tr("Plugin reinstalled successfully")
   tr("Python plugin reinstalled.\nYou have to restart Quantum GIS to reload it.")
+  tr("The plugin is designed for a newer version of Quantum GIS. The minimum required version is:")
+  tr("The plugin depends on some components missing on your system. Please install the following Python module:")
+  tr("The plugin is broken. Python said:")
   tr("Plugin uninstall failed")
 
  // def uninstallPlugin

Modified: trunk/qgis/python/plugins/plugin_installer/installer_data.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/installer_data.py	2008-11-13 11:19:01 UTC (rev 9633)
+++ trunk/qgis/python/plugins/plugin_installer/installer_data.py	2008-11-13 21:14:53 UTC (rev 9634)
@@ -39,7 +39,8 @@
                                 "desc_local" string,
                                 "author" string,
                                 "status" string,      ("not installed", "installed", "upgradeable", "orphan", "new", "newer")
-                                "error" string,       ("", "broken", "incompatible" )
+                                "error" string,       ("", "broken", "incompatible", "dependent")
+                                "error_details" string,
                                 "homepage" string,
                                 "url" string,
                                 "filename" string,
@@ -51,7 +52,10 @@
 
 try:
   QGIS_VER = QGis.qgisVersion
-  QGIS_MAJOR_VER = 0
+  if QGIS_VER[0] == "1":
+    QGIS_MAJOR_VER = 1
+  else:
+    QGIS_MAJOR_VER = 0
 except:
   QGIS_VER = QGis.QGIS_VERSION
   QGIS_MAJOR_VER = 1
@@ -302,6 +306,7 @@
             "filename"      : pluginNodes.item(i).firstChildElement("file_name").text().trimmed(),
             "status"        : "not installed",
             "error"         : "",
+            "error_details" : "",
             "version_inst"  : "",
             "repository"    : reposName,
             "localdir"      : name,
@@ -391,47 +396,63 @@
     path = QDir.cleanPath(unicode(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:
-        nam = ""
+        pass
       try:
         exec("ver = %s.version()" % key)
       except:
-        ver = ""
+        pass
       try:
         exec("desc = %s.description()" % key)
       except:
-        desc = ""
+        pass
       try:
-        exec("auth = %s.author_name()" % key)
+        exec("auth = %s.authorName()" % key)
       except:
-        auth = ""
+        pass
       try:
         exec("homepage = %s.homepage()" % key)
       except:
-        homepage = ""
+        pass
       try:
         exec("qgisMinimumVersion = %s.qgisMinimumVersion()" % key)
         if compareVersions(QGIS_VER, qgisMinimumVersion) == 2:
           error = "incompatible"
-        else:
-          error = ""
+          errorDetails = qgisMinimumVersion
       except:
-        error = ""
-    except:
-      nam   = key
-      ver   = ""
-      desc  = ""
-      auth  = ""
-      homepage  = ""
+        pass
+      #try:
+      #  exec ("%s.classFactory(QgisInterface)" % key)
+      #except Exception, error:
+      #  error = error.message
+    except Exception, error:
+      error = error.message
+
+    if not nam:
+      nam = key
+    if error[:16] == "No module named ":
+      mona = error.replace("No module named ","")
+      if mona != key:
+        error = "dependent"
+        errorDetails = mona
+    if not error in ["", "dependent", "incompatible"]:
+      errorDetails = error
       error = "broken"
-    normVer = normalizeVersion(ver)
+
     plugin = {
         "name"          : nam,
-        "version_inst"  : normVer,
+        "version_inst"  : normalizeVersion(ver),
         "version_avail" : "",
         "desc_local"    : desc,
         "desc_repo"     : "",
@@ -441,16 +462,19 @@
         "filename"      : "",
         "status"        : "",
         "error"         : error,
+        "error_details" : errorDetails,
         "repository"    : "",
         "localdir"      : key,
         "read-only"     : readOnly}
+
     if not self.mPlugins.has_key(key):
       self.mPlugins[key] = plugin   # just add a new plugin
     else:
       self.mPlugins[key]["localdir"] = plugin["localdir"]
       self.mPlugins[key]["read-only"] = plugin["read-only"]
       self.mPlugins[key]["error"] = plugin["error"]
-      if plugin["name"]:
+      self.mPlugins[key]["error_details"] = plugin["error_details"]
+      if plugin["name"] and plugin["name"] != key:
         self.mPlugins[key]["name"] = plugin["name"] # local name has higher priority
       self.mPlugins[key]["version_inst"] = plugin["version_inst"]
       self.mPlugins[key]["desc_local"] = plugin["desc_local"]
@@ -465,7 +489,7 @@
     # greater     less        "newer"
     if not self.mPlugins[key]["version_avail"]:
       self.mPlugins[key]["status"] = "orphan"
-    elif self.mPlugins[key]["error"] == "broken":
+    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"

Modified: trunk/qgis/python/plugins/plugin_installer/installer_gui.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/installer_gui.py	2008-11-13 11:19:01 UTC (rev 9633)
+++ trunk/qgis/python/plugins/plugin_installer/installer_gui.py	2008-11-13 21:14:53 UTC (rev 9634)
@@ -227,7 +227,7 @@
     self.http.abort()
     self.mResult = self.tr("Aborted by user")
     self.reject()
-# --- /class QgsPluginInstallerPluginErrorDialog ------------------------------------------------------------- #
+# --- /class QgsPluginInstallerInstallingDialog ------------------------------------------------------------- #
 
 
 
@@ -248,7 +248,6 @@
 
 
 
- 
 # --- class QgsPluginInstallerDialog ------------------------------------------------------------------------- #
 class QgsPluginInstallerDialog(QDialog, Ui_QgsPluginInstallerDialogBase):
   # ----------------------------------------- #
@@ -390,8 +389,9 @@
             "orphan" : self.tr("This plugin is installed, but I can't find it in any enabled repository"),
             "new" : self.tr("This plugin is not installed and is seen for the first time"),
             "newer" : self.tr("This plugin is installed and is newer than its version available in a repository"),
-            "incompatible" : self.tr("This plugin is incompatible and probably won't work with your Quantum GIS version"),
-            "broken" : self.tr("This plugin probably depends on some components missing in your system\nIt has been installed, but can't be loaded")}
+            "incompatible" : self.tr("This plugin is incompatible with your Quantum GIS version and probably won't work"),
+            "dependent" : self.tr("The Python module is missing on your system.\nFor more information, please visit its homepage"),
+            "broken" : self.tr("This plugin seems to be broken\nIt has been installed, but can't be loaded")}
     statuses ={"not installed" : self.tr("not installed", "singular"),
             "installed" : self.tr("installed", "singular"),
             "upgradeable" : self.tr("upgradeable", "singular"),
@@ -399,8 +399,9 @@
             "new" : self.tr("new!", "singular"),
             "newer" : self.tr("installed", "singular"),
             "incompatible" : self.tr("invalid", "singular"),
+            "dependent" : self.tr("invalid", "singular"),
             "broken" : self.tr("invalid", "singular")}
-    orderInvalid = ["incompatible","broken"]
+    orderInvalid = ["incompatible","broken","dependent"]
     orderValid = ["upgradeable","new","not installed","installed","orphan","newer"]
     def addItem(p):
       if self.filterCheck(p):
@@ -436,11 +437,14 @@
         else:
           verTip = ""
         if p["error"] == "broken":
-          desc = self.tr("This plugin is invalid or has unfulfilled dependencies")
+          desc = self.tr("This plugin is broken")
           descTip = statusTips[p["error"]]
         elif p["error"] == "incompatible":
-          desc = self.tr("This plugin is designed for a higher version of Quantum GIS")
+          desc = self.tr("This plugin requires a newer version of Quantum GIS") + " (" + self.tr("at least")+ " " + p["error_details"] + ")"
           descTip = statusTips[p["error"]]
+        elif p["error"] == "dependent":
+          desc = self.tr("This plugin requires a missing module") + " (" + p["error_details"] + ")"
+          descTip = statusTips[p["error"]]
         else:
           desc = p["desc_local"]
           descTip = p["desc_repo"]
@@ -535,54 +539,81 @@
     """ install currently selected plugin """
     if not self.treePlugins.currentItem():
       return
+    infoString = ('','')
     key = plugins.keyByUrl(self.treePlugins.currentItem().toolTip(5))
     plugin = plugins.all()[key]
+    previousStatus = plugin["status"]
     if not plugin:
       return
-
-    if plugin["status"] == "newer":
+    if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin
       if QMessageBox.warning(self, self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
         return
-
     dlg = QgsPluginInstallerInstallingDialog(self,plugin)
     dlg.exec_()
 
     if dlg.result():
       infoString = (self.tr("Plugin installation failed"), dlg.result())
+    elif not QDir(QDir.cleanPath(QgsApplication.qgisSettingsDirPath() + "/python/plugins/" + key)).exists():
+      infoString = (self.tr("Plugin has disappeared"), self.tr("The plugin seems to have been installed but I don't know where. Probably the plugin package contained a wrong named directory.\nPlease search the list of installed plugins. I'm nearly sure you'll find the plugin there, but I just can't determine which of them it is. It also means that I won't be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue."))
+      QApplication.setOverrideCursor(Qt.WaitCursor)
+      self.getAllAvailablePlugins()
+      QApplication.restoreOverrideCursor()
     else:
-      path = QDir.cleanPath(QgsApplication.qgisSettingsDirPath() + "/python/plugins/" + key)
-      if not QDir(path).exists():
-        infoString = (self.tr("Plugin has disappeared"), self.tr("The plugin seems to have been installed but I don't know where. Probably the plugin package contained a wrong named directory.\nPlease search the list of installed plugins. I'm nearly sure you'll find the plugin there, but I just can't determine which of them it is. It also means that I won't be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue."))
-        QApplication.setOverrideCursor(Qt.WaitCursor)
-        self.getAllAvailablePlugins()
-        QApplication.restoreOverrideCursor()
+      try:
+        exec ("sys.path_importer_cache.clear()")
+        exec ("import %s" % plugin["localdir"])
+        exec ("reload (%s)" % plugin["localdir"])
+      except:
+        pass
+      plugins.updatePlugin(key, False)
+      plugin = plugins.all()[key]
+      if not plugin["error"]:
+        if previousStatus in ["not installed", "new"]:
+          infoString = (self.tr("Plugin installed successfully"),
+          self.tr("Python plugin installed.\nYou have to enable it in the Plugin Manager."))
+        else:
+          infoString = (self.tr("Plugin reinstalled successfully"),
+          self.tr("Python plugin reinstalled.\nYou have to restart Quantum GIS to reload it."))
       else:
-        try:
-          exec ("sys.path_importer_cache.clear()")
-          exec ("del sys.modules[%s]" % plugin["localdir"]) # remove old version if exist
-        except:
-          pass
-        try:
-          exec ("import %s" % plugin["localdir"])
-          exec ("reload (%s)" % plugin["localdir"])
-          if plugin["status"] == "not installed" or plugin["status"] == "new":
-            infoString = (self.tr("Plugin installed successfully"), self.tr("Python plugin installed.\nYou have to enable it in the Plugin Manager."))
+        if plugin["error"] == "incompatible":
+          message = self.tr("The plugin is designed for a newer version of Quantum GIS. The minimum required version is:")
+          message += " <b>" + plugin["error_details"] + "</b>"
+        elif plugin["error"] == "dependent":
+          message = self.tr("The plugin depends on some components missing on your system. Please install the following Python module:")
+          message += "<b> " + plugin["error_details"] + "</b>"
+        else:
+          message = self.tr("The plugin is broken. Python said:")
+          message += "<br><b>" + plugin["error_details"] + "</b>"
+        dlg = QgsPluginInstallerPluginErrorDialog(self,message)
+        dlg.exec_()
+        if dlg.result():
+          # revert installation
+          plugins.setPluginData(key, "status", "not installed")
+          plugins.setPluginData(key, "version_inst", "")
+          plugins.setPluginData(key, "desc_local", "")
+          plugins.setPluginData(key, "error", "")
+          plugins.setPluginData(key, "error_details", "")
+          pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/"+ str(plugin["localdir"]))
+          removeDir(pluginDir)
+          if QDir(pluginDir).exists():
+            infoString = (self.tr("Plugin uninstall failed"), result)
+            try:
+              exec ("sys.path_importer_cache.clear()")
+              exec ("import %s" % plugin["localdir"])
+              exec ("reload (%s)" % plugin["localdir"])
+            except:
+              pass
+            plugins.updatePlugin(key, False)
           else:
-            infoString = (self.tr("Plugin installed successfully"),self.tr("Python plugin reinstalled.\nYou have to restart Quantum GIS to reload it."))
-        except Exception, error:
-          dlg = QgsPluginInstallerPluginErrorDialog(self,error.message)
-          dlg.exec_()
-          if dlg.result():
-            pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/"+ str(plugin["localdir"]))
-            result = removeDir(pluginDir)
-            if result:
-              QMessageBox.warning(self, self.tr("Plugin uninstall failed"), result)
-          plugins.updatePlugin(key, False)
-          self.populatePluginTree()
-          return
-        plugins.updatePlugin(key, False)
+            try:
+              exec ("del sys.modules[%s]" % plugin["localdir"])
+            except:
+              pass
+            if not plugin["repository"]:
+              plugins.remove(key)
     self.populatePluginTree()
-    QMessageBox.information(self, infoString[0], infoString[1])
+    if infoString[0]:
+      QMessageBox.information(self, infoString[0], infoString[1])
 
 
   # ----------------------------------------- #
@@ -603,7 +634,6 @@
     #print "Uninstalling plugin", plugin["name"], pluginDir
     result = removeDir(pluginDir)
     if result:
-      QApplication.restoreOverrideCursor()
       QMessageBox.warning(self, self.tr("Plugin uninstall failed"), result)
     else:
       try:
@@ -616,8 +646,9 @@
         plugins.setPluginData(key, "status", "not installed")
         plugins.setPluginData(key, "version_inst", "")
         plugins.setPluginData(key, "desc_local", "")
+        plugins.setPluginData(key, "error", "")
+        plugins.setPluginData(key, "error_details", "")
       self.populatePluginTree()
-      QApplication.restoreOverrideCursor()
       QMessageBox.information(self, self.tr("QGIS Python Plugin Installer"), self.tr("Plugin uninstalled successfully"))
 
 



More information about the QGIS-commit mailing list