mitsuba/doc/gendoc.py

95 lines
2.7 KiB
Python
Raw Normal View History

#! /usr/bin/python
#
# This script walks through all plugin files and
# extracts documentation that should go into the
# reference manual
import os, platform, re
def findOrderID(filename):
f = open(filename)
for line in f.readlines():
2011-08-22 12:17:55 +08:00
match = re.match(r'.*\\order{([^}]*)}.*', line)
if match != None:
return int(match.group(1))
return 1000
def extract(target, filename):
f = open(filename)
inheader = False
for line in f.readlines():
2011-06-25 22:49:26 +08:00
match = re.match(r'^/\*! ?(.*)$', line)
if match != None:
print("Processing %s" % filename)
line = match.group(1).replace('%', '\%')
target.write(line + '\n')
inheader = True
continue
if not inheader:
continue
if re.search(r'^[\s\*]*\*/$', line):
inheader = False
continue
2011-06-25 22:49:26 +08:00
match = re.match(r'^\s*\** ?(.*)$', line)
if match != None:
line = match.group(1).replace('%', '\%')
target.write(line + '\n')
f.close()
pyVer = int(platform.python_version_tuple()[0])
# Traverse source directories and process any found plugin code
def process(path, target):
def capture(fileList, dirname, files):
suffix = os.path.split(dirname)[1]
if 'lib' in suffix or suffix == 'tests' \
or suffix == 'mitsuba' or suffix == 'utils' \
or suffix == 'converter' or suffix == 'mtsgui':
return
for filename in files:
if '.cpp' == os.path.splitext(filename)[1]:
fname = os.path.join(dirname, filename)
fileList += [fname]
fileList = []
for (dirname, subdirs, files) in os.walk(path):
capture(fileList, dirname, files)
ordering = [(findOrderID(fname), fname) for fname in fileList]
ordering = sorted(ordering, key = lambda entry: entry[0])
for entry in ordering:
extract(target, entry[1])
os.chdir(os.path.dirname(__file__))
f = open('plugins_generated.tex', 'w')
2011-08-23 07:41:28 +08:00
f.write('\input{section_shapes}\n')
process('../src/shapes', f)
2011-06-25 22:49:26 +08:00
f.write('\input{section_bsdf}\n')
process('../src/bsdfs', f)
f.write('\input{section_textures}\n')
process('../src/textures', f)
2011-07-17 21:20:55 +08:00
f.write('\input{section_subsurface}\n')
process('../src/subsurface', f)
2011-07-17 21:20:55 +08:00
f.write('\input{section_media}\n')
process('../src/medium', f)
f.write('\input{section_phase}\n')
process('../src/phase', f)
2011-08-27 12:16:09 +08:00
f.write('\input{section_volumes}\n')
process('../src/volume', f)
f.write('\input{section_emitters}\n')
process('../src/emitters', f)
f.write('\input{section_sensors}\n')
process('../src/sensors', f)
2011-07-02 23:03:57 +08:00
f.write('\input{section_integrators}\n')
process('../src/integrators', f)
f.write('\input{section_samplers}\n')
process('../src/samplers', f)
2011-08-26 12:33:53 +08:00
f.write('\input{section_films}\n')
process('../src/films', f)
f.write('\input{section_rfilters}\n')
f.close()
os.system('bibtex main.aux')
os.system('pdflatex main.tex')
#os.system('pdflatex main.tex | grep -i warning | grep -v "Package \(typearea\|hyperref\)"')