Adding Pychart due to bug in recent pychart versions
[odoo/odoo.git] / bin / pychart / generate_docs.py
1 #
2 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
3
4 # Jockey is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2, or (at your option) any
7 # later version.
8 #
9 # Jockey is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 # for more details.
13 #
14 import string
15 import doc_support
16 import sys
17 import re
18 import os
19
20 import area
21 import arrow
22 import axis
23 import bar_plot
24 import line_plot
25 import pie_plot
26 import color
27 import error_bar
28 import fill_style
29 import font
30 import text_box
31 import line_style
32 import legend
33 import range_plot
34 import tick_mark
35
36 indent = 4
37 max_line_len = 64
38
39 def format_paragraph(fp, str):
40     line_len = indent
41     fp.write(" " * indent)
42     for word in str.split():
43         if line_len >= max_line_len:
44             fp.write("\n")
45             fp.write(" " * indent)
46             line_len = indent
47         fp.write(word + " ")
48         line_len += len(word) + 1
49         
50 def format_string(fp, str):
51     str = re.sub("<<([^>]+)>>", "See also pychart.\\1", str)
52
53     str2 = ""
54     in_example = 0
55     for l in str.split("\n"):
56         if re.match("@example", l):
57             in_example = 1
58         if re.match("@end example", l):
59             in_example = 0
60         if in_example:
61             str2 += l
62         else:
63             l = re.sub("^[ \t]*", "", l)
64             str2 += l
65         str2 += "\n"    
66     fname = os.tempnam()
67     out_fp = open(fname, "w")
68     out_fp.write(str2)
69     out_fp.close()
70     
71     in_fp = os.popen("makeinfo --fill-column=64 --no-headers " + fname, "r")
72     for l in in_fp.readlines():
73         fp.write(" " * indent)
74         fp.write(l)
75     in_fp.close()
76     os.remove(fname)
77     
78 def generate_doc(c, name, suffix="", append = 0):
79     if append:
80         fp = open(name + "_doc.py", "a+")
81     else:
82         fp = open(name + "_doc.py", "w")
83         fp.write("# automatically generated by generate_docs.py.\n")
84         
85     fp.write("doc" + suffix + "=\"\"\"Attributes supported by this class are:\n")
86     for key in c.keys.keys():
87             val=c.keys[key]
88             desc = ""
89             defaultValDesc = None
90             if len(val) > 3:
91                 desc = val[3]
92             if len(val) > 4:
93                 defaultValDesc = val[4]
94                 
95             fp.write(key + "(type:" + doc_support.stringify_type(val[0]))
96             if defaultValDesc:
97                 fp.write(") default:" + defaultValDesc)
98             else:
99                 fp.write(") default=" + str(doc_support.stringify_value(val[2])) + ".\n")
100             format_string(fp, desc)
101     fp.write("\"\"\"\n\n")           
102     fp.close()
103
104
105 generate_doc(arrow.T, "arrow")
106 generate_doc(area.T, "area")
107 generate_doc(axis.X, "axis", "_x")
108 generate_doc(axis.Y, "axis", "_y", 1)
109 generate_doc(bar_plot.T, "bar_plot")
110 generate_doc(line_plot.T, "line_plot")
111 generate_doc(pie_plot.T, "pie_plot")
112 generate_doc(color.T, "color")
113 generate_doc(error_bar.error_bar1, "error_bar","_1")
114 generate_doc(error_bar.error_bar2, "error_bar", "_2", 1)
115 generate_doc(error_bar.error_bar3, "error_bar", "_3", 1)
116 generate_doc(error_bar.error_bar4, "error_bar", "_4", 1)
117 generate_doc(error_bar.error_bar5, "error_bar", "_5", 1)
118 generate_doc(error_bar.error_bar6, "error_bar", "_6", 1)
119 generate_doc(fill_style.T, "fill_style")
120 generate_doc(text_box.T, "text_box")
121 generate_doc(range_plot.T, "range_plot")
122 generate_doc(legend.T, "legend")
123 generate_doc(legend.Entry, "legend", "_entry", 1)
124 generate_doc(line_style.T, "line_style")
125 generate_doc(tick_mark.T, "tick_mark")