This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
apply_failed_state.py
executable file
·73 lines (67 loc) · 1.95 KB
/
apply_failed_state.py
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
#!/usr/local/bin/python
# How to use
# $ ./update_state.sh
import os
import re
import sys
import glob
import fnmatch
import json
delimeter_line=re.compile("^--")
def find_files(directory, pattern):
ret_files = []
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
path = os.path.join(root, basename)
ret_files.append(path)
return ret_files
filename=sys.argv[1]
with open(filename) as f:
test_filename=""
test_fork=""
test_idx=0
for line in f:
if delimeter_line.match(line):
pass
elif len(test_filename) == 0:
m = re.search("--- FAIL: TestState/.*/(.*\.json)/([0-9a-zA-Z]+)/([0-9]+) \(.*", line)
test_filename = m.group(1)
test_fork = m.group(2)
test_idx = int(m.group(3))
files = find_files(".", test_filename)
if len(files) != 1:
m = re.search("--- FAIL: TestState/.*?([^/]*/.*\.json)/([0-9a-zA-Z]+)/([0-9]+) \(.*", line)
filenameWithPath = m.group(1)
filesSecond = []
for fi in files:
if re.search(".*%s" % (filenameWithPath), fi) is not None:
filesSecond.append(fi)
if len(filesSecond) != 1:
print "Filename %s matched multiple times. %s" % (test_filename, files)
exit(0)
files = filesSecond
test_filename = files[0]
else:
m = re.search("^.*got ([0-9a-zA-Z]+), want ([0-9a-zA-z]+)", line)
got = m.group(1)
want = m.group(2)
print "Processing file %s..." % (test_filename)
content = ""
new_content = ""
with open(test_filename) as jsonf:
matched_hash = 0
matched_logs = 0
for jsonl in jsonf:
if re.match("^\s+\"hash\"\s*:", jsonl):
if matched_hash == test_idx:
jsonl = re.sub(want, got, jsonl)
matched_hash += 1
elif re.match("^\s+\"logs\"\s*:", jsonl):
if matched_logs == test_idx:
jsonl = re.sub(want, got, jsonl)
matched_logs += 1
new_content += jsonl
with open(test_filename, "w") as jsonf:
jsonf.write(new_content)
test_filename=""