File: create_man

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (58 lines) | stat: -rwxr-xr-x 1,918 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3

import re
import os
import argparse

def read_content(file):
    try:
        f=open(file, "r")
        content= f.read()
        f.close()
    except:
        raise
    return content

def header(function, version):
    hdr= "%% %s(3) Version %s | MariaDB Connector/C\n" % (function, version)
    return hdr

def replace_links(content):
  links= list(re.compile(r'\[([^\]]+)\]\(([^)]+)\)').findall(content))
  for l in links:
    search= "[%s()](%s)" % (l[1], l[1])
    replace= "**%s(3)**" % l[1]
    content= content.replace(search, replace)
  return content

parser= argparse.ArgumentParser(prog="create_man.py",
                                description="Create man pages for MariaDB Connector/C")
parser.add_argument('--docs', type=str, metavar='docs', help='Directory of MariaDB Connector/C documentation')
parser.add_argument('--funcs', type=str, metavar='funcs', help='File which contains exported functions.')
parser.add_argument('--version', type=str, metavar='version', help='Connector/C version')
parser.add_argument('--out', type=str, metavar='outputdir', help='Output directory')
parser.add_argument('--warn', type=int, default=0, metavar='warnings', help='Show warnings (off)')
args= parser.parse_args()

if not os.path.isdir(args.out):
  os.mkdir(args.out)

func_list= read_content(args.funcs)
funcs= func_list.split(";")

for function in funcs:

    try:
        content= read_content("%s/%s.md" % (args.docs, function))
        
    except:
        if args.warn > 0:
            print("warning: Function '%s' is not documented yet" % function)
        continue

    f= open("%s/%s.3.md" % (args.out, function), "w")
    f.write(header(function, args.version))
    f.write(replace_links(content))
    f.close()
    ret= os.system("pandoc --standalone --to man %s/%s.3.md -o %s/%s.3" % (args.out, function, args.out, function))
    os.unlink("%s/%s.3.md" % (args.out, function))