[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz metacode/pegboard.py ./TODO
From: |
Asko Soukka |
Subject: |
[Gzz-commits] gzz metacode/pegboard.py ./TODO |
Date: |
Tue, 05 Nov 2002 11:19:54 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Asko Soukka <address@hidden> 02/11/05 11:19:53
Modified files:
metacode : pegboard.py
. : TODO
Log message:
Pegboard is now more tidy / works faster. Note! If you get 'No module
named docutils.XXX' check for newer version of docutils, I guess :)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/metacode/pegboard.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/TODO.diff?tr1=1.369&tr2=1.370&r1=text&r2=text
Patches:
Index: gzz/TODO
diff -u gzz/TODO:1.369 gzz/TODO:1.370
--- gzz/TODO:1.369 Tue Nov 5 04:12:31 2002
+++ gzz/TODO Tue Nov 5 11:19:53 2002
@@ -77,10 +77,8 @@
createPaperQuad, since that's the most flexible approach.
- porting: make sure all demos etc. work with plain mesa
humppake:
- - script to generate index for pegboard
- - converts now almost every rst twice, one should
- be enough
- - fix older pegs if necessary
+ - small peg about vobcoorder changes for culling (actually
+ already made it once, but somehow failed to commit... %-)
+ more about PEG1018 - generalizing VobVanishingClient
+ rethink interfaces between PlainVanishing and VobScene
- learn Box
Index: gzz/metacode/pegboard.py
diff -u gzz/metacode/pegboard.py:1.8 gzz/metacode/pegboard.py:1.9
--- gzz/metacode/pegboard.py:1.8 Mon Nov 4 14:34:22 2002
+++ gzz/metacode/pegboard.py Tue Nov 5 11:19:53 2002
@@ -20,135 +20,163 @@
# because of hardcoded pegroot and css.
import sys, os, os.path
-from docutils.frontend import OptionParser
-from docutils.utils import new_document
-from docutils.parsers.rst import Parser
-from docutils.core import publish_cmdline
+import sys
+from docutils import Component
+from docutils import frontend, io, readers, parsers, writers
+from docutils.core import publish_cmdline, Publisher
+from docutils.frontend import OptionParser, ConfigParser
+#collects error messages
fails = 'XXX\n'
+
+#relative or absolute location of pegboard directory
pegroot = 'doc/pegboard'
+
+#CSS' location relative to pegroot
css = '../gzz.css'
-replace = '<p>INSERT_PEGBOARD</p>\n'
+
+#macro in pegroot/pegboard.rst to replace with pegboard table
+replace = '<p>INSERT_PEGBOARD</p>\n'
+
+#pegs will be sorted after their priority
priority = {'Current': 1, 'Revising': 2, 'Accepted': 3, 'Incomplete': 4,
'Implemented': 5, 'Rejected': 6, 'Irrelevant': 7, 'Undefined': 8}
+#status for pegs without rst or with failing rst
+undefined = 'Undefined'
+
class _:
def __init__(self, **attrs):
for (k,v) in attrs.items(): setattr(self, k, v)
+#comparison function used when sorting pegs
+#compares pegs' status at first and if they are same
+#compares dates pegs are last updated
def pegcmp(a, b):
if priority.has_key(a['status'].capitalize().split(' ')[0]) \
and priority.has_key(b['status'].capitalize().split(' ')[0]) \
and not a['status'] == b['status']:
return priority[a['status'].capitalize().split(' ')[0]] \
> priority[b['status'].capitalize().split(' ')[0]] or -1
- as = a['date'].split('/')
- bs = b['date'].split('/')
+
+ as = a['date'].split('-')
+ bs = b['date'].split('-')
if not len(as) == 3 or not len(bs) == 3:
return len(as) < len(bs) or (len(bs) < len(as)) * -1 or 0
ac = as[0]*356 + as[1]*30 + as[2]
bc = bs[0]*356 + bs[1]*30 + bs[2]
return ac < bc or (bc < ac) * -1 or 0
+#returns the value of the first occurrense of
+#given tagName in docutils' document tree
def getTagValue(document, tagName):
if document.tagname.lower() == tagName.lower():
- return document.rawsource
+ if hasattr(document.children[0], 'data'):
+ return document.children[0].data
+ else:
+ return document.rawsource
if hasattr(document, 'children'):
for child in document.children:
value = getTagValue(child, tagName)
if value:
return value
return ''
-
-def getFieldValue(document, fieldName):
- if document.tagname.lower() == 'field':
- if document.children[0].rawsource.lower() == fieldName.lower():
- return document.children[1].rawsource
- if hasattr(document, 'children'):
- for child in document.children:
- value = getFieldValue(child, fieldName)
- if value:
- return value
- return ''
pegdirs = [d for d in os.listdir(pegroot+'/')
if os.path.isdir(pegroot+'/'+d) and d != 'CVS']
-#loop one: converting pegs
+#holds all information of pegs to show on the pegboard
+pegtable = []
+
+#holds names and subpaths of all generated files under pegroot
+cvsignore = []
+
+#converts all rsts' in pegdirs and parses pegs' meta information
+#from pegs' main files
for pegdir in pegdirs:
- rstfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/')
+ print 'Process PEG %s' % (pegdir)
+
+ peg = {'author': '', 'status': undefined, 'topic': pegdir, 'stakeholders':
'',
+ 'date': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': '' }
+
+ pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \
+ if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not
f.startswith('.')]
+
+ peg['files'] = pegfiles
+
+ try:
+ index = pegfiles.index('peg.rst')
+ peg['rst'] = pegfiles[index]
+ except ValueError:
+ for pegfile in peg['files']:
+ if pegfile.endswith('.rst'):
+ peg['rst'] = pegfile
+
+ rstfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \
if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and
f.endswith('.rst')]
- print 'Process PEG %s' % (pegdir)
for rstfile in rstfiles:
- file = pegroot+'/'+pegdir+'/'+rstfile[0:len(rstfile)-4] #Python2.2:
.rstrip('.rst')
-
- # Sets docutils' "command line arguments"
+ #creates and setups a new docutils.core.Publisher, which seems to be
+ #easy interface to use docutils
+ pub = Publisher()
+ pub.set_reader('standalone', None, 'restructuredtext')
+ pub.set_writer('html')
+ file = pegroot+'/'+pegdir+'/'+rstfile[0:len(rstfile)-4]
args = '-stg --stylesheet ../'+css+' %s.rst %s.html' % (file,file)
-
- # Generate the HTML
+ pub.process_command_line(argv=args.split())
+
+ #conversion may fail because of bad restructuredtext
try:
- publish_cmdline(writer_name='html', argv=args.split())
+ pub.set_io()
+ document = pub.reader.read(pub.source, pub.parser, pub.settings)
+ pub.apply_transforms(document)
+ output = pub.writer.write(document, pub.destination)
+ cvsignore.append(pegdir+'/'+rstfile[0:len(rstfile)-4]+'.html')
+ peg['html'] = rstfile[0:len(rstfile)-4]+'.html'
+
+ #conversion have succeeded so far, parsing peg's metadata
+ #from its document tree
+ if rstfile == peg['rst']:
+ peg['topic'] = getTagValue(document, 'title')
+ peg['topic'] = peg['topic'].replace('`', '')
+ peg['date'] = getTagValue(document, 'date')
+ #we may have got 'rawsource', which need some tidying
+ if peg['date'].startswith('$Date'):
+ peg['date'] =
peg['date'][7:len(peg['date'])-11].replace('/', '-')
+ peg['status'] = getTagValue(document, 'status') or undefined
+ peg['stakeholders'] = getTagValue(document, 'stakeholders')
+ peg['author'] = getTagValue(document, 'author') or \
+ getTagValue(document, 'authors')
except:
- fails += 'PEG %s: Docutil raised an exception while converting %s.
' % (pegdir, f)
+ fails += 'PEG %s: Docutil raised an exception while converting %s.
' % (pegdir, rstfile)
fails += 'Conversion failed and HTML not created.\n'
-print 'Generating pegboard2.html...\n'
-args = '-stg --stylesheet '+css+' '+pegroot+'/pegboard.rst
'+pegroot+'/pegboard2.html'
+ if not peg['html']:
+ for file in peg['files']:
+ if file[len(file)-5:len(file)] == '.html':
+ peg['html'] = file
+ break
+ elif file[len(file)-4:len(file)] in ('.rst', '.txt'):
+ peg['html'] = file
+ break
+
+ #finally adds peg's metadata into pegtable
+ pegtable.append(peg)
+
+
+#converts pegboard.rst, reads results into buffer and opens pegboard.html for
writing
+print 'Generating '+pegroot+'/pegboard.html...\n'
+args = '-stg --stylesheet '+css+' '+pegroot+'/pegboard.rst
'+pegroot+'/pegboard.html'
publish_cmdline(writer_name='html', argv=args.split())
-pegboard = open (pegroot+'/pegboard2.html', 'r')
+pegboard = open (pegroot+'/pegboard.html', 'r')
pegboard_lines = pegboard.readlines()
pegboard.close()
-pegboard = open (pegroot+'/pegboard2.html', 'w')
+pegboard = open (pegroot+'/pegboard.html', 'w')
-#loop two: parsing information from pegs
for pegboard_line in pegboard_lines:
+ #when replace 'macro' is founded, generate pegtable and replace it
if pegboard_line.find(replace) != -1:
- pegtable = []
-
- for pegdir in pegdirs:
- peg = {'author': '', 'status': 'Undefined', 'topic': pegdir,
'stakeholders': '',
- 'date': '', 'dir': pegdir,
- 'files': '', 'html': '', 'rst': '' }
- pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/')
- if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not
f.startswith('.')]
- peg['files'] = pegfiles
- for pegfile in pegfiles:
- if not peg['html']:
- if pegfile == 'peg.html' or pegfile ==
'PEG_'+pegdir+'.html':
- peg['html'] = pegfile
- if not peg['rst']:
- if pegfile == 'peg.rst' or pegfile == 'PEG_'+pegdir+'.rst':
- peg['rst'] = pegfile
- if not peg['html'] and peg['files']:
- peg['html'] = peg['files'][0]
- if not peg['rst']:
- for pegfile in peg['files']:
- if pegfile.endswith('.rst'):
- peg['rst'] = pegfile
- pegtable.append(peg)
-
- for peg in pegtable:
- if peg['rst'] and peg['html'].endswith('.html'):
- inputFile = sys.stdin
- inputFile = open(pegroot+'/'+peg['dir']+'/'+peg['rst'])
- settings =
OptionParser(components=(Parser,)).get_default_values()
- parser = Parser()
- input = inputFile.read()
- document = new_document(inputFile.name, settings)
- parser.parse(input, document)
-
- peg['topic'] = getTagValue(document, 'title')
- peg['topic'] = peg['topic'].replace('`', '')
- peg['date'] = getFieldValue(document, 'date')
- if peg['date'].startswith('$Date'):
- peg['date'] = peg['date'][7:len(peg['date'])-11]
- peg['status'] = getFieldValue(document, 'status') or
'Undefined'
- peg['stakeholders'] = getFieldValue(document, 'stakeholders')
- peg['author'] = getFieldValue(document, 'author') or \
- getFieldValue(document, 'authors')
-
pegtable.sort(pegcmp)
replace_str = '<table class=\"pegboard\">\n<tr>\n'
@@ -178,9 +206,22 @@
replace_str += '</table>\n'
pegboard_line = pegboard_line.replace(replace, replace_str)
pegboard.write(pegboard_line)
+
pegboard.close()
+cvsignore.append('pegboard.html')
+
+#generate .cvsignore for generated html-files
+print 'Replacing '+pegroot+'/.cvsignore...\n'
+cvsignorefile = open(pegroot+'/.cvsignore', 'w')
+for ignore in cvsignore:
+ cvsignorefile.write(ignore+'\n')
+cvsignorefile.close()
print fails
+
+
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz metacode/pegboard.py ./TODO,
Asko Soukka <=