Skip to content
Browse files
[FEATURE] Allow plugin metadata to be in metadata.txt
Until now plugins' metadata were always retrieved from by calling python methods.
Reading metadata from a text file has the advantage of not requiring to load the plugin code
and can be done by plugin repository.

Metadata in metadata.txt is preferred to the methods in - if the text file is
present, it is used to fetch the values. From QGIS 2.0 the metadata from
will not be accepted - the metadata.txt file will be required.

Plugin metadata should be in INI file format, recognized by python's ConfigParser module
and by Qt's QSettings class.

All currently used metadata should be in [general] section. Example use:

name=PostGIS manager
description=Manage your PostGIS database
version=Version 0.5.15
  • Loading branch information
wonder-sk committed Nov 9, 2011
1 parent b9d26e4 commit be9bdeb
Showing 1 changed file with 27 additions and 1 deletion.
@@ -11,7 +11,7 @@
import glob
import os.path
import re

import ConfigParser

@@ -72,29 +72,55 @@ def initInterface(pointer):
# list of plugins in plugin directory and home plugin directory
available_plugins = []

# dictionary of plugins providing metadata in a text file (metadata.txt)
# key = plugin package name, value = config parser instance
plugins_metadata_parser = {}

def findPlugins(path):
""" for internal use: return list of plugins in given path """
plugins = []
for plugin in glob.glob(path + "/*"):
if os.path.isdir(plugin) and os.path.exists(os.path.join(plugin, '')):
plugins.append( os.path.basename(plugin) )
return plugins

def _checkMetadataFile(pluginpath, plugin):
""" Check whether there exists a metadata.txt file.
That is now a preferred way to store plugin's metadata """
metadataFile = os.path.join(pluginpath, plugin, 'metadata.txt')
if not os.path.exists(metadataFile):
return None
cp = ConfigParser.ConfigParser()
res =
if len(res) == 0:
return None # reading of metadata file failed
return cp

def updateAvailablePlugins():
""" go thrgouh the plugin_paths list and find out what plugins are available """
# merge the lists
plugins = []
metadata_parser = {}
for pluginpath in plugin_paths:
for p in findPlugins(pluginpath):
if p not in plugins:
cp = _checkMetadataFile(pluginpath, p)
if cp: metadata_parser[p] = cp

global available_plugins
available_plugins = plugins
global plugins_metadata_parser
plugins_metadata_parser = metadata_parser

def pluginMetadata(packageName, fct):
""" fetch metadata from a plugin """
# try to use values from metadata.txt if available
if plugins_metadata_parser.has_key(packageName):
return plugins_metadata_parser[packageName].get('general', fct)
# otherwise fall back to old method, using
package = sys.modules[packageName]
return getattr(package, fct)()

0 comments on commit be9bdeb

Please sign in to comment.