Skip to content

Commit f2608b3

Browse files
committedNov 26, 2014
Added serve python plugins
1 parent 98cab97 commit f2608b3

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed
 

‎python/utils.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def initInterface(pointer):
9797
global iface
9898
iface = wrapinstance(pointer, QgisInterface)
9999

100-
101100
#######################
102101
# PLUGINS
103102

@@ -208,7 +207,7 @@ def startPlugin(packageName):
208207
plugins[packageName] = package.classFactory(iface)
209208
except:
210209
_unloadPluginModules(packageName)
211-
msg = QCoreApplication.translate("Python", "%s due an error when calling its classFactory() method") % errMsg
210+
msg = QCoreApplication.translate("Python", "%s due to an error when calling its classFactory() method") % errMsg
212211
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
213212
return False
214213

@@ -218,7 +217,7 @@ def startPlugin(packageName):
218217
except:
219218
del plugins[packageName]
220219
_unloadPluginModules(packageName)
221-
msg = QCoreApplication.translate("Python", "%s due an error when calling its initGui() method" ) % errMsg
220+
msg = QCoreApplication.translate("Python", "%s due to an error when calling its initGui() method" ) % errMsg
222221
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
223222
return False
224223

@@ -447,6 +446,57 @@ def wrapper(func):
447446
return f
448447
return wrapper
449448

449+
#######################
450+
# SERVER PLUGINS
451+
#
452+
# TODO: move into server_utils.py ?
453+
454+
# list of plugin paths. it gets filled in by the QGIS python library
455+
server_plugin_paths = []
456+
457+
# dictionary of plugins
458+
server_plugins = {}
459+
460+
# list of active (started) plugins
461+
server_active_plugins = []
462+
463+
464+
# initialize 'serverIface' object
465+
serverIface = None
466+
467+
def initServerInterface(pointer):
468+
from qgis.server import QgsServerInterface
469+
from sip import wrapinstance
470+
global serverIface
471+
serverIface = wrapinstance(pointer, QgsServerInterface)
472+
473+
474+
475+
def startServerPlugin(packageName):
476+
""" initialize the plugin """
477+
global server_plugins, server_active_plugins, serverIface
478+
479+
if packageName in server_active_plugins: return False
480+
if packageName not in sys.modules: return False
481+
482+
package = sys.modules[packageName]
483+
484+
errMsg = QCoreApplication.translate("Python", "Couldn't load server plugin %s" ) % packageName
485+
486+
# create an instance of the plugin
487+
try:
488+
server_plugins[packageName] = package.serverClassFactory(serverIface)
489+
except:
490+
_unloadPluginModules(packageName)
491+
msg = QCoreApplication.translate("Python", "%s due to an error when calling its serverClassFactory() method") % errMsg
492+
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
493+
return False
494+
495+
# add to active plugins
496+
server_active_plugins.append(packageName)
497+
return True
498+
499+
450500
#######################
451501
# IMPORT wrapper
452502

0 commit comments

Comments
 (0)
Please sign in to comment.