32
32
import ConfigParser
33
33
import qgis .utils
34
34
from qgis .core import *
35
- from qgis .utils import iface
35
+ from qgis .utils import iface , plugin_paths
36
36
from version_compare import compareVersions , normalizeVersion , isCompatible
37
37
38
38
"""
@@ -563,7 +563,7 @@ def removeRepository(self, repo):
563
563
564
564
565
565
# ----------------------------------------- #
566
- def getInstalledPlugin (self , key , readOnly , testLoad = True ):
566
+ def getInstalledPlugin (self , key , path , readOnly , testLoad = True ):
567
567
""" get the metadata of an installed plugin """
568
568
def metadataParser (fct ):
569
569
""" plugin metadata parser reimplemented from qgis.utils
@@ -590,11 +590,6 @@ def pluginMetadata(fct):
590
590
if value : return value
591
591
return metadataParser ( fct )
592
592
593
- if readOnly :
594
- path = QDir .cleanPath ( QgsApplication .pkgDataPath () ) + "/python/plugins/" + key
595
- else :
596
- path = QDir .cleanPath ( QgsApplication .qgisSettingsDirPath () ) + "/python/plugins/" + key
597
-
598
593
if not QDir (path ).exists ():
599
594
return
600
595
@@ -681,39 +676,38 @@ def pluginMetadata(fct):
681
676
def getAllInstalled (self , testLoad = True ):
682
677
""" Build the localCache """
683
678
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 )
717
711
718
712
719
713
# ----------------------------------------- #
0 commit comments