Welcome to mirror list, hosted at ThFree Co, Russian Federation.

version_update_D4342_utility.py - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 69e2f3e3601f737be23bd7f4fe9a4db1cb161b3d (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3

# Run from Blender's root DIR

SOURCE_DIRS = (
    "source",
    )

USE_MULTIPROCESS = True

replace_all = (
    ("clipsta", "clip_start"),
    ("clipend", "clip_end"),
    ("YF_dofdist", "dof_dist"),
    ("Lamp", "Light"),
)

replace_tables = (
    replace_all,
)

replace_tables_re = [
    [(src, dst) for src, dst in table]
        for table in replace_tables
]


def replace_all(fn, data_src):
    import re

    data_dst = data_src
    for table in replace_tables_re:
        for src_re, dst in table:
            data_dst = re.sub(src_re, dst, data_dst)
    return data_dst


operation = replace_all

import os

def source_files(path):
    for dirpath, dirnames, filenames in os.walk(path):
        dirnames[:] = [d for d in dirnames if not d.startswith(".")]
        for filename in filenames:
            if filename.startswith("."):
                continue
            ext = os.path.splitext(filename)[1]

            # XXX weak, don't touch this!
            if filename.endswith("versioning_dna.c"):
                continue

            if ext.lower() in {".c", ".cc", ".cxx", ".cpp", ".h", ".hxx", ".hpp"}:
                yield os.path.join(dirpath, filename)

def operation_wrap(fn):
    with open(fn, "r", encoding="utf-8") as f:
        data_src = f.read()
        data_dst = operation(fn, data_src)

    if data_dst is None or (data_src == data_dst):
        return

    with open(fn, "w", encoding="utf-8") as f:
        f.write(data_dst)


def main():
    if USE_MULTIPROCESS:
        args = [fn for DIR in SOURCE_DIRS for fn in source_files(DIR)]
        import multiprocessing
        job_total = multiprocessing.cpu_count()
        pool = multiprocessing.Pool(processes=job_total * 2)
        pool.map(operation_wrap, args)
    else:
        for fn in source_files(SOURCE_DIR):
            operation_wrap(fn)


if __name__ == "__main__":
    main()