Skip to content
Permalink
Browse files
Plugin Installer update: cleaning and smarter error handling
git-svn-id: http://svn.osgeo.org/qgis/trunk@9634 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty committed Nov 13, 2008
1 parent bf87209 commit 5f9d23c4931c8aa08eb5c49127fa3607af5017eb
@@ -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
@@ -141,8 +141,10 @@ QgsPluginInstallerDialog::foo()
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 @@ QgsPluginInstallerDialog::foo()
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 @@ QgsPluginInstallerDialog::foo()
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
@@ -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 @@ def xmlDownloaded(self,nr,state):
"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 @@ def updatePlugin(self, key, readOnly):
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 @@ def updatePlugin(self, key, readOnly):
"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 @@ def updatePlugin(self, key, readOnly):
# 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"
@@ -227,7 +227,7 @@ def abort(self):
self.http.abort()
self.mResult = self.tr("Aborted by user")
self.reject()
# --- /class QgsPluginInstallerPluginErrorDialog ------------------------------------------------------------- #
# --- /class QgsPluginInstallerInstallingDialog ------------------------------------------------------------- #



@@ -248,7 +248,6 @@ def __init__(self, parent, errorMessage):




# --- class QgsPluginInstallerDialog ------------------------------------------------------------------------- #
class QgsPluginInstallerDialog(QDialog, Ui_QgsPluginInstallerDialogBase):
# ----------------------------------------- #
@@ -390,17 +389,19 @@ def populatePluginTree(self):
"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"),
"orphan" : self.tr("installed", "singular"),
"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,10 +437,13 @@ def addItem(p):
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"]
@@ -535,54 +539,81 @@ def installPlugin(self):
""" 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 @@ def uninstallPlugin(self):
#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 @@ def uninstallPlugin(self):
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"))


0 comments on commit 5f9d23c

Please sign in to comment.