blob: b29bf4af19d0a5c358042017317b2764cf2c882c [file] [log] [blame]
Maksym Shalamov98189f52018-04-24 13:36:26 +03001--- os_testr/regex_builder.py 2018-04-25 11:33:36.330640993 +0300
2+++ os_testr/regex_builder.py 2018-04-25 11:33:54.878627168 +0300
3@@ -71,34 +71,46 @@
4 return '|'.join(lines)
5
6
7-def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
8- """Deprecated, please use testlist_builder.construct_list instead."""
9- if not blacklist_file:
10+def get_regex_from_blacklist_file(file_path, print_exclude=False):
11+ exclude_regex = ''
12+ with open(file_path, 'r') as black_file:
13 exclude_regex = ''
14- else:
15- with open(blacklist_file, 'r') as black_file:
16- exclude_regex = ''
17- for line in black_file:
18- raw_line = line.strip()
19- split_line = raw_line.split('#')
20- # Before the # is the regex
21- line_regex = split_line[0].strip()
22- if len(split_line) > 1:
23- # After the # is a comment
24- comment = split_line[1].strip()
25+ for line in black_file:
26+ raw_line = line.strip()
27+ split_line = raw_line.split('#')
28+ # Before the # is the regex
29+ line_regex = split_line[0].strip()
30+ if len(split_line) > 1:
31+ # After the # is a comment
32+ comment = split_line[1].strip()
33+ else:
34+ comment = ''
35+ if line_regex:
36+ if print_exclude:
37+ print_skips(line_regex, comment)
38+ if exclude_regex:
39+ exclude_regex = '|'.join([line_regex, exclude_regex])
40 else:
41- comment = ''
42- if line_regex:
43- if print_exclude:
44- print_skips(line_regex, comment)
45- if exclude_regex:
46- exclude_regex = '|'.join([line_regex, exclude_regex])
47- else:
48- exclude_regex = line_regex
49- if exclude_regex:
50- exclude_regex = "^((?!" + exclude_regex + ").)*$"
51- if regex:
52- exclude_regex += regex
53- if whitelist_file:
54- exclude_regex += '%s' % get_regex_from_whitelist_file(whitelist_file)
55+ exclude_regex = line_regex
56+ if exclude_regex:
57+ exclude_regex = "(?!" + exclude_regex + ")"
58 return exclude_regex
59+
60+
61+def construct_regex(blacklist_file, whitelist_file, regex, print_exclude):
62+ """Deprecated, please use testlist_builder.construct_list instead."""
63+ bregex = ''
64+ wregex = ''
65+ pregex = ''
66+
67+ if blacklist_file:
68+ bregex = get_regex_from_blacklist_file(blacklist_file, print_exclude)
69+ if whitelist_file:
70+ wregex = get_regex_from_whitelist_file(whitelist_file)
71+ if regex:
72+ pregex = regex
73+ combined_regex = '^%s.*(%s).*$' % (bregex, '|'.join(
74+ filter(None, [pregex, wregex])
75+ ))
76+
77+ return combined_regex