27 |
|
|
28 |
|
|
29 |
import os, string |
import os, string |
30 |
import docutils |
|
31 |
|
from docutils import Component |
32 |
|
from docutils import frontend, io, readers, parsers, writers, nodes |
33 |
|
from docutils.core import publish_cmdline, Publisher |
34 |
|
from docutils.frontend import OptionParser, ConfigParser |
35 |
|
|
36 |
import config |
import config |
37 |
|
|
38 |
from navidoc.utils.path import * |
from navidoc.utils.path import _slashify |
39 |
|
|
40 |
dbg = config.dbg.shorthand('pegboard') |
dbg = config.dbg.shorthand('pegboard') |
41 |
|
dbg_fail = config.dbg.shorthand('pegboard.fail') |
42 |
|
|
43 |
def pegcmp(a, b): |
def pegcmp(a, b): |
44 |
""" |
""" |
110 |
|
|
111 |
pegtable = [] |
pegtable = [] |
112 |
|
|
113 |
pegdirs = [d for d in os.listdir(_slashify(config.working_directory)) |
pegdirs = [d for d in os.listdir(config.working_directory) |
114 |
if os.path.isdir(_slashify(config.working_directory)+d) and d != 'CVS'] |
if os.path.isdir(_slashify(config.working_directory)+d) and d != 'CVS'] |
115 |
|
|
116 |
|
init_working_directory = config.working_directory |
117 |
|
|
118 |
for pegdir in pegdirs: |
for pegdir in pegdirs: |
119 |
dbg('processing PEG ' + pegdir) |
dbg('processing PEG ' + pegdir) |
120 |
|
config.working_directory = _slashify(init_working_directory)+pegdir |
121 |
|
|
122 |
peg = {'authors': [], 'status': undefined, 'topic': pegdir, 'stakeholders': [], |
peg = {'authors': [], 'status': undefined, 'topic': pegdir, 'stakeholders': [], |
123 |
'last-modified': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': '', |
'last-modified': '', 'dir': pegdir, 'files': '', 'html': '', 'rst': '', |
124 |
'rstfiles': [], 'cvsignore': [] } |
'rstfiles': [], 'cvsignore': [] } |
125 |
|
|
126 |
|
peg['files'] = [f for f in os.list(config.working_directory) \ |
127 |
|
if os.path.isfile(_slashify(config.working_directory)+f) |
128 |
|
and not f.startswith('.') and '#' not in f and '~' not in f] |
129 |
|
|
130 |
pegfiles = [f for f in os.listdir(pegroot+'/'+pegdir+'/') \ |
if peg['files'].find('peg.rst') != -1: peg['rst'] = 'peg.rst' |
131 |
if os.path.isfile(pegroot+'/'+pegdir+'/'+f) and not f.startswith('.') |
else: |
132 |
and '#' not in f and '~' not in f] |
for pegfile in peg['files']: |
133 |
|
if pegfile.endswith('.rst'): |
134 |
peg['files'] = pegfiles |
peg['rst'] = pegfile |
135 |
|
|
136 |
try: |
rstfiles = [f for f in peg['files'] if f.endswith('.rst')] |
137 |
index = pegfiles.index('peg.rst') |
|
138 |
peg['rst'] = pegfiles[index] |
for rstfile in rstfiles: |
139 |
except ValueError: |
pub = Publisher() |
140 |
for pegfile in peg['files']: |
pub.set_reader('standalone', None, 'restructuredtext') |
141 |
if pegfile.endswith('.rst'): |
filename = _slashify(config.working_directory)+rstfile |
142 |
peg['rst'] = pegfile |
pub.process_command_line(argv="--config "+config.docutils+" "+filename+"".split()) |
143 |
|
|
144 |
rstfiles = [f for f in peg['files'] if f.endswith('.rst')] |
#conversion may fail because of bad restructuredtext |
145 |
|
try: |
146 |
for rstfile in rstfiles: |
pub.set_io() |
147 |
#creates and setups a new docutils.core.Publisher, which seems to be |
document = pub.reader.read(pub.source, pub.parser, pub.settings) |
148 |
#easy interface to use docutils |
pub.apply_transforms(document) |
149 |
pub = Publisher() |
peg['cvsignore'].append(rstfile[0:len(rstfile)-4]+'.gen.html') |
150 |
pub.set_reader('standalone', None, 'restructuredtext') |
|
151 |
pub.set_writer('html') |
#conversion have succeeded so far, parsing peg's metadata |
152 |
file = pegroot+'/'+pegdir+'/'+rstfile[0:len(rstfile)-4] |
#from its document tree |
153 |
args = '-stg --stylesheet ../'+css+' %s.rst %s.gen.html' % (file,file) |
if rstfile == peg['rst']: |
154 |
|
peg['html'] = rstfile[0:len(rstfile)-4]+'.gen.html' |
155 |
#saves using contexts for diagrams |
peg['topic'] = getTagValue(document, 'title', always_raw=1) |
156 |
settings['context'] = pegroot+'/'+pegdir+'/'+rstfile |
peg['topic'] = peg['topic'] |
157 |
umltool.set_transition_paths(settings['context']) |
peg['last-modified'] = getFieldTagValue(document, 'last-modified') |
158 |
pub.process_command_line(argv=args.split()) |
#we may have got 'rawsource', which needs some tidying |
159 |
|
if peg['last-modified'].startswith('$Date'): |
160 |
#conversion may fail because of bad restructuredtext |
peg['last-modified'] = peg['last-modified'][7:len(peg['last-modified'])-11].replace('/', '-') |
161 |
try: |
peg['status'] = getTagValue(document, 'status') or undefined |
162 |
pub.set_io() |
stakeholders = getFieldTagValue(document, 'stakeholder') |
163 |
document = pub.reader.read(pub.source, pub.parser, pub.settings) |
if not stakeholders: |
164 |
pub.apply_transforms(document) |
stakeholders = getFieldTagValue(document, 'stakeholders') |
165 |
output = pub.writer.write(document, pub.destination) |
peg['stakeholders'] = [s.strip() for s in stakeholders.split(',')] |
166 |
peg['cvsignore'].append(rstfile[0:len(rstfile)-4]+'.gen.html') |
peg['authors'] = getTagValue(document, 'author', all=1) |
167 |
|
else: |
168 |
#conversion have succeeded so far, parsing peg's metadata |
status = getTagValue(document, 'status') |
169 |
#from its document tree |
if status: |
170 |
if rstfile == peg['rst']: |
peg['rstfiles'].append({'filename': rstfile, 'status': status}) |
|
peg['html'] = rstfile[0:len(rstfile)-4]+'.gen.html' |
|
|
peg['topic'] = getTagValue(document, 'title', always_raw=1) |
|
|
peg['topic'] = peg['topic'] |
|
|
peg['last-modified'] = getFieldTagValue(document, 'last-modified') |
|
|
#we may have got 'rawsource', which needs some tidying |
|
|
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 |
|
|
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') |
|
|
if status: |
|
|
peg['rstfiles'].append({'filename': rstfile, 'status': status}) |
|
171 |
|
|
172 |
except: |
except: |
173 |
fails += 'PEG %s: Docutil raised an exception while converting %s. ' % (pegdir, rstfile) |
dbg_fail('PEG %s: Docutil raised an exception while converting %s. ' % (pegdir, rstfile)) |
174 |
fails += 'Conversion failed and HTML not created.\n' |
dbg_fail('Conversion failed and HTML not created.\n') |
175 |
|
|
176 |
if not peg['html']: |
if not peg['html']: |
177 |
for file in peg['files']: |
for file in peg['files']: |
185 |
#finally adds peg's metadata into pegtable |
#finally adds peg's metadata into pegtable |
186 |
pegtable.append(peg) |
pegtable.append(peg) |
187 |
|
|
|
|
|
188 |
#create the ``.. pegboard::`` directive |
#create the ``.. pegboard::`` directive |
|
|
|
|
|
|
189 |
def pegboard_directive(*args): |
def pegboard_directive(*args): |
190 |
|
|
191 |
pegtable = build_pegtable() |
pegtable = build_pegtable() |