rules.py 1.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from jflow.rules import SimpleRule, LinkRule, ConditionalLinkRule

# Define your rules check below


class Unique(SimpleRule):

    def check(self):
Floreal Cabanettes's avatar
Floreal Cabanettes committed
26
27
28
29
30
        if self.is_file_list:
            for file in self.parameter_value:
                if self.parameter_value.count(file) > 1:
                    raise Exception("the file \"" + file + "\" in parameter \"" + self.parameter_name +
                                    "\" is duplicated")
31
        else:
Floreal Cabanettes's avatar
Floreal Cabanettes committed
32
33
            print("\033[93mWarning: rule unique is ignored: " + self.parameter_name +
                  " is not an input file list\033[0m")
34
35
36
37
38


class UniqueAll(SimpleRule):

    def check(self):
Floreal Cabanettes's avatar
Floreal Cabanettes committed
39
40
        if self.is_file:
            files = self.parameter_value if type(self.parameter_value) == list else [self.parameter_value]
41
42
            for file in files:
                if self.all_files.count(file) > 1:
Floreal Cabanettes's avatar
Floreal Cabanettes committed
43
                    raise Exception("the file \"" + file + "\" from parameter \"" + self.parameter_name + "\" is given "
44
45
                                    "several times (on this or another argument)")
        else:
Floreal Cabanettes's avatar
Floreal Cabanettes committed
46
            print("\033[93mWarning: rule unique_all is ignored: " + self.parameter_name +
47
                  " is not an input file or input file list\033[0m")