File: create_identifiers.py

package info (click to toggle)
cmake 3.13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 77,660 kB
  • sloc: ansic: 271,692; cpp: 195,350; yacc: 3,203; sh: 3,078; xml: 2,586; python: 1,182; lex: 1,138; asm: 370; lisp: 275; perl: 226; java: 197; f90: 175; objc: 157; cs: 124; fortran: 113; makefile: 81; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (49 lines) | stat: -rwxr-xr-x 1,433 bytes parent folder | download
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
#!/usr/bin/env python

import sys, os

if len(sys.argv) != 2:
  sys.exit(-1)
name = sys.argv[1] + "/CMake.qhp"

f = open(name)

if not f:
  sys.exit(-1)

lines = f.read().splitlines()

if not lines:
  sys.exit(-1)

newlines = []

for line in lines:

  mapping = (("command", "command"),
             ("cpack generator", "cpack_gen"),
             ("envvar", "envvar"),
             ("variable", "variable"),
             ("generator", "generator"),
             ("target property", "prop_tgt"),
             ("test property", "prop_test"),
             ("source file property", "prop_sf"),
             ("global property", "prop_gbl"),
             ("module", "module"),
             ("directory property", "prop_dir"),
             ("cache property", "prop_cache"),
             ("policy", "policy"),
             ("installed file property", "prop_inst"))

  for domain_object_string, domain_object_type in mapping:
    if "<keyword name=\"" + domain_object_string + "\"" in line:
      if not "id=\"" in line and not "#index-" in line:
        prefix = "<keyword name=\"" + domain_object_string + "\" "
        part1, part2 = line.split(prefix)
        head, tail = part2.split("#" + domain_object_type + ":")
        domain_object, rest = tail.split("\"")
        line = part1 + prefix + "id=\"" + domain_object_type + "/" + domain_object + "\" " + part2
  newlines.append(line + "\n")

f = open(name, "w")
f.writelines(newlines)