Skip to content

Commit b9c9ec4

Browse files
committedJul 30, 2013
[Plugin Installer] Don't forget about plugins in QGIS-PLUGINPATH env variable. Fix #8376
1 parent 34c3b44 commit b9c9ec4

File tree

1 file changed

+34
-40
lines changed

1 file changed

+34
-40
lines changed
 

‎python/pyplugin_installer/installer_data.py

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import ConfigParser
3333
import qgis.utils
3434
from qgis.core import *
35-
from qgis.utils import iface
35+
from qgis.utils import iface, plugin_paths
3636
from version_compare import compareVersions, normalizeVersion, isCompatible
3737

3838
"""
@@ -563,7 +563,7 @@ def removeRepository(self, repo):
563563

564564

565565
# ----------------------------------------- #
566-
def getInstalledPlugin(self, key, readOnly, testLoad=True):
566+
def getInstalledPlugin(self, key, path, readOnly, testLoad=True):
567567
""" get the metadata of an installed plugin """
568568
def metadataParser(fct):
569569
""" plugin metadata parser reimplemented from qgis.utils
@@ -590,11 +590,6 @@ def pluginMetadata(fct):
590590
if value: return value
591591
return metadataParser( fct )
592592

593-
if readOnly:
594-
path = QDir.cleanPath( QgsApplication.pkgDataPath() ) + "/python/plugins/" + key
595-
else:
596-
path = QDir.cleanPath( QgsApplication.qgisSettingsDirPath() ) + "/python/plugins/" + key
597-
598593
if not QDir(path).exists():
599594
return
600595

@@ -681,39 +676,38 @@ def pluginMetadata(fct):
681676
def getAllInstalled(self, testLoad=True):
682677
""" Build the localCache """
683678
self.localCache = {}
684-
# first, try to add the readonly plugins...
685-
pluginsPath = unicode(QDir.convertSeparators(QDir.cleanPath(QgsApplication.pkgDataPath() + "/python/plugins")))
686-
# temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
687-
sys.path = [pluginsPath] + sys.path
688-
try:
689-
pluginDir = QDir(pluginsPath)
690-
pluginDir.setFilter(QDir.AllDirs)
691-
for key in pluginDir.entryList():
692-
key = unicode(key)
693-
if not key in [".",".."]:
694-
# only test those not yet loaded. Others proved they're o.k.
695-
self.localCache[key] = self.getInstalledPlugin(key, readOnly=True, testLoad=testLoad and not qgis.utils.plugins.has_key(key))
696-
except:
697-
# return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the system plugin directory")
698-
pass # it's not necessary to stop due to this error
699-
# remove the temporarily added path
700-
sys.path.remove(pluginsPath)
701-
# ...then try to add locally installed ones
702-
try:
703-
pluginDir = QDir.convertSeparators(QDir.cleanPath(QgsApplication.qgisSettingsDirPath() + "/python/plugins"))
704-
pluginDir = QDir(pluginDir)
705-
pluginDir.setFilter(QDir.AllDirs)
706-
except:
707-
return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the local plugin directory")
708-
for key in pluginDir.entryList():
709-
key = unicode(key)
710-
if not key in [".",".."]:
711-
# only test those not yet loaded. Others proved they're o.k.
712-
plugin = self.getInstalledPlugin(key, readOnly=False, testLoad=testLoad and not qgis.utils.plugins.has_key(key))
713-
if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"],plugin["version_installed"]) == 1:
714-
# An obsolete plugin in the "user" location is masking a newer one in the "system" location!
715-
self.obsoletePlugins += [key]
716-
self.localCache[key] = plugin
679+
680+
# reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
681+
pluginPaths = list(plugin_paths)
682+
pluginPaths.reverse()
683+
684+
for pluginsPath in pluginPaths:
685+
isTheSystemDir = (pluginPaths.index(pluginsPath)==0) # The curent dir is the system plugins dir
686+
if isTheSystemDir:
687+
# temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
688+
sys.path = [pluginsPath] + sys.path
689+
try:
690+
pluginDir = QDir(pluginsPath)
691+
pluginDir.setFilter(QDir.AllDirs)
692+
for key in pluginDir.entryList():
693+
if not key in [".",".."]:
694+
path = QDir.convertSeparators( pluginsPath + "/" + key )
695+
# readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
696+
readOnly = isTheSystemDir # Assume only the system plugins are not writable.
697+
# only test those not yet loaded. Loaded plugins already proved they're o.k.
698+
testLoadThis = testLoad and not qgis.utils.plugins.has_key(key)
699+
plugin = self.getInstalledPlugin(key, path=path, readOnly=readOnly, testLoad=testLoadThis)
700+
self.localCache[key] = plugin
701+
if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"],plugin["version_installed"]) == 1:
702+
# An obsolete plugin in the "user" location is masking a newer one in the "system" location!
703+
self.obsoletePlugins += [key]
704+
except:
705+
# it's not necessary to stop if one of the dirs is inaccessible
706+
pass
707+
708+
if isTheSystemDir:
709+
# remove the temporarily added path
710+
sys.path.remove(pluginsPath)
717711

718712

719713
# ----------------------------------------- #

0 commit comments

Comments
 (0)
Please sign in to comment.