Skip to content
Permalink
Browse files

Remove the support for reading python plugin metadata from __init__.py

From now on, plugins must have metadata.txt file (with INI format)
that is used for storing of metadata. This has two advantages:
- plugins do not need to be loaded in order to read metadata
- repository can parse the metadata more easily
  • Loading branch information
wonder-sk committed Mar 18, 2013
1 parent 41dc754 commit 32de07dc4d7f3cd52128bccb53dd5660ccc9da4b
@@ -9,7 +9,7 @@ PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)
SET(INSTALLER_FILES ${INSTALLER_FILES} ${PYUI_FILES} ${PYRC_FILES})

#INSTALL(FILES ${INSTALLER_FILES} DESTINATION ${QGIS_DATA_DIR}/python/plugins/GdalTools)
PLUGIN_INSTALL(GdalTools . ${INSTALLER_FILES} __init__.py)
PLUGIN_INSTALL(GdalTools . ${INSTALLER_FILES} __init__.py metadata.txt)

ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(icons)
@@ -17,18 +17,6 @@
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""
def name():
return "GdalTools"
def description():
return "Integrate gdal tools into qgis"
def category():
return "Raster"
def version():
return "Version 1.2.29"
def qgisMinimumVersion():
return "1.0"
def icon():
return "icons/raster-info.png"
def classFactory(iface):
# load GdalTools class from file GdalTools
from GdalTools import GdalTools
@@ -8,5 +8,5 @@ FILE(GLOB UI_FILES ui/*.ui)
PYQT4_WRAP_UI(PYUI_FILES ${UI_FILES})
PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)

PLUGIN_INSTALL(db_manager . ${OTHER_FILES} ${PY_FILES} ${PYRC_FILES})
PLUGIN_INSTALL(db_manager . ${OTHER_FILES} ${PY_FILES} ${PYRC_FILES} metadata.txt)
PLUGIN_INSTALL(db_manager ui ${PYUI_FILES} ui/__init__.py)
@@ -20,24 +20,6 @@
***************************************************************************/
"""

def name():
return "DB Manager"

def description():
return "Manage your databases within QGis"

def version():
return "0.1.20"

def qgisMinimumVersion():
return "1.5.0"

def icon():
return "icons/dbmanager.png"

def authorName():
return "Giuseppe Sucameli"

def classFactory(iface):
from .db_manager_plugin import DBManagerPlugin
return DBManagerPlugin(iface)
@@ -5,7 +5,7 @@ PYQT4_ADD_RESOURCES(PYRC_FILES resources.qrc)

SET(INSTALLER_FILES ${INSTALLER_FILES} ${PYUI_FILES} ${PYRC_FILES})

PLUGIN_INSTALL(fTools . ${INSTALLER_FILES} __init__.py)
PLUGIN_INSTALL(fTools . ${INSTALLER_FILES} __init__.py metadata.txt)

ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(icons)
@@ -28,27 +28,6 @@
#
#---------------------------------------------------------------------

def name():
return "fTools"

def description():
return "Tools for vector data analysis and management"

def category():
return "Vector"

def version():
return "0.6.2"

def qgisMinimumVersion():
return "1.4"

def icon():
return "icons/logo_small.png"

def authorName():
return "Carson J. Q. Farmer"

def classFactory( iface ):
from .fTools import fToolsPlugin
return fToolsPlugin( iface )
@@ -1,4 +1,5 @@
SET(INSTALLER_FILES
metadata.txt
mapserver_export.png
__init__.py
mapserverexportdialog.py
@@ -19,20 +19,6 @@
This script initializes the plugin, making it known to QGIS.
"""

def name():
return "MapServer Export"
def description():
return "Export a saved QGIS project file to a MapServer map file"
def category():
return "Web"
def version():
return "Version 0.4.4"
def qgisMinimumVersion():
return "1.0"
def icon():
return "mapserver_export.png"
def authorName():
return "Gary E. Sherman"
def classFactory(iface):
# load MapServerExport class from file mapserverexport.py
from mapserverexport import MapServerExport
@@ -1,4 +1,5 @@
SET(INSTALLER_FILES
metadata.txt
__init__.py
installer_data.py
installer_gui.py
@@ -11,30 +11,6 @@
* *
***************************************************************************/
"""
def name():
return "Plugin Installer"

def version():
return "Version 1.2.1"

def description():
return "Downloads and installs QGIS python plugins"

def category():
return "Plugins"

def qgisMinimumVersion():
return "1.0"

def icon():
import resources_rc
return ":/plugins/installer/plugin_installer.png"

def authorName():
return "Matthew Perry, Borys Jurgiel"

def homepage():
return "http://bwj.aster.net.pl/qgis/"

def classFactory(iface):
from installer_plugin import InstallerPlugin
@@ -119,21 +119,25 @@ 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) )
if not os.path.isdir(plugin):
continue
if not os.path.exists(os.path.join(plugin, '__init__.py')):
continue

metadataFile = os.path.join(plugin, 'metadata.txt')
if not os.path.exists(metadataFile):
continue

cp = ConfigParser.ConfigParser()
res = cp.read(metadataFile)
if len(res) == 0:
return None # reading of metadata file failed

pluginName = os.path.basename(plugin)
plugins.append( (pluginName, cp) )

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 """
@@ -142,10 +146,10 @@ def updateAvailablePlugins():
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
pluginName = p[0]
if pluginName not in plugins:
plugins.append(pluginName)
metadata_parser[pluginName] = p[1]

global available_plugins
available_plugins = plugins
@@ -154,14 +158,13 @@ def updateAvailablePlugins():


def pluginMetadata(packageName, fct):
""" fetch metadata from a plugin """

# use values from metadata.txt
if plugins_metadata_parser.has_key(packageName):
""" fetch metadata from a plugin - use values from metadata.txt """
try:
return plugins_metadata_parser[packageName].get('general', fct)
else:
except Exception:
return "__error__"


def loadPlugin(packageName):
""" load plugin's package """

@@ -250,6 +250,8 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
// if plugin is not compatible, disable it
if ( ! isPythonPluginCompatible( packageName ) )
{
QgsMessageLog::logMessage( QObject::tr("Plugin \"%1\" is not compatible with this version of Quantum GIS.\nIt will be disabled.").arg( packageName ),
QObject::tr( "Plugins" ) );
settings.setValue( "/PythonPlugins/" + packageName, false );
return;
}
@@ -496,28 +498,20 @@ bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )

bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
{
// import plugin's package
if ( !mPythonUtils->loadPlugin( packageName ) )
return false;

QString pluginName, description, category, version;
QString pluginName, description, /*category,*/ version;

// get information from the plugin
// if there are some problems, don't continue with metadata retreival
pluginName = mPythonUtils->getPluginMetadata( packageName, "name" );
if ( pluginName != "__error__" )
{
description = mPythonUtils->getPluginMetadata( packageName, "description" );
if ( description != "__error__" )
version = mPythonUtils->getPluginMetadata( packageName, "version" );
// for Python plugins category still optional, by default used "Plugins" category
//category = mPythonUtils->getPluginMetadata( packageName, "category" );
}
pluginName = mPythonUtils->getPluginMetadata( packageName, "name" );
description = mPythonUtils->getPluginMetadata( packageName, "description" );
version = mPythonUtils->getPluginMetadata( packageName, "version" );
// for Python plugins category still optional, by default used "Plugins" category
//category = mPythonUtils->getPluginMetadata( packageName, "category" );

if ( pluginName == "__error__" || description == "__error__" || version == "__error__" )
{
QMessageBox::warning( mQgisInterface->mainWindow(), QObject::tr( "Python error" ),
QObject::tr( "Error when reading metadata of plugin %1" ).arg( packageName ) );
QgsMessageLog::logMessage( QObject::tr( "Error when reading metadata of plugin %1" ).arg( packageName ),
QObject::tr( "Plugins" ) );
return false;
}

@@ -527,15 +521,7 @@ bool QgsPluginRegistry::checkPythonPlugin( QString packageName )
bool QgsPluginRegistry::isPythonPluginCompatible( QString packageName )
{
QString minVersion = mPythonUtils->getPluginMetadata( packageName, "qgisMinimumVersion" );
if ( minVersion == "__error__" || !checkQgisVersion( minVersion ) )
{
//QMessageBox::information(mQgisInterface->mainWindow(),
// QObject::tr("Incompatible plugin"),
// QObject::tr("Plugin \"%1\" is not compatible with this version of Quantum GIS.\nIt will be disabled.").arg(pluginName));
//settings.setValue( "/PythonPlugins/" + packageName, false );
return false;
}
return true;
return minVersion != "__error__" && checkQgisVersion( minVersion );
}

QList<QgsPluginMetadata*> QgsPluginRegistry::pluginData()

0 comments on commit 32de07d

Please sign in to comment.
You can’t perform that action at this time.