Skip to content

Commit

Permalink
Remove the support for reading python plugin metadata from __init__.py
Browse files Browse the repository at this point in the history
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 32de07d
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 139 deletions.
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 0 additions & 12 deletions python/plugins/GdalTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 0 additions & 18 deletions python/plugins/db_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion python/plugins/fTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions python/plugins/fTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions python/plugins/mapserver_export/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET(INSTALLER_FILES
metadata.txt
mapserver_export.png
__init__.py
mapserverexportdialog.py
Expand Down
14 changes: 0 additions & 14 deletions python/plugins/mapserver_export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions python/plugins/plugin_installer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET(INSTALLER_FILES
metadata.txt
__init__.py
installer_data.py
installer_gui.py
Expand Down
24 changes: 0 additions & 24 deletions python/plugins/plugin_installer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 25 additions & 22 deletions python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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
Expand All @@ -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 """

Expand Down
36 changes: 11 additions & 25 deletions src/app/qgspluginregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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()
Expand Down

0 comments on commit 32de07d

Please sign in to comment.