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