3
3
# Author: David Goodger
4
4
# Contact: goodger@users.sourceforge.net
5
# Revision: $Revision: 1.23 $
6
# Date: $Date: 2004/03/28 15:39:27 $
5
# Revision: $Revision: 2504 $
6
# Date: $Date: 2004-07-29 06:36:53 +0200 (Thu, 29 Jul 2004) $
7
7
# Copyright: This module has been placed in the public domain.
10
10
Generates .html from all the .txt files in a directory.
12
12
Ordinary .txt files are understood to be standalone reStructuredText.
13
Files named ``pep-*.txt`` are interpreted as PEPs (either old-style or
14
new reStructuredText PEPs).
13
Files named ``pep-*.txt`` are interpreted as reStructuredText PEPs.
16
15
# Once PySource is here, build .html from .py as well.
39
38
usage = '%prog [options] [<directory> ...]'
40
description = ('Generates .html from all the .txt files (including PEPs) '
41
'in each <directory> (default is the current directory).')
39
description = ('Generates .html from all the reStructuredText .txt files '
40
'(including PEPs) in each <directory> '
41
'(default is the current directory).')
44
44
class SettingsSpec(docutils.SettingsSpec):
108
108
'': Struct(components=(pep.Reader, rst.Parser, pep_html.Writer,
110
110
'.txt': Struct(components=(rst.Parser, standalone.Reader,
111
html4css1.Writer, SettingsSpec)),
111
html4css1.Writer, SettingsSpec),
112
reader_name='standalone',
112
114
'PEPs': Struct(components=(rst.Parser, pep.Reader,
113
pep_html.Writer, SettingsSpec))}
115
pep_html.Writer, SettingsSpec),
117
writer_name='pep_html')}
114
118
"""Publisher-specific settings. Key '' is for the front-end script
115
119
itself. ``self.publishers[''].components`` must contain a superset of
116
120
all components used by individual publishers."""
130
134
for name, publisher in self.publishers.items():
131
135
option_parser = OptionParser(
132
components=publisher.components,
136
components=publisher.components, read_config_files=1,
133
137
usage=usage, description=description)
134
138
publisher.option_parser = option_parser
135
139
publisher.setting_defaults = option_parser.get_default_values()
136
140
frontend.make_paths_absolute(publisher.setting_defaults.__dict__,
137
141
option_parser.relative_path_settings)
138
self.config_settings = option_parser.get_standard_config_settings()
142
publisher.config_settings = (
143
option_parser.get_standard_config_settings())
139
144
self.settings_spec = self.publishers[''].option_parser.parse_args(
140
145
values=frontend.Values()) # no defaults; just the cmdline opts
141
146
self.initial_settings = self.get_settings('')
151
156
publisher = self.publishers[publisher_name]
152
157
settings = frontend.Values(publisher.setting_defaults.__dict__)
153
settings.update(self.config_settings, publisher.option_parser)
158
settings.update(publisher.config_settings, publisher.option_parser)
155
160
local_config = publisher.option_parser.get_config_file_settings(
156
161
os.path.join(directory, 'docutils.conf'))
182
187
if not self.initial_settings.silent:
183
188
print >>sys.stderr, '/// Processing directory:', directory
184
189
sys.stderr.flush()
187
191
for name in names:
188
192
if name.endswith('.txt'):
189
if name.startswith('pep-'):
192
prune = self.process_txt(directory, name)
195
if peps_found and not prune:
196
self.process_peps(directory)
193
prune = self.process_txt(directory, name)
200
199
def process_txt(self, directory, name):
201
settings = self.get_settings('.txt', directory)
200
if name.startswith('pep-'):
204
settings = self.get_settings(publisher, directory)
205
pub_struct = self.publishers[publisher]
202
206
if settings.prune and (directory in settings.prune):
204
208
settings._source = os.path.normpath(os.path.join(directory, name))
205
209
settings._destination = settings._source[:-4]+'.html'
206
210
if not self.initial_settings.silent:
207
print >>sys.stderr, ' ::: Processing .txt:', name
211
print >>sys.stderr, ' ::: Processing:', name
208
212
sys.stderr.flush()
210
214
core.publish_file(source_path=settings._source,
211
215
destination_path=settings._destination,
212
reader_name='standalone',
216
reader_name=pub_struct.reader_name,
213
217
parser_name='restructuredtext',
218
writer_name=pub_struct.writer_name,
215
219
settings=settings)
216
220
except ApplicationError, error:
217
221
print >>sys.stderr, (' Error (%s): %s'
218
222
% (error.__class__.__name__, error))
220
def process_peps(self, directory):
221
# only import PEP module/script if we need it.
224
settings = self.get_settings('PEPs', directory)
225
if settings.prune and (directory in settings.prune):
227
old_directory = os.getcwd()
229
if self.initial_settings.silent:
232
print >>sys.stderr, ' ::: Processing PEPs:'
235
pep2html.docutils_settings = settings
238
except Exception, error:
239
print >>sys.stderr, (' Error (%s): %s'
240
% (error.__class__.__name__, error))
241
os.chdir(old_directory)
244
225
if __name__ == "__main__":