aboutsummaryrefslogtreecommitdiff
path: root/tools/migrate-1/migrate-cmake.py
blob: b90bd2e97f1d640b5223563225c1f9279816c4b9 (plain)
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
import re
from pathlib import Path

regex = re.compile(r'\s*(.*\/)*(.*)(\.[hc]pp)$')

def xstr(s):
    if s is None:
        return ''
    return str(s)

for p in Path('./src').rglob('CMakeLists.txt'):
    text = ''
    with p.open(mode='r', encoding='utf-8') as f:
        for line in f.readlines():
            m = regex.match(line)
            if m:
                t = m.group(2)
                t = ''.join(([i.capitalize() for i in t.split('_')]))
                t = '\t{}{}{}\n'.format(xstr(m.group(1)), t, m.group(3))
                text += t
            else:
                text += line
    with p.open(mode='w', encoding='utf-8') as f:
        f.write(text)