Skip to content

Commit

Permalink
[FEATURE] Allow plugin metadata to be in metadata.txt
Browse files Browse the repository at this point in the history
Until now plugins' metadata were always retrieved from __init__.py 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 __init__.py - if the text file is
present, it is used to fetch the values. From QGIS 2.0 the metadata from __init__.py
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:

[general]
name=PostGIS manager
description=Manage your PostGIS database
version=Version 0.5.15
icon=icons/postgis_elephant.png
qgisMinimumVersion=1.0.0
  • Loading branch information
wonder-sk committed Nov 9, 2011
1 parent b9d26e4 commit be9bdeb
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion python/utils.py
Expand Up @@ -11,7 +11,7 @@
import glob
import os.path
import re

import ConfigParser

#######################
# ERROR HANDLING
Expand Down Expand Up @@ -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, '__init__.py')):
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 = cp.read(metadataFile)
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:
plugins.append(p)
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:
# 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 __init__.py
package = sys.modules[packageName]
return getattr(package, fct)()
except:
Expand Down

0 comments on commit be9bdeb

Please sign in to comment.