Skip to content

Commit abef7a5

Browse files
committedJun 8, 2013
[Plugin Installer] Better uninstall obsolete user plugins masking more recent versions installed as core
1 parent 780301c commit abef7a5

File tree

2 files changed

+33
-143
lines changed

2 files changed

+33
-143
lines changed
 

‎python/pyplugin_installer/installer.py

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,23 @@ def __init__(self):
7171
repositories.setRepositoryData(key, "state", 3)
7272

7373
# look for obsolete plugins (the user-installed one is newer than core one)
74-
for i in plugins.obsoletePlugins:
75-
if i == "plugin_installer":
76-
# uninstall the installer itself
77-
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Plugin Installer update"), self.tr("The Plugin Installer has been updated. Please restart QGIS prior to using it"))
78-
removeDir( QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugins.localCache[i]["id"] )
79-
return
80-
else:
81-
# don't remove brutally other plugins, just inform
82-
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Plugin Conflict:")+" "+plugins.localCache[i]["name"], "<b>"+ plugins.localCache[i]["name"] + "</b><br/><br/>" + self.tr("The Plugin Installer has detected an obsolete plugin which masks a newer version shipped with this QGIS version. This is likely due to files associated with a previous installation of QGIS. Please use the Plugin Installer to remove that older plugin in order to unmask the newer version shipped with this copy of QGIS."))
74+
for key in plugins.obsoletePlugins:
75+
plugin = plugins.localCache[key]
76+
msg = QMessageBox()
77+
msg.setIcon( QMessageBox.Warning )
78+
msg.setWindowTitle( self.tr("QGIS Python Plugin Installer") )
79+
msg.addButton( self.tr("Uninstall (recommended)"), QMessageBox.AcceptRole )
80+
msg.addButton( self.tr("I will uninstall it later"), QMessageBox.RejectRole )
81+
msg.setText( "%s <b>%s</b><br/><br/>%s" % ( self.tr("Obsolete plugin:"), plugin["name"] , self.tr("QGIS has detected an obsolete plugin that masks its more recent version shipped with this copy of QGIS. This is likely due to files associated with a previous installation of QGIS. Do you want to remove the old plugin right now and unmask the more recent version?") ) )
82+
msg.exec_()
83+
if not msg.result():
84+
# uninstall, update utils and reload if enabled
85+
self.uninstallPlugin(key, quiet = True)
86+
updateAvailablePlugins()
87+
settings = QSettings()
88+
if settings.value("/PythonPlugins/"+key, False, type=bool):
89+
loadPlugin(key)
90+
startPlugin(key)
8391

8492

8593
# ----------------------------------------- #
@@ -346,35 +354,30 @@ def installPlugin(self, key, quiet=False):
346354

347355

348356
# ----------------------------------------- #
349-
def uninstallPlugin(self,key):
357+
def uninstallPlugin(self, key, quiet=False):
350358
""" Uninstall given plugin """
351-
plugin = plugins.all()[key]
359+
if plugins.all().has_key(key):
360+
plugin = plugins.all()[key]
361+
else:
362+
plugin = plugins.localCache[key]
352363
if not plugin:
353364
return
354-
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
355-
if plugin["status"] == "orphan" and not plugin["error"]:
356-
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
357-
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
358-
return
359-
# unload the plugin if it's not plugin_installer itself (otherwise, do it after removing its directory):
360-
if key != "plugin_installer":
361-
try:
362-
unloadPlugin(key)
363-
except:
364-
pass
365+
if not quiet:
366+
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
367+
if plugin["status"] == "orphan" and not plugin["error"]:
368+
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
369+
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
370+
return
371+
# unload the plugin
372+
try:
373+
unloadPlugin(key)
374+
except:
375+
pass
365376
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["id"]
366377
result = removeDir(pluginDir)
367378
if result:
368379
QMessageBox.warning(iface.mainWindow(), self.tr("Plugin uninstall failed"), result)
369380
else:
370-
# if the uninstalled plugin is the installer itself, reload it and quit
371-
if key == "plugin_installer":
372-
try:
373-
QMessageBox.information(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Plugin Installer update uninstalled. Plugin Installer will now close and revert to its primary version. You can find it in the Plugins menu and continue operation."))
374-
reloadPlugin(key)
375-
return
376-
except:
377-
pass
378381
# safe remove
379382
try:
380383
unloadPlugin(plugin["id"])

‎python/pyplugin_installer/qgsplugininstalleroldreposbase.ui

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.