File: rename_headers.py

package info (click to toggle)
xtensor-blas 0.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,860 kB
  • sloc: cpp: 98,000; makefile: 201; perl: 178; python: 153
file content (41 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download | duplicates (3)
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
import sys
import re
import os
from shutil import copyfile

args = sys.argv[1:]

expr = r"#include *[\<\"](?P<path>.+)[\>\"]"

def mkdir(path):
    dname = os.path.dirname(path)
    if not os.path.exists(dname):
        print("Making dir: ", dname)
        os.makedirs(dname)

for arg in args:
    print("Opening: ", arg)
    temp = ""
    if os.path.isdir(arg):
        continue

    arg2 = arg.replace('flens', '../xflens/')
    if arg.endswith(('.cxx', '.tcc', '.h', '.cc')):
        with open(arg) as f:
                for l in f.readlines():
                    match = re.match(expr, l)
                    if match:
                        path = match.group('path')
                        if path.startswith('cxxblas/') or path.startswith('cxxlapack/'):
                            path = "xflens/" + path
                            temp += '#include \"' + path + '"\n'
                        else:
                            temp += l
                    else:
                        temp += l
        mkdir(arg2)
        with open(arg2, 'w+') as f:
            f.write(temp)
    else:
        mkdir(arg2)
        copyfile(arg, arg2)