Added automagic argument checking when running functions.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
import gtk
|
||||
import sys
|
||||
import os
|
||||
import inspect
|
||||
from system import logger
|
||||
|
||||
def _workflow_classes(modname):
|
||||
@@ -174,17 +174,27 @@ class WorkflowView (gtk.VBox):
|
||||
if not validation.succeeded:
|
||||
logger.log('warning','Invalid Inputdata: ' + str(reason))
|
||||
return
|
||||
|
||||
argcount =function.run.func_code.co_argcount - 1
|
||||
|
||||
if argcount != len(parent_data) and argcount != 0:
|
||||
logger.log('warning','Method requires ' + str(argcount) + ' Data. ' + str(len(parent_data)) + ' selected')
|
||||
|
||||
args, varargs, varkw, defaults = inspect.getargspec(function.run)
|
||||
|
||||
# first argument is 'self' and we don't care about that...
|
||||
args = args[1:]
|
||||
|
||||
if varargs and len(parent_data) < len(args):
|
||||
logger.log('warning', "Function requires minimum %d datasets selected." % len(args))
|
||||
return
|
||||
elif not varargs and args and len(args) != len(parent_data):
|
||||
# functions requiring datasets have to have the right number
|
||||
logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data)))
|
||||
return
|
||||
|
||||
if not project.current_data or argcount == 0:
|
||||
# we allow functions requiring no data to be run even if
|
||||
# something is selected
|
||||
|
||||
if not args:
|
||||
new_data = function.run()
|
||||
else:
|
||||
new_data = function.run(*project.current_data)
|
||||
new_data = function.run(*parent_data)
|
||||
|
||||
if new_data != None:
|
||||
project.add_data(parent_data, new_data, function.name)
|
||||
|
Reference in New Issue
Block a user