Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/Sphinx/create_identifiers.py
3150 views
1
#!/usr/bin/env python
2
3
import sys
4
5
if len(sys.argv) != 2:
6
sys.exit(-1)
7
name = sys.argv[1] + "/CMake.qhp"
8
9
f = open(name, "r", encoding="utf-8")
10
11
if not f:
12
sys.exit(-1)
13
14
lines = f.read().splitlines()
15
16
if not lines:
17
sys.exit(-1)
18
19
newlines = []
20
21
for line in lines:
22
23
mapping = (("command", "command"),
24
("cpack generator", "cpack_gen"),
25
("envvar", "envvar"),
26
("variable", "variable"),
27
("generator", "generator"),
28
("genex", "genex"),
29
("guide", "guide"),
30
("target property", "prop_tgt"),
31
("test property", "prop_test"),
32
("source file property", "prop_sf"),
33
("global property", "prop_gbl"),
34
("module", "module"),
35
("directory property", "prop_dir"),
36
("cache property", "prop_cache"),
37
("policy", "policy"),
38
("installed file property", "prop_inst"))
39
40
for domain_object_string, domain_object_type in mapping:
41
if "<keyword name=\"" + domain_object_string + "\"" in line:
42
if "id=\"" not in line and "#index-" not in line:
43
prefix = "<keyword name=\"" + domain_object_string + "\" "
44
part1, part2 = line.split(prefix)
45
head, tail = part2.split("#" + domain_object_type + ":")
46
domain_object, rest = tail.split("\"")
47
line = part1 + prefix + "id=\"" + domain_object_type + "/" + domain_object + "\" " + part2
48
newlines.append(line + "\n")
49
50
f = open(name, "w", encoding="utf-8")
51
f.writelines(newlines)
52
53