|
11 | 11 | import glob
|
12 | 12 | import os.path
|
13 | 13 | import re
|
14 |
| - |
| 14 | +import ConfigParser |
15 | 15 |
|
16 | 16 | #######################
|
17 | 17 | # ERROR HANDLING
|
@@ -72,29 +72,55 @@ def initInterface(pointer):
|
72 | 72 | # list of plugins in plugin directory and home plugin directory
|
73 | 73 | available_plugins = []
|
74 | 74 |
|
| 75 | +# dictionary of plugins providing metadata in a text file (metadata.txt) |
| 76 | +# key = plugin package name, value = config parser instance |
| 77 | +plugins_metadata_parser = {} |
| 78 | + |
75 | 79 | def findPlugins(path):
|
| 80 | + """ for internal use: return list of plugins in given path """ |
76 | 81 | plugins = []
|
77 | 82 | for plugin in glob.glob(path + "/*"):
|
78 | 83 | if os.path.isdir(plugin) and os.path.exists(os.path.join(plugin, '__init__.py')):
|
79 | 84 | plugins.append( os.path.basename(plugin) )
|
80 | 85 | return plugins
|
81 | 86 |
|
| 87 | +def _checkMetadataFile(pluginpath, plugin): |
| 88 | + """ Check whether there exists a metadata.txt file. |
| 89 | + That is now a preferred way to store plugin's metadata """ |
| 90 | + metadataFile = os.path.join(pluginpath, plugin, 'metadata.txt') |
| 91 | + if not os.path.exists(metadataFile): |
| 92 | + return None |
| 93 | + cp = ConfigParser.ConfigParser() |
| 94 | + res = cp.read(metadataFile) |
| 95 | + if len(res) == 0: |
| 96 | + return None # reading of metadata file failed |
| 97 | + return cp |
| 98 | + |
82 | 99 | def updateAvailablePlugins():
|
83 | 100 | """ go thrgouh the plugin_paths list and find out what plugins are available """
|
84 | 101 | # merge the lists
|
85 | 102 | plugins = []
|
| 103 | + metadata_parser = {} |
86 | 104 | for pluginpath in plugin_paths:
|
87 | 105 | for p in findPlugins(pluginpath):
|
88 | 106 | if p not in plugins:
|
89 | 107 | plugins.append(p)
|
| 108 | + cp = _checkMetadataFile(pluginpath, p) |
| 109 | + if cp: metadata_parser[p] = cp |
90 | 110 |
|
91 | 111 | global available_plugins
|
92 | 112 | available_plugins = plugins
|
| 113 | + global plugins_metadata_parser |
| 114 | + plugins_metadata_parser = metadata_parser |
93 | 115 |
|
94 | 116 |
|
95 | 117 | def pluginMetadata(packageName, fct):
|
96 | 118 | """ fetch metadata from a plugin """
|
97 | 119 | try:
|
| 120 | + # try to use values from metadata.txt if available |
| 121 | + if plugins_metadata_parser.has_key(packageName): |
| 122 | + return plugins_metadata_parser[packageName].get('general', fct) |
| 123 | + # otherwise fall back to old method, using __init__.py |
98 | 124 | package = sys.modules[packageName]
|
99 | 125 | return getattr(package, fct)()
|
100 | 126 | except:
|
|
0 commit comments