Commit 8e42547f authored by payno's avatar payno
Browse files

add management of add-ons

parent 03e88d35
...@@ -25,8 +25,6 @@ __date__ = "28/05/2019" ...@@ -25,8 +25,6 @@ __date__ = "28/05/2019"
import logging import logging
#from pypushflow import UtilsMongoDb
logger = logging.getLogger('pypushflow') logger = logging.getLogger('pypushflow')
...@@ -55,23 +53,9 @@ class AbstractActor(object): ...@@ -55,23 +53,9 @@ class AbstractActor(object):
)) ))
actor.trigger(inData) actor.trigger(inData)
# def uploadDataToMongo(self, actorData={}, script=None):
# if self.parent is not None:
# if self.parent.mongoId is not None:
# if self.actorId is None:
# actorPath = self.getActorPath() + '/' + self.name
# self.actorId = UtilsMongoDb.initActor(
# workflowId=self.parent.mongoId,
# name=actorPath,
# actorData=actorData,
# script=script
# )
# else:
# UtilsMongoDb.addDataToActor(
# workflowId=self.parent.mongoId,
# actorId=self.actorId,
# actorData=actorData
# )
def getActorPath(self): def getActorPath(self):
return self.parent.getActorPath() return self.parent.getActorPath()
def get_addons(self):
"""Return the list of add-on that will be apply to this actor"""
raise NotImplementedError()
from .classes import *
\ No newline at end of file
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2019-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "22/04/2020"
class BaseWorkflowAddOn:
"""Base class for a Workflow instance"""
def __init__(self, workflow_instance):
pass
class BaseActorAddOn:
"""Base class to define an add on for an actor"""
def __init__(self, target):
"""Apply an add on to classes that are instances of target class"""
self.__target = target
@property
def target(self):
return self.__target
def pre_trigger_action(self, actor):
pass
def post_trigger_action(self, actor):
pass
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2019-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "22/04/2020"
import logging
import pkgutil
import inspect
_logger = logging.getLogger(__name__)
def get_registered_add_ons():
"""Return the list of registered add-on"""
try:
import ppfaddon
except ImportError:
_logger.info('no add on found')
return []
else:
modules = []
for importer, modname, ispkg in pkgutil.iter_modules(ppfaddon.__path__):
if ispkg:
modules.append(modname)
return modules
def get_registered_add_ons_classes():
"""Return the list of registered add-on classes"""
classes = []
add_on_modules = get_registered_add_ons()
for module in add_on_modules:
package_name = '.'.join(('ppfaddon', module))
try:
mymodule = __import__(package_name, fromlist=['foo'])
for element_name in dir(mymodule):
element = getattr(mymodule, element_name)
if inspect.isclass(element):
classes.append(element)
except ImportError as e:
_logger.error(str(e))
return classes
def is_add_on_class_relative_to(add_on_class, myclass):
"""Return the list of registered add-on classes"""
return isinstance(myclass, add_on_class.target)
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