File: create_manual.py

package info (click to toggle)
openms 1.11.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436,688 kB
  • ctags: 150,907
  • sloc: cpp: 387,126; xml: 71,547; python: 7,764; ansic: 2,626; php: 2,499; sql: 737; ruby: 342; sh: 325; makefile: 128
file content (85 lines) | stat: -rw-r--r-- 2,528 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
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
75
76
77
78
79
80
81
82
83
84
85
import os
import glob
pxd_files = glob.glob("../pxds/*.pxd")
classdocu_base = "http://ftp.mi.fu-berlin.de/OpenMS/release-documentation/html"
classdocu_base = "http://www.openms.de/current_doxygen/html/"

# after how many characters should a line be wrapped
Linebreak = 85
remove_nogil = True
ignores = ["ctime", "smart_ptr", "Time"]

# Apply line break
def line_break(line):
    # print "trying to break line ", line
    if len(line) < Linebreak:return line

    for i in reversed(range(Linebreak)):
        if line[i] == " ":
            break
    if len(line) - i < 9: return line
    if i == 0:
        print "Could not break line", line
        # return line
        return line[:Linebreak] + "\\\n" + " "*6 + line_break(line[Linebreak:])
    # print "call again with i", i, "and len ", len(line)
    return line[:i] + "\\\n" + " "*6 + line_break(line[i:])

# Prepare a line for printing
def prepare_line(line):
    # replace the indent from 4/8 to 2/4 -> get more space
    line = line.replace("        ", "xxxx")
    line = line.replace("    ", "  ")
    line = line.replace("xxxx", "    ")
    return line

def get_namespace(pxd):
    filehandle = open(pxd)
    fulltext = filehandle.read()
    filehandle.close()
    import re
    match = re.search("cdef extern.*?namespace\s*\"([^\"]*)\"", fulltext)
    if not match:
        return "OpenMS"
    else:
        return match.group(1)


def get_header(title, ns):

    return r"""
$\rightarrow$ \textit{\href{%s/class%s_1_1%s.html}{Link
to OpenMS documentation}}

Wrapped functions in Python:
""" % (classdocu_base, ns, title)

write_handle = open("appendix.tex", "w")
print pxd_files
for pxd in sorted(pxd_files):
    # get title for latex section
    title = pxd[8:-4]
    if title in ignores:
        continue
    title = title.replace("_", "\\_")
    write_handle.write("\subsection{%s}\n\n" % title)
    write_handle.write("\label{%s}\n\n" % title)
    # write_handle.write("{\\tiny\n    \\begin{verbatim}")
    write_handle.write( get_header(title, get_namespace(pxd)) )
    write_handle.write("{    \\begin{verbatim}")
    filehandle = open(pxd)
    found_start = False
    for line in filehandle:
        if line.find("import") == -1 and len(line.strip() ) > 0:
            found_start = True
        if line.find("import") == -1 and found_start:
            # print line.strip()
            line = prepare_line(line)
            line = line_break(line)
            write_handle.write(line)
    write_handle.write("\end{verbatim}\n}\n\n")

write_handle.close()