~ubuntu-branches/ubuntu/trusty/python-sfml/trusty

« back to all changes in this revision

Viewing changes to python/scripts/gen_doc.py

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2013-12-09 17:50:52 UTC
  • mfrom: (1.1.3) (8.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131209175052-11v6drpb6g3yksst
Tags: 1.5.1.is.1.3+dfsg-1
* New upstream version 1.3 (from python-sfml.org)
  - This is a complete rewrite of the Python bindings for SFML2, and
    the new maintainer is using a different version numbering scheme.
* Added myself to the list of uploaders
* Change package priority from extra to optional
* Bumped standards version (to 3.9.5) and debhelper compat (to 9)
* Added Python 3 and documentation packages
* Improve package description for debug packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# coding=UTF-8
3
 
 
4
 
from PySFML import sf
5
 
 
6
 
# Amélioration à faire : trouver les méthodes héritées, et de quelle classe
7
 
 
8
 
def function_str(function, class_name=None):
9
 
        string = ''
10
 
        name = function.__name__
11
 
        doc = function.__doc__
12
 
        if not doc.startswith(name+'('):
13
 
                string += name+"(...)"+'\n'
14
 
        string += doc+'\n'
15
 
        strings = string.split('\n')
16
 
        strings[0] = '<div class="attr_name">'+strings[0]+'</div>\n<div class="desc">'
17
 
        string = strings[0]
18
 
        for s in strings[1:-1]:
19
 
                string += s + '<br />'
20
 
        string += strings[-1]
21
 
        inherited = ''
22
 
        if class_name != None:
23
 
                try:
24
 
                        base_class_name = function.__objclass__.__name__
25
 
                        if base_class_name != class_name:
26
 
                                inherited = '<div class="inherited">Inherited</div>\n'
27
 
                except AttributeError:
28
 
                        pass
29
 
        return string.replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;')+'</div>\n'+inherited
30
 
 
31
 
class FilesManager:
32
 
        def __init__(self):
33
 
                self.files = {}
34
 
                f = open("header.htm")
35
 
                self.header = f.read()
36
 
                f.close()
37
 
                f = open("footer.htm")
38
 
                self.footer = f.read()
39
 
                f.close()
40
 
 
41
 
        def add(self, filename, string):
42
 
                if not self.files.has_key(filename):
43
 
                        self.files[filename] = open('../doc/' + filename + '.html', 'w')
44
 
                        self.files[filename].write(self.header.replace('TITLE', filename))
45
 
                self.files[filename].write(string)
46
 
 
47
 
        def __del__(self):
48
 
                for filename in self.files:
49
 
                        self.files[filename].write(self.footer)
50
 
                        self.files[filename].close()
51
 
 
52
 
 
53
 
def Main():
54
 
 
55
 
        fm = FilesManager()
56
 
 
57
 
        fm.add('index', '<h1>PySFML index</h1>\n')
58
 
 
59
 
        fm.add('index', '<h2>Classes</h2>\n')
60
 
 
61
 
        module_methods = ""
62
 
        module_constants = ""
63
 
 
64
 
        for m in dir(sf):
65
 
                if not m.startswith('__'):
66
 
                        if m == 'Event':
67
 
                                attr = sf.Event()
68
 
                        else:
69
 
                                attr = getattr(sf, m)
70
 
                        if type(attr) == str:
71
 
                                module_constants += '<div class="attr_name">'+m+'</div>\n<div class="desc">"'+attr+'"</div>\n'
72
 
                        elif str(type(attr)) == "<type 'builtin_function_or_method'>" or str(type(attr)) == "<type 'method_descriptor'>":
73
 
                                module_methods += function_str(attr)
74
 
                        else:
75
 
                                fm.add('index', '<a href="'+m+'.html">'+m+'</a><br />\n')
76
 
                                info = {'Attributes':'', 'Constants':'', 'Methods':'', 'Static methods':''}
77
 
                                members = ""
78
 
                                constants = ""
79
 
                                static_methods = ""
80
 
                                methods = ""
81
 
                                for n in dir(attr):
82
 
                                        if not n.startswith('__'):
83
 
                                                attr2 = getattr(attr, n)
84
 
                                                if str(type(attr2)) == "<type 'member_descriptor'>": # member
85
 
                                                        info['Attributes'] += '<div class="attr_name">'+n+'</div>\n<div class="desc">'+attr2.__doc__+'</div>\n'
86
 
                                                elif type(attr2) == long:
87
 
                                                        info['Attributes'] += '<div class="attr_name">'+n+'</div>\n'
88
 
                                                elif type(attr2) == int or type(attr2) == sf.Color: # int or color (constant)
89
 
                                                        info['Constants'] += '<div class="attr_name">'+n+'</div>\n'
90
 
                                                elif str(type(attr2)) == "<type 'builtin_function_or_method'>": # static method
91
 
                                                        info['Static methods'] += function_str(attr2, m)
92
 
                                                elif str(type(attr2)) == "<type 'method_descriptor'>": # method
93
 
                                                        info['Methods'] += function_str(attr2, m)
94
 
                                                elif str(type(attr2)).startswith("<type 'Event."):
95
 
                                                        info['Attributes'] += '<div class="attr_name">'+n+'</div>\n<div class="desc">' + attr2.__doc__+'</div>\n'
96
 
                                                        for o in dir(attr2):
97
 
                                                                if not o.startswith('__'):
98
 
                                                                        attr3 = getattr(attr2, o)
99
 
                                                                        info['Attributes'] += '<div class="event_member"> > ' + o + '</div>\n'
100
 
                                                else:
101
 
                                                        print "Warning : unknown type for " + n + " " + str(type(attr2))
102
 
                                fm.add(m, '<h1>sf.'+m+' Class Reference</h1>\n')
103
 
                                fm.add(m, '<div class="class_desc">'+attr.__doc__.replace('\n', '<br />\n').replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;')+'</div>\n')
104
 
                                if m != 'Event':
105
 
                                        base = attr.__base__.__name__
106
 
                                        if base != 'object':
107
 
                                                fm.add(m, '<div class="base_class">Base class: <a href="'+base+'.html">sf.'+base+'</a>.</div>\n')
108
 
                                for t in info:
109
 
                                        if info[t] != '':
110
 
                                                fm.add(m, '<h2>'+t+'</h2>\n'+info[t]+'<br />\n')
111
 
                                fm.add(m, '<br />\n<br />\n')
112
 
 
113
 
        fm.add('index', '<h2>Module methods</h2>\n' + module_methods)
114
 
 
115
 
        fm.add('index', '<h2>Module constants</h2>\n' + module_constants)
116
 
 
117
 
Main()
118