Attachment 'Gantt-1.3.3-2.py'
Download 1 """
2 MoinMoin - Parser for GANTT data based on pygantt from http://www.logilab.org/projects/pygantt
3
4 Copyright (c) 2003 by Reimar Bauer <R.Bauer@fz-juelich.de>
5
6 This routine is published under the GNU Library General Public License
7
8
9 PURPOSE:
10 This parser is used to visualize gantt data in MoinMoin.
11
12 CALLING SEQUENCE:
13 {{{
14 #!Gantt [name=name, renderer=renderer, width=width, height=height,
15 usdates=, datesinbars=, rappel=,display-resources=,
16 timestep=timestep,detail=[0,1,2,3],datesinbars=,
17 view-begin=view-begin,view-end=view-end ]
18 }}}
19
20
21 KEYWORD PARAMETERS:
22
23 parts of the descriptions are taken from the man page of pygantt
24
25 name=name: optional if set this is the name of the gantt result image
26 renderer=renderer: default is png, optional if set the type
27 [tiff, jpeg, png,gif or svg] is used to tender the gantt chart
28 width=width: optional if set it is the width of the output image
29 height=height: optional if set it is the height of the outputt image
30
31 usdates=: optional US can't help write dates backwards...
32 datesinbars=: optional write begin/end dates in task bars.
33 rappel=: optional recall tasks'title on the left hand side of the diagram
34 display-resources=:: optional Display resources on the Gantt chart
35 timestep=timestep: optional timeline increment in days for diagram [default=1].
36 detail=detail: optional detail level [0=no 1=duration/status 2=begin/end 3=all].
37 datesinbars=: optional write begin/end dates in task bars.
38 view-begin=view-begin: optional view begin date, as in --view-begin=2000/12/24.
39 view-end=view-end: optional view end date, as in --view-end=2000/12/24.
40
41 EXAMPLE:
42 {{{
43 { { {#!Gantt view-end=2005/03/14,
44 <project xmlns:pg="http://www.logilab.org/namespaces/pygantt_docbook" id="monprojet">
45 <label>Specification</label>
46 <task id="module">
47 <label>Module Gantt.py</label>
48 <task id="func1">
49 <label>Implementation Parser</label>
50 <duration>2</duration>
51 <constraint type="begin-after-date">2005/03/03</constraint>
52 </task>
53 <task id="func2">
54 <label>Testing</label>
55 <duration>3</duration>
56 <constraint type="begin-after-date">2005/03/05</constraint>
57 </task>
58 </task>
59 <task id="documentation">
60 <label>Documentation</label>
61 <task id="doc_func1">
62 <label>Documentation Gantt.py</label>
63 <duration>1</duration>
64 <constraint type="begin-after-end">func1</constraint>
65 </task>
66 <task id="doc_func2">
67 <label>Examples</label>
68 <duration>3</duration>
69 <constraint type="begin-after-end">func2</constraint>
70 </task>
71 </task>
72 </project>
73 } } }
74 }}}
75
76 PROCEDURE:
77 This parser uses the pygantt from http://www.logilab.org/projects/pygantt
78
79 Please remove the version number from the file.
80
81 RESTRICTIONS:
82
83 MODIFICATION:
84 Copyright (c) 2003 by Reimar Bauer <R.Bauer@fz-juelich.de>
85
86 This routine is published under the GNU Library General Public License
87
88 2004-04-15 : Daniel Hottinger code fix to work with moin 1.2.1
89
90 2005-03-05: changed to parser Vesion: 1.3.3-1
91 2005-04-12: 1.3.3-2 bug fixed the parser does not work on subpages recogniced by JunHu
92 : bug fixed if highligting by e.g. search was used.
93
94
95 DISCUSSION:
96
97 """
98 Dependencies = []
99 import string, os, re, sha
100
101
102 from MoinMoin.Page import Page
103 from MoinMoin import wikiutil,config
104 from MoinMoin.action import AttachFile
105
106 def param_test(listof,key):
107 for arg in listof:
108 if (arg == key):
109 return(1)
110 return(0)
111
112 class Parser:
113 def __init__(self, raw, request, **kw):
114
115 self.raw = raw
116 self.request = request
117 self.kw = []
118 for arg in kw.get('format_args','').split(','):
119 self.kw.append(arg)
120
121 def format(self, formatter):
122
123 lines = self.raw.split('\n')
124
125 args=self.kw
126
127 kw ={} # create a dictionary for the formatter.image call
128 exclude = []
129
130 texstr = ''.join(args)+'\n'.join(lines).strip()
131 imgname = re.sub('\s+', ' ', texstr)
132 imgname = sha.new(imgname).hexdigest()
133 kw['name'] = imgname + "_gantt"
134
135 pgparams=['usdates','datesinbars','rappel','display-resources','timestep','detail',
136 'datesinbars','view-begin','view-end' ]
137
138 kw['renderer'] = 'png'
139 txt=''
140
141 count=0
142
143
144 for a in args :
145 if (a.find('=') > -1):
146 count=count+1
147 key=a.split('=')
148 sep='='
149 if (key[1].strip() == '') :
150 sep=''
151 if (param_test(pgparams,str(key[0].strip())) == 1):
152 txt +=" --%(arg)s%(sep)s%(val)s" %{
153 "arg":key[0].strip(),
154 "sep":sep,
155 "val":key[1].strip()}
156
157 else:
158 kw[str(key[0].strip())]=wikiutil.escape(string.join(key[1],'').strip(), quote=1)
159
160 pagename=formatter.page.page_name
161
162
163 file_name="%(name)s.%(renderer)s" %{
164 "name":kw['name'],
165 "renderer":kw['renderer']}
166
167 attach_dir=AttachFile.getAttachDir(self.request,pagename,create=1)
168 kw['src']=AttachFile.getAttachUrl(pagename, file_name,self.request)
169
170
171 file="%(attach_dir)s/%(file_name)s" %{
172 "attach_dir":attach_dir,
173 "file_name":file_name}
174
175 if not os.path.isfile(file):
176
177 cmd="pygantt --renderer=%(renderer)s %(txt)s - > '%(file)s'" %{
178 "renderer":kw['renderer'],
179 "txt":txt,
180 "file":file}
181
182 f=os.popen(cmd,'w')
183 for line in lines:
184 print >>f, line
185 f.flush()
186
187 kw['title']=kw['name']
188 kw['alt']=kw['name']
189
190 image_link=formatter.image(**kw)
191
192 self.request.write(formatter.url(1,kw['src'])+image_link +formatter.url(0))
193 return()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.