7
# An interface to docutils that does textmacros processing
9
# Homepage : http://www.voidspace.org.uk/python/firedrop2/textamcros.shtml
11
# Copyright Michael Foord, 2004 & 2005.
12
# Released subject to the BSD License
13
# Please see http://www.voidspace.org.uk/python/license.shtml
15
# Adapted for personal needs by Christopher Arndt
16
# - Removed pythonutils dependencies
17
# - Accepts source directory as command line arg
19
# For information about bugfixes, updates and support,
20
# please join the Pythonutils mailing list.
21
# http://groups.google.com/group/pythonutils/
22
# Comments, suggestions and bug reports welcome.
23
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
24
# E-mail fuzzyman@voidspace.org.uk
27
Requires ConfigObj module
28
See http://www.voidspace.org.uk/python/modules.shtml#configobj
35
from StringIO import StringIO
36
from traceback import print_exc
38
from os.path import dirname, join
41
from configobj import ConfigObj
43
from pythonutils.configobj import ConfigObj
45
sys.path.insert(0, join(dirname(__file__), 'lib'))
49
from buildhtml import Builder
51
from walkfiles import walkfiles
56
log_file = 'FuzzyBuilder.log'
62
stand = Tee(logfile = log_file)
66
# source directory specified on command line?
72
# do the reST to html conversion
73
# then macro processing
75
Builder().run(directory=srcdir)
77
# walk through all the files in this directory (and below)
78
for entry in walkfiles(srcdir, '*.html'):
79
print 'Processing "%s" for macros.' % entry
80
body = open(entry).read()
81
newbody = textmacros.replace_all(body, macros.__dict__, 1)
82
print 'Writing "%s".' % entry
83
open(entry, 'w').write(newbody)
84
except KeyboardInterrupt:
85
print 'Exited by Keyboard Interrupt.'
87
# print any error without bombing out
88
# (so we can display it, then close our files nicely)
91
# write error to sys.stderr rather than printing to sys.stdout
92
sys.stderr.write(f.getvalue() + '\n')
98
raw_input('Hit return to continue >>> ')