gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/metacode pegboard.py


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/metacode pegboard.py
Date: Fri, 15 Nov 2002 16:42:20 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      02/11/15 16:42:20

Modified files:
        metacode       : pegboard.py 

Log message:
        hups, forgot to commit here :-)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/metacode/pegboard.py.diff?tr1=1.20&tr2=1.21&r1=text&r2=text

Patches:
Index: gzz/metacode/pegboard.py
diff -u gzz/metacode/pegboard.py:1.20 gzz/metacode/pegboard.py:1.21
--- gzz/metacode/pegboard.py:1.20       Fri Nov 15 02:46:29 2002
+++ gzz/metacode/pegboard.py    Fri Nov 15 16:42:20 2002
@@ -19,10 +19,10 @@
 # Must be run in the main directory (the one Makefile is in),
 # because of hardcoded pegroot and css.
 
-import sys, os, os.path
-import sys
+import sys, os, os.path, string
+import docutils
 from docutils import Component
-from docutils import frontend, io, readers, parsers, writers
+from docutils import frontend, io, readers, parsers, writers, nodes
 from docutils.core import publish_cmdline, Publisher
 from docutils.frontend import OptionParser, ConfigParser
 
@@ -53,6 +53,7 @@
 authors = {'Tuomas Lukka': 'tjl',
            'Tuomas J. Lukka': 'tjl',
            'Benja Fallenstein': 'benja',
+           'Benja': 'benja',
            'Asko Soukka': 'humppake',
            'Matti Katila': 'mudyc',
            'Anton Feldmann': 'anton',
@@ -139,12 +140,13 @@
 for pegdir in pegdirs:
     print 'Processing PEG %s' % (pegdir)
 
-    peg = {'authors': '', 'status': undefined, 'topic': pegdir, 
'stakeholders': '', 
+    peg = {'authors': [], 'status': undefined, 'topic': pegdir, 
'stakeholders': [], 
            'last-modified': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': 
'',
            'rstfiles': [], 'cvsignore': [] }
 
     pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \
-               if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not 
f.startswith('.')]
+               if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not 
f.startswith('.')
+                  and '#' not in f and '~' not in f]
 
     peg['files'] = pegfiles
 
@@ -194,9 +196,10 @@
                 if peg['last-modified'].startswith('$Date'):
                     peg['last-modified'] = 
peg['last-modified'][7:len(peg['last-modified'])-11].replace('/', '-')
                 peg['status'] = getTagValue(document, 'status') or undefined
-                peg['stakeholders'] = getFieldTagValue(document, 'stakeholder')
-                if not peg['stakeholders']:
-                    peg['stakeholders'] = getFieldTagValue(document, 
'stakeholders')
+                stakeholders = getFieldTagValue(document, 'stakeholder')
+                if not stakeholders:
+                    stakeholders = getFieldTagValue(document, 'stakeholders')
+                peg['stakeholders'] = [s.strip() for s in 
stakeholders.split(',')]
                 peg['authors'] = getTagValue(document, 'author', all=1)
             else:
                 status = getTagValue(document, 'status')
@@ -220,97 +223,139 @@
     pegtable.append(peg)
 
 
+#create the ``.. pegboard::`` directive
+
+def pegboard_directive(*args):
+    pegtable.sort(pegcmp)
+
+    table = nodes.table(class='pegboard')
+    tgroup = nodes.tgroup(cols=6)
+    table += tgroup
+
+    thead = nodes.thead()
+    tgroup += thead
+    row = nodes.row()
+    thead += row
+
+    for col in ['Status', 'Name', 'Topic', 'Authors',
+                'Stakeholders', 'Files']:
+        entry = nodes.entry()
+        row += entry
+        para = nodes.paragraph()
+        entry += para
+        para += nodes.Text(col)
+
+    tbody = nodes.tbody()
+    tgroup += tbody
+
+    for peg in pegtable:
+        status = peg['status'].split()
+
+        if status:
+            peg_class = 'peg-' + status[0].lower()
+            row = nodes.row(class=peg_class)
+        else:
+            row = nodes.row()
+            
+        tbody += row
+
+        def get_author(s):
+            if authors.has_key(s): return authors[s]
+            else: return s
+
+        _authors = [get_author(s) for s in peg['authors']]
+        _stakeholders = [get_author(s) for s in peg['stakeholders']]
+
+        ref = nodes.reference(refuri=peg['dir']+'/'+peg['html'])
+        text = nodes.Text(peg['dir'].split('--')[0])
+        ref += text
+
+        status_field = peg['status'].split()
+        status_comment = nodes.Text(string.join(status_field[1:]))
+        status_emph = nodes.emphasis()
+        status_emph += status_comment
+        
+        status = [
+            nodes.Text(status_field[0] + " "),
+            status_emph
+        ]
+        
+        row += td(status, class='peg_status_field')
+        row += td(ref, class='peg_name_field')
+        row += td(peg['topic'].split(':')[-1], class='peg_topic_field')
+        row += td(string.join(_authors, ', '), class='peg_authors_field')
+        row += td(string.join(_stakeholders, ', '), 
class='peg_stakeholders_field')
+        row += make_files(peg)
+    
+    return [table]
+
+def td(__node, **args):
+    if isinstance(__node, type('')):
+        __node = nodes.Text(__node)
+        
+    entry = nodes.entry(**args)
+    para = nodes.paragraph()
+    entry += para
+    para += __node
+    return entry
+    
+
+def make_files(peg):
+    para = nodes.paragraph()
+    entry = nodes.entry(class='peg_files_field')
+    entry += para
+    
+    for file in peg['files']:
+        try:
+            if peg['cvsignore'].index(file):
+                pass
+        except ValueError:
+            converted = 0
+            status = 0
+            if file != peg['rst']:
+                for rstfile in peg['rstfiles']:
+                    if rstfile['filename'] == file:
+                        status = rstfile['status']
+                for htmlfile in peg['cvsignore']:
+                    if htmlfile == file[0:len(file)-4]+'.html':
+                        converted = htmlfile
+            if converted:
+                href = peg['dir'] + '/' + converted
+
+                if status:
+                    klass = 'peg-'+status.split()[0].lower()
+                    ref = nodes.reference(anonymous=1, class=klass, 
refuri=href)
+                else:
+                    ref = nodes.reference(anonymous=1, refuri=href)
+                    
+                text = nodes.Text(converted)
+
+                ref += text
+                para += ref
+            else:
+                href = peg['dir'] + '/' + file
+                ref = nodes.reference(anonymous=1, refuri=href)
+                text = nodes.Text(file)
+                
+                ref += text
+                para += ref
+
+    return entry
+
+pegboard_directive.arguments = ()
+pegboard_directive.options = {}
+pegboard_directive.content = 0
+
+#register the directive (not very clean)
+
+docutils.parsers.rst.directives._directives['pegboard'] = pegboard_directive
+
+
 #converts pegboard.rst, reads results into buffer and opens pegboard.html for 
