/[gzz]/gzz/metacode/pegboard.py
ViewVC logotype

Diff of /gzz/metacode/pegboard.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by humppake, Mon Nov 11 15:39:26 2002 UTC revision 1.16 by humppake, Tue Nov 12 16:53:03 2002 UTC
# Line 134  pegdirs = [d for d in os.listdir(pegroot Line 134  pegdirs = [d for d in os.listdir(pegroot
134  #holds all information of pegs to show on the pegboard  #holds all information of pegs to show on the pegboard
135  pegtable = []  pegtable = []
136    
 #holds names and subpaths of all generated files under pegroot  
 cvsignore = []  
   
137  #converts all rsts' in pegdirs and parses pegs' meta information  #converts all rsts' in pegdirs and parses pegs' meta information
138  #from pegs' main files  #from pegs' main files
139  for pegdir in pegdirs:  for pegdir in pegdirs:
140      print 'Process PEG %s' % (pegdir)      print 'Process PEG %s' % (pegdir)
141    
142      peg = {'authors': '', 'status': undefined, 'topic': pegdir, 'stakeholders': '',      peg = {'authors': '', 'status': undefined, 'topic': pegdir, 'stakeholders': '',
143             'date': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': '' }             'date': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': '',
144               'rstfiles': [], 'cvsignore': [] }
145    
146      pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \      pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \
147                 if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not f.startswith('.')]                 if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not f.startswith('.')]
# Line 158  for pegdir in pegdirs: Line 156  for pegdir in pegdirs:
156              if pegfile.endswith('.rst'):              if pegfile.endswith('.rst'):
157                  peg['rst'] = pegfile                  peg['rst'] = pegfile
158    
159      rstfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \      rstfiles = [f for f in peg['files'] if f.endswith('.rst')]
                 if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and f.endswith('.rst')]  
160    
161      for rstfile in rstfiles:      for rstfile in rstfiles:
162          #creates and setups a new docutils.core.Publisher, which seems to be          #creates and setups a new docutils.core.Publisher, which seems to be
# Line 177  for pegdir in pegdirs: Line 174  for pegdir in pegdirs:
174              document = pub.reader.read(pub.source, pub.parser, pub.settings)              document = pub.reader.read(pub.source, pub.parser, pub.settings)
175              pub.apply_transforms(document)              pub.apply_transforms(document)
176              output = pub.writer.write(document, pub.destination)              output = pub.writer.write(document, pub.destination)
177              cvsignore.append(pegdir+'/'+rstfile[0:len(rstfile)-4]+'.html')              peg['cvsignore'].append(rstfile[0:len(rstfile)-4]+'.html')
178              peg['html'] = rstfile[0:len(rstfile)-4]+'.html'              peg['html'] = rstfile[0:len(rstfile)-4]+'.html'
179    
180              #conversion have succeeded so far, parsing peg's metadata              #conversion have succeeded so far, parsing peg's metadata
# Line 201  for pegdir in pegdirs: Line 198  for pegdir in pegdirs:
198                  if not peg['stakeholders']:                  if not peg['stakeholders']:
199                      peg['stakeholders'] = getFieldTagValue(document, 'stakeholders')                      peg['stakeholders'] = getFieldTagValue(document, 'stakeholders')
200                  peg['authors'] = getTagValue(document, 'author', all=1)                  peg['authors'] = getTagValue(document, 'author', all=1)
201                else:
202                    status = getTagValue(document, 'status')
203                    if status:
204                        peg['rstfiles'].append({'filename': rstfile, 'status': status})
205                    
206          except:          except:
207              fails += 'PEG %s: Docutil raised an exception while converting %s. ' % (pegdir, rstfile)              fails += 'PEG %s: Docutil raised an exception while converting %s. ' % (pegdir, rstfile)
208              fails += 'Conversion failed and HTML not created.\n'              fails += 'Conversion failed and HTML not created.\n'
# Line 219  for pegdir in pegdirs: Line 221  for pegdir in pegdirs:
221    
222    
223  #converts pegboard.rst, reads results into buffer and opens pegboard.html for writing  #converts pegboard.rst, reads results into buffer and opens pegboard.html for writing
224  print 'Generating '+pegroot+'/pegboard.html...'  print 'Generating '+pegroot+'/pegboard.html'
225  args = '-stg --stylesheet '+css+' '+pegroot+'/pegboard.rst '+pegroot+'/pegboard.html'  args = '-stg --stylesheet '+css+' '+pegroot+'/pegboard.rst '+pegroot+'/pegboard.html'
226  publish_cmdline(writer_name='html', argv=args.split())  publish_cmdline(writer_name='html', argv=args.split())
227    
# Line 274  for pegboard_line in pegboard_lines: Line 276  for pegboard_line in pegboard_lines:
276              replace_str += '\n\t</td>\n'              replace_str += '\n\t</td>\n'
277              replace_str += '\t<td>\n'              replace_str += '\t<td>\n'
278              for file in peg['files']:              for file in peg['files']:
279                  replace_str += '\t\t<a href=\"'+peg['dir']+'/'+file+'\">' \                  try:
280                                 +file+'</a>'                      if peg['cvsignore'].index(file):
281                  if peg['files'].index(file) < len(peg['files']) -1:                          pass
282                      replace_str += '<br/>'                  except ValueError:
283                        converted = 0
284                        status = 0
285                        if file != peg['rst']:
286                            for rstfile in peg['rstfiles']:
287                                if rstfile['filename'] == file:
288                                    status = rstfile['status']
289                            for htmlfile in peg['cvsignore']:
290                                if htmlfile == file[0:len(file)-4]+'.html':
291                                    converted = htmlfile
292                        if converted:
293                            if status:
294                                replace_str += '\t\t<a class=\"peg-'+status.split()[0].lower()+ \
295                                           '\" '+'href=\"'+peg['dir']+'/'+converted+'\">'+ \
296                                           converted+'</a>'
297                            else:
298                                replace_str += '\t\t<a href=\"'+peg['dir']+'/'+converted+'\">'+ \
299                                           converted+'</a>'
300                        else:
301                            replace_str += '\t\t<a href=\"'+peg['dir']+'/'+file+'\">' \
302                                           +file+'</a>'
303                        if peg['files'].index(file) < len(peg['files']) -1:
304                            replace_str += '<br/>\n'
305    
306              replace_str += '\n\t<td>\n'              replace_str += '\n\t<td>\n'
307              replace_str += '</tr>\n'              replace_str += '</tr>\n'
308    
# Line 286  for pegboard_line in pegboard_lines: Line 311  for pegboard_line in pegboard_lines:
311      pegboard.write(pegboard_line)      pegboard.write(pegboard_line)
312    
313  pegboard.close()  pegboard.close()
 cvsignore.append('pegboard.html')  
