File: dumphtml.py

package info (click to toggle)
python-kde3 3.15.2%2B20060422-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 14,620 kB
  • ctags: 7,123
  • sloc: python: 5,100; cpp: 4,676; ansic: 629; makefile: 116
file content (155 lines) | stat: -rw-r--r-- 4,102 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import os, os.path, sys

from genhtml import GenHTML
from reader import Reader

#config = {}

htmlHead ="""
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
        "http://www.w3.org/TR/html4/loose.dtd"">
<html>
<head>
  <title>%s</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <meta name="GENERATOR" content="wabbit dumphtml">
</head>
<body>
<h4>PyKDE - Python Bindings for KDE</h4>
<hr>
"""

htmlFoot = """
</body>
</html>
"""


def readConfigFile ():
    config = {}
    try:
        homepath = os.getenv ("HOME")
        if not homepath:
            homepath = os.path.join (os.sep, home, os.getlogin ())

        configFile = os.path.join (homepath, ".wabbit", "wabbitrc")

        if os.path.exists (configFile):
            config ["wabbit"] = os.path.dirname (configFile)
            f = open (configFile, "r")
            for line in f:
                if line.find ("="):
                    pair = line.split ("=")
                    if len (pair) >= 2:
                        config [pair [0].strip ()] = pair [1].strip ()
                    else:
                        config [pair [0].strip ()] = ""
        else:
            print "Error: can't locate or read config file wabbitrc"
            return None

        return config
    except:
        print "Error: can't locate or read config file wabbitrc"
        return None


def writeHTMLFiles (config, dest):
    glCopy = "cp %s %s" % (os.path.join (config ["PyKDERef"], "glossary.html"), os.path.join (dest, "glossary.html"))
    os.system (glCopy)

    reader = Reader (os.path.join (config ["PyKDERef"], "classref.txt"), config)
    reader.readfile ()
    genHTML = GenHTML (reader, config, True)

    homefile = os.path.join (dest, "index.html")

    page = htmlHead % ("PyKDE Classref")
    page += genHTML.homePage ()
    page += htmlFoot

    print homefile
    f = open (homefile, "w")
    f.write (page)
    f.close ()

    allfile = os.path.join (dest, "allclasses.html")
    page = htmlHead % ("All PyKDE Classes")
    page += genHTML.allClassesPage ()
    page += htmlFoot

    f = open (allfile, "w")
    f.write (page)
    f.close ()

    print "modules", reader.modules.keys ()
    for mod in reader.modules:
    #    print mod
        moddir = os.path.join (dest, mod)
        if not os.path.exists (moddir):
            os.mkdir (moddir)

        modfile = os.path.join (moddir, "index.html")

        page = htmlHead % ("module " + mod)
        page += genHTML.classesPage (mod)
        page += htmlFoot

        f = open (modfile, "w")
        f.write (page)
        f.close ()

        if mod in reader.globals:
            globfile = os.path.join (moddir, "%s-globals.html" % mod)

            page = htmlHead % ("%s globals" % (mod))
            page += genHTML.globalPage (mod)
            page += htmlFoot

            f = open (globfile, "w")
            f.write (page)
            f.close ()

        for cls in reader.modules [mod]:
    #        print "    %s" % cls
            clsfile = os.path.join (moddir, "%s.html" % cls)

            page = htmlHead % ("class " + cls)
            page += genHTML.classPage (mod, cls)
            page += htmlFoot

            f = open (clsfile, "w")
            f.write (page)
            f.close ()


if __name__ == "__main__":
    config = {}
    config ["PyKDERef"]      = "sip/"
    config ["PyFont"]        = "Sans"
    config ["PyFontSize"]    = 10
    config ["PyFontWeight"]  = 75
    config ["PyFontItalic"]  = True
    config ["CppFont"]       = "Sans"
    config ["CppFontSize"]   = 10
    config ["CppFontWeight"] = 50
    config ["CppFontItalic"] = True
    config ["KDERef"]        = config ["PyKDERef"]
    config ["WebLink"]       = None
#    config = readConfigFile ()

    if len (sys.argv) < 2:
        print "no destination specified"
        sys.exit (1)

    dest = sys.argv [-1]
    config ["PyKDEDocs"]     = os.path.dirname (dest)

    if not dest:
        print "problem with destination or config file"
        sys.exit (1)

    if config:
         writeHTMLFiles (config, dest)