Commit f0ec396c authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add ValueRules + ForbiddenChars rule

parent 33a9d88d
......@@ -99,6 +99,20 @@ class LinkRule (SimpleRule):
def check(self):
pass
class ValueRule (SimpleRule):
def __init__(self, user_args, wf_instance, src_arg, values_arg, nb_rows):
SimpleRule.__init__(self, user_args, wf_instance, src_arg, nb_rows)
values = values_arg.replace("\,", "###virgule###")
values = values.split(",")
all_values = []
for val in values:
all_values.append(val.replace("###virgule###", ","))
self.values_arg = all_values
@abstractmethod
def check(self):
pass
class ConditionalRule(SimpleRule):
def __init__(self, user_args, wf_instance, src_arg, conditions, which, nb_rows):
......@@ -218,4 +232,15 @@ class FilesUnique(SimpleRule):
if isinstance(sub_parameter_obj, InputFile) or isinstance(sub_parameter_obj, InputDirectory):
all_files += value
if len(set(all_files)) < len(all_files):
self.error("Some files into '" + self.parameter_name + "' are given several times")
\ No newline at end of file
self.error("Some files into '" + self.parameter_name + "' are given several times")
class ForbiddenChars(ValueRule):
"""
Some characters are not allowed
"""
def check(self):
for value in self.values_arg:
if value in self.parameter_value:
self.error("Character not allowed: \"" + value + "\"")
......@@ -1352,9 +1352,13 @@ class Workflow(threading.Thread):
raise Exception("Rule is not defined: " + name)
# Launch validator
if issubclass(validator_class, j_rules.LinkRule): # Check the rule is the same special rule
if issubclass(validator_class, j_rules.LinkRule):
# Check the rule is the same special rule
validator = validator_class(user_args, self, src_arg, targets, nb_rows)
validator.check()
elif issubclass(validator_class, j_rules.ValueRule):
validator = validator_class(user_args, self, src_arg, is_link_rule.group(2), nb_rows)
validator.check()
else:
raise Exception("Rule is not a link rule: " + name)
else: # It's a simple rule
......
Markdown is supported
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