-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_diff_offset.py
43 lines (35 loc) · 1.01 KB
/
generate_diff_offset.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
import click
import json
@click.command()
@click.argument("diff_file", type=click.File("r"))
@click.argument("offset", type=int)
def generate_diff_offset(diff_file, offset):
"""
Given a diff file, produces another diff file where the matches
are offset by OFFSET.
Example:
python generate_diff_offset.py -- diff.json -1 > offset.diff.json
"""
diff_json = json.load(diff_file)
olds = []
news = []
for pair in diff_json:
if "old" not in pair or "new" not in pair:
continue
olds.append(pair["old"])
news.append(pair["new"])
if offset < 0:
news = [[] for _ in range(-offset)] + news
if offset > 0:
olds = [[] for _ in range(offset)] + olds
opcodes_object = []
for old, new in zip(olds, news):
opcodes_object.append(
{
"old": old,
"new": new,
}
)
print(json.dumps(opcodes_object, indent=2))
if __name__ == "__main__":
generate_diff_offset()