File: split_help.py

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (48 lines) | stat: -rw-r--r-- 1,339 bytes parent folder | download | duplicates (4)
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
"""
Split help contents into the tool-specific short help and the common
configuration options.
"""

import argparse
import io

from cmakelang import configuration


def main():
  argparser = argparse.ArgumentParser(description=__doc__)
  argparser.add_argument("infile")
  argparser.add_argument("unique_outfile")
  argparser.add_argument("common_outfile", nargs="?", default="/dev/null")
  args = argparser.parse_args()

  matchlines = []
  for _, item in vars(configuration).items():
    if (isinstance(item, type) and
        issubclass(item, configuration.ConfigObject) and
        item is not configuration.ConfigObject):
      firstline = item.__doc__.strip().split("\n")[0]
      matchlines.append(firstline)

  unique_lines = []
  common_lines = []
  with io.open(args.infile, "r", encoding="utf-8") as infile:
    for line in infile:
      if line.strip().rstrip(":") in matchlines:
        common_lines.append(line)
        break
      unique_lines.append(line)

    for line in infile:
      common_lines.append(line)

  with io.open(args.unique_outfile, "w", encoding="utf-8") as outfile:
    outfile.write("".join(unique_lines))

  if args.common_outfile != "/dev/null":
    with io.open(args.common_outfile, "w", encoding="utf-8") as outfile:
      outfile.write("".join(common_lines))


if __name__ == "__main__":
  main()