File size: 644 Bytes
ed552fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
"""移除 stokes_wave 所有 case controlDict 中的 line 函数"""
import os, re

raw = '/mnt/f/agent-workspace/paper2/Exp/data/raw/stokes_wave'
fixed = 0
for d in sorted(os.listdir(raw)):
    if not d.startswith('t'):
        continue
    cd = os.path.join(raw, d, 'system', 'controlDict')
    if not os.path.isfile(cd):
        continue
    c = open(cd).read()
    m = re.search(r'functions\s*\{.*?\}\s*\n', c, re.DOTALL)
    if m:
        new_c = c[:m.start()] + 'functions       {};\n' + c[m.end():]
        with open(cd, 'w') as f:
            f.write(new_c)
        fixed += 1
print(f'Fixed {fixed} controlDicts')