"""
    MoinMoin - Processor for GANTT data

    Copyright (c) 2003 by Reimar Bauer <R.Bauer@fz-juelich.de>
    All rights reserved.

    This routine is published under the GNU Library General Public License

"""

import string, os

from MoinMoin.Page import Page
from MoinMoin import config 
from MoinMoin.action import AttachFile 

htdocs_access = isinstance(config.attachments, type({}))

def process(request, formatter, lines):
    # parse bangpath for arguments
    exclude = []
    image = 'gantt'
    renderer = 'png'
    txt=''
   

    arg=string.split(lines[0])
    
    for test in arg:
      if test == '-name' :
         i=string.index(arg,test)
         image=arg[i+1] 
      if test == '-renderer' :
         i=string.index(arg,test)
         renderer = arg[i+1]
      if test == '-csp':
         txt = txt + ' --csp '
      if test == '-usdates':
         txt = txt + ' --usdates '
      if test == '-datesinbars':
         txt = txt + ' --datesinbars '
      if test == '-rappel':
         txt = txt + ' --rappel '
      if test == '-display-resources':
         txt = txt + ' --display-resources '
      if test == '-display-id' :
         i=string.index(arg,test)
         txt = txt + ' --display-id ' + arg[i+1]
      if test == '-resource':
         i=string.index(arg,test)
         txt = txt + ' --resourcep ' + arg[i+1]
      if test == '-timestep':
         i=string.index(arg,test)
         txt = txt + ' --timestep ' + arg[i+1]
      if test == '-detail':
         i=string.index(arg,test)
         txt = txt + ' --detail ' + arg[i+1]
      if test == '-datesinbars':
         txt = txt + ' --datesinbars '
      if test == '-depth':
         i=string.index(arg,test)
         txt = txt + ' --depth ' + arg[i+1]
      if test == '-view-begin':
         i=string.index(arg,test)
         txt=txt + ' --view-begin=' + arg[i+1]
      if test == '-view-end':
         i=string.index(arg,test)
         txt=txt + ' --view-end=' + arg[i+1]
    # remove bang path, create output list
    del lines[0]
    pagename=formatter.page.page_name
    attach_dir=AttachFile.getAttachDir(pagename,create=1)
    url=AttachFile.getAttachUrl(pagename,image + '.' + renderer)
    file_name=attach_dir+ '/' + image + '.' + renderer
    cmd='pygantt --renderer '+renderer +' ' + txt + ' - > ' + file_name
    f=os.popen(cmd,'w')
    for line in lines:
       print >>f, line
    f.flush()

 
    link='<img src="'+url+'" >' 
    request.write(link)