writing
 print 'Generating '+pegroot+'/pegboard.html'
 args = '-stg --stylesheet '+css+' '+pegroot+'/pegboard.rst 
'+pegroot+'/pegboard.html'
 publish_cmdline(writer_name='html', argv=args.split())
 
-pegboard = open (pegroot+'/pegboard.html', 'r')
-pegboard_lines = pegboard.readlines()
-pegboard.close()
-pegboard = open (pegroot+'/pegboard.html', 'w')
-
-for pegboard_line in pegboard_lines:
-    #when replace 'macro' is founded, generate pegtable and replace it
-    if pegboard_line.find(replace) != -1:
-        pegtable.sort(pegcmp)
-
-        replace_str = '<table class=\"pegboard\">\n<tr>\n'
-#        replace_str += '\t<th>Date</th>\n'
-        replace_str += '\t<th>Status</th>\n\t<th>Name</th>\n\t<th>Topic</th>\n'
-        replace_str += 
'\t<th>Authors</th>\n\t<th>Stakeholders</th>\n\t<th>Files</th>\n'
-        replace_str += '</tr>\n'
-        
-        for peg in pegtable:
-            status = peg['status'].split()[0]
-            if peg['status'] != '':
-                replace_str += '<tr class=\"peg-'+status.lower()+'\">\n'
-            else:
-                replace_str += '<tr>\n'
-#            replace_str += '\t<td>' + peg['last-modified'] + '</td>\n'
-            replace_str += '\t<td><small>' + status;
-            if len(status) > 1:
-                replace_str += 
'<br/><em>'+peg['status'][len(status)+1:len(peg['status'])]+'</em>'
-            replace_str += '</small></td>\n'
-            replace_str += '\t<td><a href=\"'+peg['dir']+'/'+peg['html']+'\">' 
\
-                           + peg['dir'].split('--')[0] + '</a></td>\n'
-            if peg['topic'].find(':') > -1:
-                replace_str += '\t<td>' + 
peg['topic'][peg['topic'].find(':')+1:len(peg['topic'])] \
-                               + '</td>\n'
-            else:
-                replace_str += '\t<td>' + peg['topic'] + '</td>\n'
-            replace_str += '\t<td>'
-            for author in peg['authors']:
-                if peg['authors'].index(author) > 0:
-                    replace_str += ','
-                try:
-                    replace_str += '\n\t\t' + authors[author]
-                except KeyError:
-                    replace_str += '\n\t\t' + author
-            replace_str += '\n\t</td>\n'
-            replace_str += '\t<td>'
-            stakeholders = peg['stakeholders']
-            for key, value in authors.items():
-                stakeholders = stakeholders.replace(key, value)
-            replace_str += '\n\t\t' + stakeholders
-            replace_str += '\n\t</td>\n'
-            replace_str += '\t<td>\n'
-            for file in peg['files']:
-                try:
-                    if peg['cvsignore'].index(file):
-                        pass
-                except ValueError:
-                    converted = 0
-                    status = 0
-                    if file != peg['rst']:
-                        for rstfile in peg['rstfiles']:
-                            if rstfile['filename'] == file:
-                                status = rstfile['status']
-                        for htmlfile in peg['cvsignore']:
-                            if htmlfile == file[0:len(file)-4]+'.html':
-                                converted = htmlfile
-                    if converted:
-                        if status:
-                            replace_str += '\t\t<a 
class=\"peg-'+status.split()[0].lower()+ \
-                                       '\" 
'+'href=\"'+peg['dir']+'/'+converted+'\">'+ \
-                                       converted+'</a>'
-                        else:
-                            replace_str += '\t\t<a 
href=\"'+peg['dir']+'/'+converted+'\">'+ \
-                                       converted+'</a>'
-                    else:
-                        replace_str += '\t\t<a 
href=\"'+peg['dir']+'/'+file+'\">' \
-                                       +file+'</a>'
-                    if peg['files'].index(file) < len(peg['files']) -1:
-                        replace_str += '<br/>\n'
-
-            replace_str += '\n\t<td>\n'
-            replace_str += '</tr>\n'
-
-        replace_str += '</table>\n'
-        pegboard_line = pegboard_line.replace(replace, replace_str)
-    pegboard.write(pegboard_line)
-
-pegboard.close()
 
 #generate .cvsignores for generated html-files
 if os.path.isfile(pegroot+'/.cvsignore'):




reply via email to

[Prev in Thread] Current Thread [Next in Thread]