-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpt-generate
More file actions
executable file
·89 lines (75 loc) · 2.67 KB
/
wpt-generate
File metadata and controls
executable file
·89 lines (75 loc) · 2.67 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
import fileinput
import itertools
import os
import re
from functools import cmp_to_key
def grep_match_line_to_filename(line):
return re.sub(':.*$', '', line).rstrip()
def compare_filepaths(filepath1, filepath2):
dirname1 = os.path.dirname(filepath1)
dirname2 = os.path.dirname(filepath2)
if dirname1 < dirname2:
return -1
if dirname1 > dirname2:
return 1
filename1 = os.path.basename(filepath1)
filename2 = os.path.basename(filepath2)
if filename1 < filename2:
return -1
if filename1 > filename2:
return 1
return 0
def is_test_file(entry, dirname):
return os.path.isfile(os.path.join(dirname, entry)) and \
'-ref.' not in entry and \
'-notref.' not in entry and \
entry != 'WEB_FEATURES.yml'
def list_test_files(dirname):
return sorted(
filter(
lambda entry: is_test_file(entry, dirname),
os.listdir(dirname)
)
)
def is_auxilliary_dir(dirname):
dirparts = dirname.split(os.path.sep)
return set(['resources', 'support']).intersection(dirparts)
def main():
directories = itertools.groupby(
sorted(
set(map(grep_match_line_to_filename, fileinput.input())),
key=cmp_to_key(compare_filepaths)
),
key=lambda filepath: os.path.dirname(filepath)
)
stdout = ''
for dirname, matching_test_filepaths in directories:
all_test_filenames = list_test_files(dirname)
matching_test_filenames = set(map(lambda filepath: os.path.basename(filepath), matching_test_filepaths))
yaml_filenames = map(
lambda filename: f'{" " if filename in matching_test_filenames else "#"} - {os.path.basename(filename)}',
all_test_filenames
)
if is_auxilliary_dir(dirname):
stdout += f'{dirname} (not a test-containing directory))\n'
stdout += '\n'.join(matching_test_filenames)
stdout += '\n\n'
else:
web_features_filename = os.path.join(dirname, 'WEB_FEATURES.yml')
try:
with open(web_features_filename, 'x') as handle:
handle.write('features:\n')
except FileExistsError:
pass
with open(web_features_filename, 'a') as handle:
handle.write('- name: \n')
handle.write(' files:\n')
handle.write('\n'.join(yaml_filenames))
handle.write('\n')
stdout += f'{web_features_filename}\n'
stdout += '\n'.join(matching_test_filenames)
stdout += '\n\n'
return stdout
if __name__ == '__main__':
print(main())