|
From: Aahz <aa...@py...> - 2002-10-12 02:24:02
|
On Fri, Oct 11, 2002, David Goodger wrote:
> Aahz wrote:
>>
>> pub = core.Publisher()
>> options = pub.set_options()
>> pub.source = io.FileInput(options, source_path=sys.argv[1])
>> pub.destination = io.StringOutput(options)
>> pub.set_reader('standalone', None, 'restructuredtext')
>> pub.writer = OOwriter.Writer
>
> Is "OOwriter.Writer" a class or an object? "pub.writer" needs to be
> an object.
That I figured out on my own. Here's what works::
pub = core.Publisher(writer=OOwriter.Writer())
pub.set_reader('standalone', None, 'restructuredtext')
options = pub.set_options()
pub.source = io.FileInput(options, source_path=sys.argv[1])
pub.destination = io.StringOutput(options)
content = pub.publish()
> Sorry, I forgot that you need to set up the reader & writer *before*
> calling pub.set_options(). The reader, parser, and writer
> (collectively, the "components") specify the available options along
> with their default values.
Well, success at last! I have now produced an OpenOffice.org document
completely programmatically. It's rough and ugly, but it will be enough
to make my publishers happy that I haven't completely screwed up.
I have to say that this is a Bad Design for Publisher. "Ordinary setup"
shouldn't requre specific ordering; at the very least, there ought to be
error checking higher up in the call chain.
If people want to see my code, I'm willing to stick it in a sandbox, but
I really, really don't want comments about how ugly it is. Constructive
criticism that takes less than fifteen minutes to implement is welcome,
though.
--
Aahz (aa...@py...) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/
|