mrv.automation.processes
Covered: 19 lines
Missed: 6 lines
Skipped 22 lines
Percent: 76 %
 2
"""Contains all processes """
 3
__docformat__ = "restructuredtext"
 5
from mrv.automation.process import ProcessBase
 6
import mrv.util as util
 9
def parseProcessesFromPackage( importBase, packageFile ):
10
	"""Parse all processes from the given package's sub-modules and add them to main
11
	processes module to make them available to the workflow system
13
	:param importBase: Something like: parentPackage.subpackage.mypackage, of your processes package
14
	:param packageFile: the pointing to your processes package, usually __file__ of your package
15
	"""
16
	isProcess = lambda cls: hasattr( cls, 'mro' ) and ProcessBase in cls.mro()
17
	processes = util.getPackageClasses( importBase, packageFile, predicate = isProcess )
19
	gd = globals()
20
	for pcls in processes:
21
		gd[pcls.__name__] = pcls
24
def addProcesses( *args ):
25
	"""Add the given process classes to the list of known process types. They will be regeistered
26
	with their name obtained by str( processCls ).
27
	Workflows loaded from files will have access to the processes in this package
29
	:param args: process classes to be registered to this module."""
30
	gd = globals();
31
	for pcls in args:
32
		if ProcessBase not in pcls.mro():
33
			raise TypeError( "%r does not support the process interface" % pcls )
35
		gd[pcls.__name__] = pcls