Commit a29e342c authored by mkomm's avatar mkomm
Browse files

rpc in basic navigation plugin

parent fd125fc1
......@@ -24,7 +24,7 @@ class PXLBrowserController(AbstractController):
self.pluginConfigPathList=[]
for pluginConfig in self.pluginConfigList:
self.pluginConfigPathList.append(pluginConfig.__module__+"."+pluginConfig.__name__)
setattr(self,pluginConfig.getPluginName(),pluginConfig.getCherrypyController()())
setattr(self,pluginConfig.getPluginName(),pluginConfig.getCherrypyController()(platform,pluginConfig.getRemoteControllerClassString()))
self.pluginMethods=None
def __getReader(self, tabid, filename, eventnumber):
......
......@@ -48,7 +48,7 @@ class PXLBrowserExtension(AbstractExtension):
logging.getLogger(__name__+".plugins").error("Import plugin: "+pluginDir+", "+str(e))
pluginList = vispa.extensions.pxlbrowser.plugins.PXLBrowserPluginConfig.__subclasses__()
self.remote(os.path.join(os.path.dirname(__file__),"plugins","remote"))
self.remote(os.path.join("plugins","remote"))
for plugin in pluginList:
#---------------------------------------------------------------------------------------------------for dev
if plugin.getPluginName()=="BasicNavigation":
......@@ -56,4 +56,4 @@ class PXLBrowserExtension(AbstractExtension):
self.pluginConfigList.append(plugin)
for jsfile in plugin.getJSFiles():
platform.add_common_js(vispa.url.static(vispa.url.join("extensions","pxlbrowser","plugins",jsfile),staticdir=False))
self.remote(os.path.join(os.path.dirname(__file__),plugin.getRemoteDirectory()))
self.remote(plugin.getRemoteDirectory())
......@@ -20,10 +20,8 @@ var BasicNavigation = PxlBrowserPlugin.extend({
.button({text: false, label:"previous", icons:{primary: "ui-icon-circle-arrow-w"}})
.click(function(ev) {
_this.invoke('previous',_this.currentObjectCount,{},function(data) {
if (_this.currentObjectCount<data.eventnumber) {
_this.maxObjectCount=data.eventnumber;
}
_this.currentObjectCount=data.eventnumber;
_this.maxObjectCount=data.maxObjectCount;
_this.number.text(_this.currentObjectCount+"/"+_this.maxObjectCount);
_this.pluginManager.publishChannel("BasicNavigation_changedObjectCount",DataContainer({eventnumber:_this.currentObjectCount}));
});
......@@ -34,10 +32,8 @@ var BasicNavigation = PxlBrowserPlugin.extend({
.button({text: false, label:"next", icons:{primary:"ui-icon-circle-arrow-e"}})
.click(function(ev) {
_this.invoke('next',_this.currentObjectCount,{},function(data) {
if (_this.currentObjectCount==data.eventnumber) {
_this.maxObjectCount=data.eventnumber;
}
_this.currentObjectCount=data.eventnumber;
_this.maxObjectCount=data.maxObjectCount;
_this.number.text(_this.currentObjectCount+"/"+_this.maxObjectCount);
_this.pluginManager.publishChannel("BasicNavigation_changedObjectCount",DataContainer({eventnumber:_this.currentObjectCount}));
});
......
......@@ -3,37 +3,22 @@ import vispa
from vispa.extensions.pxlbrowser.plugins import *
class Controller(PXLBrowserPluginCherrypyController):
def __init__(self):
PXLBrowserPluginCherrypyController.__init__(self)
def __init__(self, platform, remoteControllerClassName):
PXLBrowserPluginCherrypyController.__init__(self, platform, remoteControllerClassName)
@cherrypy.expose
@cherrypy.tools.workspace()
@cherrypy.tools.user()
def next(self,pluginname, method, tabid, pluginid, filename, eventnumber,*args, **kw):
plugin = vispa.rpc.get(cherrypy.request.user, cherrypy.request.workspace, "vispa.extensions.pxlbrowser.plugins.remote.PluginManager.PluginManager",filename)
return plugin.test()
@cherrypy.tools.json_out()
@pxlbrowserpluginfunction
def next(self,plugin):
return plugin.next()
@cherrypy.expose
@cherrypy.tools.workspace()
@cherrypy.tools.user()
@cherrypy.tools.json_out()
@pxlbrowserpluginfunction
def previous(self,plugin):
return plugin.previous()
@cherrypy.expose
def test(self):
return "<h1>Ba!</h1>"
'''
@cherrypy.expose
@cherrypy.tools.json_out()
@cherrypy.tools.user()
def invokePlugin(self, pluginname, method, tabid, pluginid, filename, eventnumber,*args,**kwargs):
#logging.getLogger(__name__).info(kwargs)
try:
reader = self.__getReader(tabid, os.path.expanduser(filename), eventnumber)
result = reader.plugins.invokePlugin(pluginname,method,pluginid,cPickle.dumps(args),cPickle.dumps(kwargs))
except Exception,e:
print e,traceback.format_exc()
return {"success": False,"msg":str(e)}
return {"success": True, "data": result,"eventnumber":reader.objectCount()}
'''
\ No newline at end of file
......@@ -3,14 +3,11 @@ class BasicNavigation(PXLBrowserPluginRemoteController):
def __init__(self,pxlioreader):
PXLBrowserPluginRemoteController.__init__(self,pxlioreader)
@pluginfunction
def next(self):
self.pxlioreader.readNextObject()
return {"eventnumber":self.pxlioreader.objectCount()}
return {"eventnumber":self.pxlioreader.objectCount(),"maxObjectCount": "?"}
@pluginfunction
def previous(self):
self.pxlioreader.readPreviousObject()
return {"eventnumber":self.pxlioreader.objectCount()}
return {"eventnumber":self.pxlioreader.objectCount(), "maxObjectCount": "?"}
\ No newline at end of file
import os
import logging
import cherrypy
import vispa
class PXLBrowserPluginConfig(object):
def __init__(self):
......@@ -35,18 +36,14 @@ class PXLBrowserPluginConfig(object):
raise NotImplementedError
class PXLBrowserPluginCherrypyController(object):
def __init__(self):
pass
def pluginfunction(fn):
fn.exposed=True
return fn
def __init__(self, platform, remoteControllerClassName):
self.platform=platform
self.remoteControllerClassName=remoteControllerClassName
def pxlbrowserpluginfunction(function):
def wrapper(self,pluginname, method, tabid, pluginid, filename, eventnumber,*args, **kw):
vispa.rpc.get(cherrypy.request.user, workspace_id, 'vispa.remote.filesystem.FileSystem')
return function(self, plugin, *args, **kw)
service = vispa.rpc.get(cherrypy.request.user, cherrypy.request.workspace, classname=None, key = None)
pluginManager = service.getmodule("vispa.extensions.pxlbrowser.plugins.remote").PluginManager(filename, eventnumber)
plugin = pluginManager.getPlugin(pluginname,pluginid, self.remoteControllerClassName)
return function(self,plugin,*args,**kw)
return wrapper
\ No newline at end of file
from pxl import core, hep
from PluginManager import *
import logging
class PXLIOReader():
......@@ -11,9 +10,9 @@ class PXLIOReader():
self.file.open(filename)
logging.getLogger(__name__).info("input file is good? "+str(self.file.good()))
self.currentObject=self.file.seekToObject(0)
#logging.info("init pxlioreader")
def readNextObject(self):
self.currentObject = self.file.readNextObject()
return self.file.good()
......@@ -31,4 +30,4 @@ class PXLIOReader():
def close(self):
self.close()
from pxl import core, hep
import logging
import cPickle
import types
#import PXLIOReader
class PluginManager(object):
def __init__(self):
pass
def setup(self,pluginRemoteControllerClassDict,filename,eventnumberself):
self.pluginRemoteControllerClassDict=pluginRemoteControllerClassDict
self._pxlioreader=PXLIOReader(filename)
self._activePlugins={}
def getPlugin(self,pluginname,pluginid):
if not self._activePlugins.has_key(pluginid):
self._activePlugins[pluginid]=self.createPluginFromName(pluginname)
return self._activePlugins[pluginid]
def test(self):
return "<h1>Fet test</h1>"
def createPluginFromName(self, pluginname):
classname = self.pluginRemoteControllerClassDict[pluginname]
plugin = self._loadModule(classname)(self._pxlioreader)
return plugin
'''
def addPlugin(self,pluginConfigPath):
try:
pluginConfig = self._loadModule(pluginConfigPath)
logging.getLogger(__name__).info("load config: "+pluginConfigPath)
pluginController = self._loadModule(pluginConfig.getControllerClass())
logging.getLogger(__name__).info("load plugin: "+pluginConfig.getName())
self.loadedPluginControllerDict[pluginConfig.getName()]=pluginController
except Exception, e:
logging.getLogger(__name__).error("Import plugin: "+pluginConfigPath+", "+str(e))
def getPluginMethods(self):
methodDict={}
for pluginName in self.loadedPluginControllerDict.keys():
methodDict[pluginName]=[]
pluginClass = self.loadedPluginControllerDict[pluginName]
for methodName in dir(pluginClass):
method = getattr(pluginClass,methodName)
if hasattr(method,"exposed"):
if getattr(method,"exposed"):
methodDict[pluginName].append(methodName)
return cPickle.dumps(methodDict)
def invokePlugin(self,pluginname,method,pluginid,args_pickled,kwargs_pickled):
args=cPickle.loads(args_pickled)
kwargs=cPickle.loads(kwargs_pickled)
logging.getLogger(__name__).info("invoke: "+pluginname+"::"+method+" < "+str(args)+","+str(kwargs))
if self._activePlugins.has_key(pluginid):
logging.getLogger(__name__).info("found plugin")
else:
logging.getLogger(__name__).info("create plugin: "+pluginname)
#init plugin
pluginInstance = self.loadedPluginControllerDict[pluginname](self._pxlioreader)
self._activePlugins[pluginid]=pluginInstance
return self._activePlugins[pluginid].invoke(method,*args,**kwargs)
def getPluginData(self,pluginname,method,pluginid,args_pickled,kwargs_pickled):
args=cPickle.loads(args_pickled)
kwargs=cPickle.loads(kwargs_pickled)
logging.getLogger(__name__).info("invoke: "+pluginname+"::"+method+" < "+str(args)+","+str(kwargs))
if self._activePlugins.has_key(pluginid):
logging.getLogger(__name__).info("found plugin")
else:
logging.getLogger(__name__).info("create plugin: "+pluginname)
#init plugin
pluginInstance = self.loadedPluginControllerDict[pluginname](self._pxlioreader)
self._activePlugins[pluginid]=pluginInstance
return self._activePlugins[pluginid].invoke(method,*args,**kwargs)
'''
def _loadModule(self,path):
cls = path.split('.')
module = ".".join(cls[:-1])
name = cls[-1]
return __import__(module, globals(), locals(), [name], -1).__dict__[name]
\ No newline at end of file
from pxl import core, hep
import logging
import cPickle
import types
import os
import vispa
from vispa.extensions.pxlbrowser.plugins.remote.PXLIOReader import PXLIOReader
#singleton decorator for PluginManager (only one PluginManager per RPC process)
def singleton(cls):
instances = {}
def getinstance(*args,**kw):
if cls not in instances:
instances[cls] = cls(*args,**kw)
return instances[cls]
return getinstance
@singleton
class PluginManager(object):
def __init__(self,filename,eventnumber):
self._pxlioreader=PXLIOReader(str(os.path.expanduser(filename)))
self._pxlioreader.seekToObject(int(str(eventnumber)))
self._activePlugins={}
def getPlugin(self,pluginname,pluginid, classname):
if not self._activePlugins.has_key(pluginid):
self._activePlugins[pluginid]=self._createPluginFromClassName(classname)
return self._activePlugins[pluginid]
def test(self):
return "<h1>Fet test</h1>"
def _createPluginFromClassName(self, classname):
plugin = self._loadModule(classname)(self._pxlioreader)
return plugin
'''
def addPlugin(self,pluginConfigPath):
try:
pluginConfig = self._loadModule(pluginConfigPath)
logging.getLogger(__name__).info("load config: "+pluginConfigPath)
pluginController = self._loadModule(pluginConfig.getControllerClass())
logging.getLogger(__name__).info("load plugin: "+pluginConfig.getName())
self.loadedPluginControllerDict[pluginConfig.getName()]=pluginController
except Exception, e:
logging.getLogger(__name__).error("Import plugin: "+pluginConfigPath+", "+str(e))
def getPluginMethods(self):
methodDict={}
for pluginName in self.loadedPluginControllerDict.keys():
methodDict[pluginName]=[]
pluginClass = self.loadedPluginControllerDict[pluginName]
for methodName in dir(pluginClass):
method = getattr(pluginClass,methodName)
if hasattr(method,"exposed"):
if getattr(method,"exposed"):
methodDict[pluginName].append(methodName)
return cPickle.dumps(methodDict)
def invokePlugin(self,pluginname,method,pluginid,args_pickled,kwargs_pickled):
args=cPickle.loads(args_pickled)
kwargs=cPickle.loads(kwargs_pickled)
logging.getLogger(__name__).info("invoke: "+pluginname+"::"+method+" < "+str(args)+","+str(kwargs))
if self._activePlugins.has_key(pluginid):
logging.getLogger(__name__).info("found plugin")
else:
logging.getLogger(__name__).info("create plugin: "+pluginname)
#init plugin
pluginInstance = self.loadedPluginControllerDict[pluginname](self._pxlioreader)
self._activePlugins[pluginid]=pluginInstance
return self._activePlugins[pluginid].invoke(method,*args,**kwargs)
def getPluginData(self,pluginname,method,pluginid,args_pickled,kwargs_pickled):
args=cPickle.loads(args_pickled)
kwargs=cPickle.loads(kwargs_pickled)
logging.getLogger(__name__).info("invoke: "+pluginname+"::"+method+" < "+str(args)+","+str(kwargs))
if self._activePlugins.has_key(pluginid):
logging.getLogger(__name__).info("found plugin")
else:
logging.getLogger(__name__).info("create plugin: "+pluginname)
#init plugin
pluginInstance = self.loadedPluginControllerDict[pluginname](self._pxlioreader)
self._activePlugins[pluginid]=pluginInstance
return self._activePlugins[pluginid].invoke(method,*args,**kwargs)
'''
def _loadModule(self,path):
cls = path.split('.')
module = ".".join(cls[:-1])
name = cls[-1]
constructor = __import__(module, globals(), locals(), [name], -1).__dict__[name]
return constructor
class PXLBrowserPluginRemoteController(object):
def __init__(self,pxlioreader):
self.pxlioreader=pxlioreader
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment