/usr/share/pyshared/pydoctor/templatewriter/writer.py is in python-pydoctor 0.5b1+bzr603-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | """Badly named module that contains the driving code for the rendering."""
from pydoctor.templatewriter.util import link, templatefile
from pydoctor.templatewriter import DOCTYPE, pages, summary
from pydoctor import model
from twisted.web.template import flattenString
import os, shutil
def flattenToFile(fobj, page):
fobj.write(DOCTYPE)
err = []
def e(r):
err.append(r.value)
flattenString(None, page).addCallback(fobj.write).addErrback(e)
if err:
raise err[0]
class TemplateWriter:
def __init__(self, filebase):
self.base = filebase
self.written_pages = 0
self.total_pages = 0
self.dry_run = False
def prepOutputDirectory(self):
if not os.path.exists(self.base):
os.mkdir(self.base)
shutil.copyfile(templatefile('apidocs.css'),
os.path.join(self.base, 'apidocs.css'))
if self.system.options.htmlusesorttable:
shutil.copyfile(templatefile('sorttable.js'),
os.path.join(self.base, 'sorttable.js'))
if self.system.options.htmlusesplitlinks or self.system.options.htmlshortenlists:
shutil.copyfile(templatefile('pydoctor.js'),
os.path.join(self.base, 'pydoctor.js'))
def writeIndividualFiles(self, obs, functionpages=False):
self.dry_run = True
for ob in obs:
self.writeDocsFor(ob, functionpages=functionpages)
self.dry_run = False
for ob in obs:
self.writeDocsFor(ob, functionpages=functionpages)
def writeModuleIndex(self, system):
import time
for i, pclass in enumerate(summary.summarypages):
system.msg('html', 'starting ' + pclass.__name__ + ' ...', nonl=True)
T = time.time()
page = pclass(system)
f = open(os.path.join(self.base, pclass.filename), 'w')
flattenToFile(f, page)
f.close()
system.msg('html', "took %fs"%(time.time() - T), wantsnl=False)
def writeDocsFor(self, ob, functionpages):
if not ob.isVisible:
return
isfunc = ob.documentation_location == model.DocLocation.PARENT_PAGE
if (isfunc and functionpages) or not isfunc:
if self.dry_run:
self.total_pages += 1
else:
f = open(os.path.join(self.base, link(ob)), 'w')
self.writeDocsForOne(ob, f)
f.close()
for o in ob.orderedcontents:
self.writeDocsFor(o, functionpages)
def writeDocsForOne(self, ob, fobj):
if not ob.isVisible:
return
# brrrrrrrr!
d = pages.__dict__
for c in ob.__class__.__mro__:
n = c.__name__ + 'Page'
if n in d:
pclass = d[n]
break
else:
pclass = pages.CommonPage
self.system.msg('html', str(ob), thresh=1)
page = pclass(ob)
self.written_pages += 1
self.system.progress('html', self.written_pages, self.total_pages, 'pages written')
flattenToFile(fobj, page)
|