forked from Liquifact/Liquifact-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_init_calls.py
More file actions
36 lines (26 loc) · 1022 Bytes
/
Copy pathfix_init_calls.py
File metadata and controls
36 lines (26 loc) · 1022 Bytes
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
#!/usr/bin/env python3
"""Fix all client.init() calls to include the two new parameters."""
import re
import os
from pathlib import Path
# Pattern to find init calls: look for the closing of init() with &None parameters
pattern = re.compile(
r'(client\.init\([^)]*?)([\s]*&None,[\s]*&None,[\s]*\);)',
re.DOTALL
)
# The replacement adds the two missing &None parameters
replacement = r'\1 &None,\n &None,\n );'
test_dir = Path('/workspaces/Liquifact-contracts/escrow/src')
for rs_file in test_dir.rglob('*.rs'):
with open(rs_file, 'r') as f:
content = f.read()
# Count matches before
matches_before = len(pattern.findall(content))
if matches_before > 0:
# Replace all occurrences
new_content = pattern.sub(replacement, content)
# Write back
with open(rs_file, 'w') as f:
f.write(new_content)
print(f"Fixed {matches_before} calls in {rs_file.relative_to(test_dir.parent)}")
print("Done!")