2013-03-23 12:43:48 +08:00
|
|
|
#!/usr/bin/env python
|
2013-08-02 23:36:28 +08:00
|
|
|
#
|
|
|
|
# This script walks through all plugin files and
|
2011-06-25 09:47:41 +08:00
|
|
|
# extracts documentation that should go into the
|
|
|
|
# reference manual
|
|
|
|
|
2011-09-03 01:58:35 +08:00
|
|
|
import os, platform, re
|
2011-06-25 09:47:41 +08:00
|
|
|
|
2011-07-08 06:36:02 +08:00
|
|
|
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)
|
2011-07-08 06:36:02 +08:00
|
|
|
if match != None:
|
|
|
|
return int(match.group(1))
|
|
|
|
return 1000
|
|
|
|
|
2012-09-28 00:43:51 +08:00
|
|
|
def extract(target, filename):
|
2011-06-25 09:47:41 +08:00
|
|
|
f = open(filename)
|
|
|
|
inheader = False
|
|
|
|
for line in f.readlines():
|
2011-06-25 22:49:26 +08:00
|
|
|
match = re.match(r'^/\*! ?(.*)$', line)
|
2011-06-25 09:47:41 +08:00
|
|
|
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)
|
2011-06-25 09:47:41 +08:00
|
|
|
if match != None:
|
|
|
|
line = match.group(1).replace('%', '\%')
|
|
|
|
target.write(line + '\n')
|
|
|
|
f.close()
|
|
|
|
|
2012-09-28 00:43:51 +08:00
|
|
|
pyVer = int(platform.python_version_tuple()[0])
|
2011-06-25 09:47:41 +08:00
|
|
|
|
2012-09-28 00:43:51 +08:00
|
|
|
# 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]
|
2011-07-08 06:36:02 +08:00
|
|
|
|
2012-09-28 00:43:51 +08:00
|
|
|
fileList = []
|
2012-11-15 23:17:03 +08:00
|
|
|
for (dirname, subdirs, files) in os.walk(path):
|
|
|
|
capture(fileList, dirname, files)
|
2012-09-28 00:43:51 +08:00
|
|
|
|
|
|
|
ordering = [(findOrderID(fname), fname) for fname in fileList]
|
|
|
|
ordering = sorted(ordering, key = lambda entry: entry[0])
|
|
|
|
|
|
|
|
for entry in ordering:
|
|
|
|
extract(target, entry[1])
|
2011-09-03 01:58:35 +08:00
|
|
|
|
2013-03-23 12:43:48 +08:00
|
|
|
def process_src(target, src_subdir, section=None):
|
|
|
|
if section is None:
|
|
|
|
section = "section_" + src_subdir
|
|
|
|
target.write('\input{{{0}}}\n'.format(section))
|
|
|
|
process('../src/{0}'.format(src_subdir), target)
|
2013-08-02 23:36:28 +08:00
|
|
|
|
2013-03-23 13:31:41 +08:00
|
|
|
def texify(texfile):
|
|
|
|
from subprocess import Popen, PIPE, check_call
|
|
|
|
version = Popen(["pdflatex", "-version"], stdout=PIPE).communicate()[0]
|
|
|
|
# Call decode() to convert from bytes to string, required in Python 3
|
|
|
|
if re.match('.*MiKTeX.*', version.decode()):
|
|
|
|
# MiKTeX's "texify" calls latex/bibtex in tandem automatically
|
|
|
|
print("Running texify on {0}...".format(texfile))
|
|
|
|
check_call(['texify', '-pq', texfile])
|
|
|
|
else:
|
|
|
|
check_call(['pdflatex', texfile])
|
|
|
|
check_call(['bibtex', texfile.replace('.tex', '.aux')])
|
2014-08-01 04:33:00 +08:00
|
|
|
#check_call(['pdflatex', texfile])
|
|
|
|
#check_call(['pdflatex', texfile])
|
2013-03-23 12:43:48 +08:00
|
|
|
|
2013-03-23 13:31:41 +08:00
|
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
2013-03-23 12:43:48 +08:00
|
|
|
with open('plugins_generated.tex', 'w') as f:
|
|
|
|
process_src(f, 'shapes')
|
|
|
|
process_src(f, 'bsdfs', 'section_bsdf')
|
|
|
|
process_src(f, 'textures')
|
|
|
|
process_src(f, 'subsurface')
|
|
|
|
process_src(f, 'medium', 'section_media')
|
|
|
|
process_src(f, 'phase')
|
|
|
|
process_src(f, 'volume', 'section_volumes')
|
|
|
|
process_src(f, 'emitters')
|
|
|
|
process_src(f, 'sensors')
|
|
|
|
process_src(f, 'integrators')
|
|
|
|
process_src(f, 'samplers')
|
|
|
|
process_src(f, 'films')
|
|
|
|
process_src(f, 'rfilters')
|
|
|
|
|
2013-03-23 13:31:41 +08:00
|
|
|
texify('main.tex')
|