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.
  • [get | view] (2006-02-16 14:59:57, 14.6 KB) [[attachment:Calendar-20060216.py]]
  • [get | view] (2007-05-28 09:42:03, 2.7 KB) [[attachment:ExcelPastedTable.py]]
  • [get | view] (2005-04-12 19:22:18, 6.0 KB) [[attachment:Gantt-1.3.3-2.py]]
  • [get | view] (2007-03-24 02:05:26, 3.9 KB) [[attachment:Literate_parser-0.7_Moin-1.3.tgz]]
  • [get | view] (2007-03-24 02:08:08, 4.8 KB) [[attachment:Literate_parser-0.7_Moin-1.3.zip]]
  • [get | view] (2005-03-11 13:50:49, 12.3 KB) [[attachment:MySQL.py]]
  • [get | view] (2005-09-11 08:09:44, 1.6 KB) [[attachment:SortText-1.3.5-1.py]]
  • [get | view] (2005-11-21 08:40:10, 2.8 KB) [[attachment:Sorter-1.3.py]]
  • [get | view] (2005-06-02 13:02:06, 1.2 KB) [[attachment:colorer.py]]
  • [get | view] (2006-01-04 16:10:31, 0.6 KB) [[attachment:gettext.py]]
  • [get | view] (2004-10-19 13:05:05, 0.7 KB) [[attachment:html-parser-1.2.py]]
  • [get | view] (2005-02-17 10:46:56, 0.6 KB) [[attachment:html.py]]
  • [get | view] (2005-12-06 21:09:48, 1.3 KB) [[attachment:matlab.py]]
  • [get | view] (2005-01-20 07:42:34, 0.4 KB) [[attachment:nocamelcase.py]]
  • [get | view] (2005-11-28 16:55:23, 2.3 KB) [[attachment:php-1.3.4-1]]
  • [get | view] (2005-12-18 22:36:37, 15.0 KB) [[attachment:sctable-1.3.5-4.py]]
  • [get | view] (2004-12-31 04:41:23, 1.6 KB) [[attachment:textil.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.