Subversion Repositories Scribus

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1062 subik 1
# -*- coding: Utf8 -*-
1535 subik 2
import sys
3
import inspect
4
import types
1062 subik 5
 
1535 subik 6
sys.setappdefaultencoding('utf8')
1062 subik 7
 
1535 subik 8
#import scribus - I need all into locals()
9
from scribus import *
1062 subik 10
 
1535 subik 11
PyCObjectType = type(qApp)
1062 subik 12
 
1535 subik 13
def checkObject(name):
14
        if name in ['parseDocString', 'docHeader', 'docFooter', 'PyCObjectType', 'checkObject']:
15
                return 1
16
        return 0
1062 subik 17
 
1535 subik 18
def parseDocString(name, dstr = " ", optval=None):
19
        """Makes HTML from plain text"""
20
        ret = '\t<dt><b>'+ name + '</b></dt>\n\t<dd><pre><p>'
21
        ret = ret + str(dstr).replace('\n\n', '</p><p>')#rows[0]
22
        ret = ret + '</p>' #</p>\n\t<p>'
23
        if optval:
24
                ret = ret + '<p>Value: ' + str(optval) + '</p>'
25
        return ret.replace('<p></p>', '') + '</pre></dd>\n\n'
1062 subik 26
 
27
 
1535 subik 28
def docHeader(fname):
29
        return fname.write("<qt><dl>\n\n")
1062 subik 30
 
31
 
1535 subik 32
def docFooter(fname):
33
        return fname.write("\n\n</dl></qt>")
1062 subik 34
 
35
 
1535 subik 36
const = []
37
proc = []
38
classes = []
39
excep = []
40
strs = []
41
cobj = []
1062 subik 42
 
1535 subik 43
print '\n\n'
1062 subik 44
 
1535 subik 45
for name, var in locals().items():#globals().items():
46
        v = type(var)
47
        if checkObject(name):
48
                continue
49
        # constants
50
        if v == types.IntType or v == types.TupleType:
51
                const.append((name, var))
52
                continue
53
        # functions or procedures
54
        if v == types.FunctionType or v == types.MethodType or v == types.BuiltinFunctionType or v == types.BuiltinMethodType:
55
                proc.append((name, inspect.getdoc(var) or inspect.getcomments(var)))#var.__doc__))
56
                continue
57
        # Classes (types)
58
        if v == types.TypeType and v != PyCObjectType:
59
                classes.append((name, inspect.getdoc(var) or inspect.getcomments(var)))
60
                continue
61
        if v == types.ClassType:
62
                excep.append((name, inspect.getdoc(var) or inspect.getcomments(var)))
63
                continue
64
        if v == types.StringType:
65
                strs.append((name, inspect.getdoc(var) or inspect.getcomments(var), var))
66
                continue
67
        if v == PyCObjectType:
68
                cobj.append((name, inspect.getdoc(var) or inspect.getcomments(var), var))
69
                continue
70
        print 'UNDOCUMENTED: '+ name+ ' '+ str(v)
1062 subik 71
 
72
 
1535 subik 73
import glob
74
origdocs = glob.glob('/home/subzero/devel/SCRIBUS13/share/scribus/doc/en/scripterapi-*.html')
75
docmap = {}
76
for i in origdocs:
77
        f = file(i, 'r')
78
        docmap[i] = (f.read(), '\n')
79
        f.close()
1062 subik 80
 
1535 subik 81
f = file('scripterapi-constants.html', 'w')
82
docHeader(f)
83
const.sort()
84
for i in const:
85
        f.write(parseDocString(i[0], 'Predefined constant', i[1]))
86
docFooter(f)
87
f.close()
1062 subik 88
 
1535 subik 89
import string
90
proc.sort()
91
unresolved = ''
92
isresolved = 0
93
for i in proc:
94
        isresolved = 0
95
        for j in docmap:
96
                if string.find(docmap[j][0], i[0]) > 0:
97
                        docmap[j] = (docmap[j][0], docmap[j][1] + parseDocString(i[0], i[1]))
98
                        isresolved = 1
99
        if isresolved == 0:
100
                unresolved = unresolved + parseDocString(i[0], i[1])
1062 subik 101
 
1535 subik 102
if len(unresolved) > 0:
103
        f = file('UNKNOWN.html', 'w')
104
        f.write(unresolved)
105
        f.close()
1062 subik 106
 
1535 subik 107
import os.path
108
for i in docmap:
109
        f = file(os.path.basename(i), 'w')
110
        docHeader(f)
111
        f.write(docmap[i][1])
112
        docFooter(f)
113
        f.close()
1062 subik 114
 
1535 subik 115
import scribus
116
classes.sort()
117
for i in classes:
118
        f = file('scripterapi-'+i[0]+'.html', 'w')
119
        docHeader(f)
120
        f.write(parseDocString(i[0], i[1]))
1063 subik 121
        try:
1535 subik 122
                d = dir(getattr(scribus, i[0]))
1063 subik 123
        except:
1535 subik 124
                d = []
125
        if len(d) == 0:
126
                continue
127
        d.sort()
128
        for j in d:
129
                if j[:2] != '__':
130
                        obj = getattr(getattr(scribus, i[0]), j)
131
                        f.write(parseDocString(j, inspect.getdoc(obj) or inspect.getcomments(obj)))
132
        docFooter(f)
133
        f.close()
1062 subik 134
 
1535 subik 135
f = file('scripterapi-exceptions.html', 'w')
136
docHeader(f)
137
excep.sort()
138
for i in excep:
139
        f.write(parseDocString(i[0], i[1]))
140
docFooter(f)
141
f.close()
1062 subik 142
 
1535 subik 143
f = file('scripterapi-strings.html', 'w')
144
docHeader(f)
145
strs.sort()
146
for i in strs:
147
        f.write(parseDocString(i[0], i[1], i[2]))
148
docFooter(f)
149
f.close()
1062 subik 150
 
1535 subik 151
f = file('scripterapi-cobjects.html', 'w')
152
docHeader(f)
153
cobj.sort()
154
for i in cobj:
155
        f.write(parseDocString(i[0], i[1]))
156
docFooter(f)
157
f.close()
1062 subik 158
 
1535 subik 159
"""
160
f = file('SCRIBUS.html', 'w')
161
docHeader(f)
162
f.write(parseDocString('Scribus Python API', inspect.getdoc(scribus) or inspect.getcomments(scribus)))
163
docFooter(f)
164
f.close()
165
"""