forked from Jagadeeshftw/grainlify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve_all.py
More file actions
45 lines (38 loc) · 1.03 KB
/
resolve_all.py
File metadata and controls
45 lines (38 loc) · 1.03 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
import re
import glob
import os
files = glob.glob("contracts/**/*.rs", recursive=True)
for filepath in files:
if not os.path.isfile(filepath):
continue
with open(filepath, 'r') as f:
content = f.read()
if '<<<<<<< HEAD' not in content:
continue
lines = content.split('\n')
new_lines = []
in_head = False
in_remote = False
for line in lines:
if line.startswith('<<<<<<< HEAD'):
in_head = True
continue
elif line.startswith('======='):
if in_head:
in_head = False
in_remote = True
else:
new_lines.append(line)
continue
elif line.startswith('>>>>>>>'):
if in_remote:
in_remote = False
else:
new_lines.append(line)
continue
if in_remote:
pass
else:
new_lines.append(line)
with open(filepath, 'w') as f:
f.write('\n'.join(new_lines))