1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
6
from zope.interface import Interface, Attribute
8
from twisted.lore import process, indexer, numberer, htmlbook
10
from twisted.python import usage, plugin as oldplugin, reflect
11
from twisted import plugin as newplugin
13
class IProcessor(Interface):
20
class Options(usage.Options):
22
optFlags = [["plain", 'p', "Report filenames without progress bar"],
23
["null", 'n', "Do not report filenames"],
24
["number", 'N', "Add chapter/section numbers to section headings"],
28
["input", "i", 'lore'],
29
["inputext", "e", ".xhtml", "The extension that your Lore input files have"],
30
["docsdir", "d", None],
32
["output", "o", 'html'],
33
["index", "x", None, "The base filename you want to give your index file"],
34
["book", "b", None, "The book file to generate a book from"],
35
["prefixurl", None, "", "The prefix to stick on to relative links; only useful when processing directories"],
38
#zsh_altArgDescr = {"foo":"use this description for foo instead"}
39
#zsh_multiUse = ["foo", "bar"]
40
#zsh_mutuallyExclusive = [("foo", "bar"), ("bar", "baz")]
41
#zsh_actions = {"foo":'_files -g "*.foo"', "bar":"(one two three)"}
42
#zsh_actionDescr = {"logfile":"log file name", "random":"random seed"}
43
zsh_extras = ["*:files:_files"]
45
def __init__(self, *args, **kw):
46
usage.Options.__init__(self, *args, **kw)
49
def opt_config(self, s):
51
k, v = s.split('=', 1)
56
def parseArgs(self, *files):
60
def getProcessor(input, output, config):
61
plugins = oldplugin._getPlugIns("lore")
63
if plug.tapname == input:
67
plugins = newplugin.getPlugins(IProcessor)
69
if plug.name == input:
70
module = reflect.namedModule(plug.moduleName)
73
# try treating it as a module name
75
module = reflect.namedModule(input)
77
print '%s: no such input: %s' % (sys.argv[0], input)
80
return process.getProcessor(module, output, config)
81
except process.NoProcessorError, e:
82
print "%s: %s" % (sys.argv[0], e)
85
def getWalker(df, opt):
86
klass = process.Walker
88
klass = process.PlainReportingWalker
90
klass = process.NullReportingWalker
91
return klass(df, opt['inputext'], opt['linkrel'])
94
def runGivenOptions(opt):
95
"""Do everything but parse the options; useful for testing.
96
Returns a descriptive string if there's an error."""
100
book = htmlbook.Book(opt['book'])
102
df = getProcessor(opt['input'], opt['output'], opt.config)
104
return 'getProcessor() failed'
106
walker = getWalker(df, opt)
109
for filename in opt['files']:
110
walker.walked.append(('', filename))
112
for filename in book.getFiles():
113
walker.walked.append(('', filename))
115
walker.walkdir(opt['docsdir'] or '.', opt['prefixurl'])
118
indexFilename = opt['index']
120
indexFilename = book.getIndexFilename()
125
indexer.setIndexFilename("%s.%s" % (indexFilename, opt['output']))
127
indexer.setIndexFilename(None)
129
## TODO: get numberSections from book, if any
130
numberer.setNumberSections(opt['number'])
135
for (file, errors) in walker.failures:
137
print "%s:%s" % (file, error)
138
return 'Walker failures'
145
except usage.UsageError, errortext:
146
print '%s: %s' % (sys.argv[0], errortext)
147
print '%s: Try --help for usage details.' % sys.argv[0]
150
result = runGivenOptions(opt)
156
if __name__ == '__main__':