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

Migrate some rules from wf_rules to j_rules

parent 9401c25e
...@@ -80,3 +80,46 @@ class ConditionalLinkRule(LinkRule): ...@@ -80,3 +80,46 @@ class ConditionalLinkRule(LinkRule):
@abstractmethod @abstractmethod
def check(self): def check(self):
pass pass
class Exclude(LinkRule):
def check(self):
for exclude in self.targets_args:
if exclude in self.user_args and self.user_args[exclude] is not None: # The target is found
raise Exception("arguments " + self.parameter_name + " and " + exclude + " are mutually excluded")
class ExcludeIf(ConditionalLinkRule):
def check(self):
if self.condition_raised is not None:
validator = Exclude(self.user_args, self.wf_instance, self.parameter_name, self.targets_args, self.all_files)
try:
validator.check()
except Exception as e:
raise Exception("Argument " + self.parameter_name + " is set to " + self.condition_raised + ": " +
str(e))
class ToBeRequired(LinkRule):
def check(self):
for require in self.targets_args:
if require not in self.user_args or (require in self.user_args and self.user_args[require] is None): # The target is not found
raise Exception("the argument " + self.parameter_name + " require argument " + require +
" to be defined")
class ToBeRequiredIf(ConditionalLinkRule):
def check(self):
if self.condition_raised is not None:
validator = ToBeRequired(self.user_args, self.wf_instance, self.parameter_name, self.targets_args,
self.all_files)
try:
validator.check()
except Exception as e:
raise Exception("Argument " + self.parameter_name + " is set to " + self.condition_raised + ": " +
str(e))
...@@ -46,7 +46,7 @@ from jflow.utils import get_octet_string_representation, get_nb_octet ...@@ -46,7 +46,7 @@ from jflow.utils import get_octet_string_representation, get_nb_octet
from jflow.parameter import * from jflow.parameter import *
from cctools.util import time_format from cctools.util import time_format
from jflow.rules import * import jflow.rules as j_rules
from weaver.script import ABSTRACTIONS from weaver.script import ABSTRACTIONS
from weaver.script import DATASETS from weaver.script import DATASETS
...@@ -1271,38 +1271,57 @@ class Workflow(threading.Thread): ...@@ -1271,38 +1271,57 @@ class Workflow(threading.Thread):
name = is_conditional_link_rule.group(1) name = is_conditional_link_rule.group(1)
conditions = is_conditional_link_rule.group(2).split(",") conditions = is_conditional_link_rule.group(2).split(",")
targets = is_conditional_link_rule.group(3).split(",") targets = is_conditional_link_rule.group(3).split(",")
# Get validator:
if hasattr(wf_rules, name): # Check the rule exists if hasattr(wf_rules, name): # Check the rule exists
validator_instance = getattr(wf_rules, name) validator_class = getattr(wf_rules, name)
if issubclass(validator_instance, ConditionalLinkRule): # Check the rule is the same special rule elif hasattr(j_rules, name):
validator = getattr(wf_rules, name)(user_args, self, src_arg, targets, conditions, all_files) validator_class = getattr(j_rules, name)
validator.check()
else:
raise Exception("Rule is not a conditional link rule: " + name)
else: else:
raise Exception("Rule is not defined: " + name) raise Exception("Rule is not defined: " + name)
# Launch validator:
if issubclass(validator_class, j_rules.ConditionalLinkRule): # Check the rule is the same special rule
validator = validator_class(user_args, self, src_arg, targets, conditions, all_files)
validator.check()
else:
raise Exception("Rule is not a conditional link rule: " + name)
else: else:
is_link_rule = re.match(link_rule, rule) # Check the second special rule is_link_rule = re.match(link_rule, rule) # Check the second special rule
if is_link_rule: if is_link_rule:
# Check this special rule: # Check this special rule:
name = is_link_rule.group(1) name = is_link_rule.group(1)
targets = is_link_rule.group(2).split(",") targets = is_link_rule.group(2).split(",")
# Get validator:
if hasattr(wf_rules, name): # Check the rule exists if hasattr(wf_rules, name): # Check the rule exists
validator_class = getattr(wf_rules, name) validator_class = getattr(wf_rules, name)
if issubclass(validator_class, LinkRule): # Check the rule is the same special rule elif hasattr(j_rules, name):
validator = validator_class(user_args, self, src_arg, targets, all_files) validator_class = getattr(j_rules, name)
validator.check()
else:
raise Exception("Rule is not a link rule: " + name)
else: else:
raise Exception("Rule is not defined: " + name) raise Exception("Rule is not defined: " + name)
# Launch validator
if issubclass(validator_class, j_rules.LinkRule): # Check the rule is the same special rule
validator = validator_class(user_args, self, src_arg, targets, all_files)
validator.check()
else:
raise Exception("Rule is not a link rule: " + name)
else: # It's a simple rule else: # It's a simple rule
name = rule name = rule
# Get validator:
if hasattr(wf_rules, name): # Check the rule exists if hasattr(wf_rules, name): # Check the rule exists
validator_class = getattr(wf_rules, name) validator_class = getattr(wf_rules, name)
if issubclass(validator_class, SimpleRule): # Check it's a simple rule elif hasattr(j_rules, name):
validator = validator_class(user_args, self, src_arg, all_files) validator_class = getattr(j_rules, name)
validator.check()
else:
raise Exception("Rule is not a simple rule: " + name)
else: else:
raise Exception("Rule is not defined: " + name) raise Exception("Rule is not defined: " + name)
# Launch validator:
if issubclass(validator_class, j_rules.SimpleRule): # Check it's a simple rule
validator = validator_class(user_args, self, src_arg, all_files)
validator.check()
else:
raise Exception("Rule is not a simple rule: " + name)
...@@ -45,46 +45,3 @@ class UniqueAll(SimpleRule): ...@@ -45,46 +45,3 @@ class UniqueAll(SimpleRule):
else: else:
print("\033[93mWarning: rule unique_all is ignored: " + self.parameter_name + print("\033[93mWarning: rule unique_all is ignored: " + self.parameter_name +
" is not an input file or input file list\033[0m") " is not an input file or input file list\033[0m")
class Exclude(LinkRule):
def check(self):
for exclude in self.targets_args:
if exclude in self.user_args and self.user_args[exclude] is not None: # The target is found
raise Exception("arguments " + self.parameter_name + " and " + exclude + " are mutually excluded")
class ExcludeIf(ConditionalLinkRule):
def check(self):
if self.condition_raised is not None:
validator = Exclude(self.user_args, self.wf_instance, self.parameter_name, self.targets_args, self.all_files)
try:
validator.check()
except Exception as e:
raise Exception("Argument " + self.parameter_name + " is set to " + self.condition_raised + ": " +
str(e))
class ToBeRequired(LinkRule):
def check(self):
for require in self.targets_args:
if require not in self.user_args or (require in self.user_args and self.user_args[require] is None): # The target is not found
raise Exception("the argument " + self.parameter_name + " require argument " + require +
" to be defined")
class ToBeRequiredIf(ConditionalLinkRule):
def check(self):
if self.condition_raised is not None:
validator = ToBeRequired(self.user_args, self.wf_instance, self.parameter_name, self.targets_args,
self.all_files)
try:
validator.check()
except Exception as e:
raise Exception("Argument " + self.parameter_name + " is set to " + self.condition_raised + ": " +
str(e))
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