File: locate-cpp-options

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (74 lines) | stat: -rwxr-xr-x 2,392 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
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
#!/usr/bin/env python3

import os
import re
import yaml
try:
    from yaml import CDumper as MyDumper
    from yaml import CLoader as MyLoader
except ImportError:
    from yaml import Dumper as MyDumper
    from yaml import Loader as MyLoader


abinit_trees = {
    "common": os.path.join("shared", "common", "src"),
    "libpaw": os.path.join("shared", "libpaw"),
    "core": "src",
}
tree_map = {"libpaw": ["39_libpaw"]}

abinit_incs = {
    "common": "01_incs",
    "libpaw": "39_incs",
    "core": "41_incs",
}

with open(os.path.join("split", "abinit_cpp_options.yml"), "r") as yaml_file:
    cpp_options = yaml.load(yaml_file, Loader=MyLoader)["cpp_options"]

cpp_map = {}
for key, topdir in abinit_trees.items():
    for root, dirs, files in os.walk(topdir):
        mark = os.path.basename(root)
        if mark != "src":
            if not key in tree_map:
                tree_map[key] = []
            tree_map[key].append(mark)
        for src in [item for item in files \
                if (item.endswith(".F90") or item.endswith(".f90") or \
                item.endswith(".h")) and \
                (not item.startswith("m_cppopts_dumper"))]:
            text = [line for line in open(os.path.join(root, src), "r").readlines() \
                    if line.startswith("#")]
            text = "".join(text)
            if mark == "incs":
                mark = abinit_incs[key]
            elif mark == "src":
                mark = "39_libpaw"
            for opt in cpp_options:
                if re.search(opt, text):
                    if not opt in cpp_map:
                        cpp_map[opt] = {mark: []}
                    if not mark in cpp_map[opt]:
                        cpp_map[opt][mark] = []
                    cpp_map[opt][mark].append(src)

for key, val in tree_map.items():
    tree_map[key] = [item for item in val \
            if re.match("[0-9][0-9]", item) or item in ["incs"]]
    tree_map[key] = [abinit_incs[key] if item == "incs" else item \
            for item in tree_map[key]]
    tree_map[key].sort()

map_data = {
        "tree_map": tree_map,
        "cpp_map":cpp_map,
}
with open(os.path.join("split", "abinit_cpp_map.yml"), "w") as map_file:
    yaml.dump(map_data, stream=map_file, Dumper=MyDumper,
        default_flow_style=False,
        explicit_start=True,
        explicit_end=True,
        version=(1, 1),
        indent=2)