314    
315  #generate .cvsignore for generated html-files  #generate .cvsignores for generated html-files
316  print 'Replacing '+pegroot+'/.cvsignore...'  if os.path.isfile(pegroot+'/.cvsignore'):
317  cvsignorefile = open(pegroot+'/.cvsignore', 'w')      cvsignorefile = open(pegroot+'/.cvsignore', 'r')
318  for ignore in cvsignore:      if cvsignorefile.read().find('pegboard.html') == -1:
319      cvsignorefile.write(ignore+'\n')          print 'Updating '+pegroot+'/.cvsignore'
320  cvsignorefile.close()          cvsignorefile.close()
321            cvsignorefile = open(pegroot+'/.cvsignore', 'a')
322            cvsignorefile.write('pegboard.html\n')
323        cvsignorefile.close()
324    else:
325        print 'Creating '+pegroot+'/.cvsignore'    
326        cvsignorefile = open(pegroot+'/.cvsignore', 'w')
327        cvsignorefile.write('pegboard.html\n')
328        cvsignorefile.close()
329    
330    for peg in pegtable:
331        if os.path.isfile(pegroot+'/'+peg['dir']+'/.cvsignore'):
332            cvsignorefile = open(pegroot+'/'+peg['dir']+'/.cvsignore', 'r')
333            oldignore = cvsignorefile.read()
334            cvsignorefile.close()
335            cvsignorefile = open(pegroot+'/'+peg['dir']+'/.cvsignore', 'a')
336            for ignore in peg['cvsignore']:
337                if oldignore.find(ignore) == -1:
338                    print 'Updating '+pegroot+'/'+peg['dir']+'/.cvsignore'
339                    cvsignorefile.write(ignore+'\n')
340            cvsignorefile.close()
341        else:
342            print 'Creating '+pegroot+'/'+peg['dir']+'/.cvsignore'        
343            cvsignorefile = open(pegroot+'/'+peg['dir']+'/.cvsignore', 'w')
344            for ignore in peg['cvsignore']:
345                cvsignorefile.write(ignore+'\n')
346            cvsignorefile.close()
347    
348  if fails != 'XXX\n':  if fails != 'XXX\n':
349      print fails      print fails

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26