4 # Author: Dave Kuhlman <dkuhlman@rexx.com>
5 # Copyright: This module has been placed in the public domain.
8 A front end to the Docutils Publisher, producing OpenOffice documents.
14 locale
.setlocale(locale
.LC_ALL
, '')
18 from docutils
.core
import publish_cmdline
, default_description
, \
19 Publisher
, default_usage
20 from docutils
import io
21 from docutils
.writers
.odtwriter
import Writer
, Reader
24 description
= ('Generates OpenDocument/OpenOffice/ODF documents from '
25 'standalone reStructuredText sources. ' + default_description
)
28 class BinaryFileOutput(io
.FileOutput
):
30 A version of docutils.io.FileOutput which writes to a binary file.
34 self
.destination
= open(self
.destination_path
, 'wb')
35 except IOError, error
:
36 if not self
.handle_io_errors
:
38 print >>sys
.stderr
, '%s: %s' % (error
.__class
__.__name
__,
40 print >>sys
.stderr
, ('Unable to open destination file for writing '
41 '(%r). Exiting.' % self
.destination_path
)
46 def publish_cmdline_to_binary(reader
=None, reader_name
='standalone',
47 parser
=None, parser_name
='restructuredtext',
48 writer
=None, writer_name
='pseudoxml',
49 settings
=None, settings_spec
=None,
50 settings_overrides
=None, config_section
=None,
51 enable_exit_status
=1, argv
=None,
52 usage
=default_usage
, description
=default_description
,
53 destination
=None, destination_class
=BinaryFileOutput
56 Set up & run a `Publisher` for command-line-based file I/O (input and
57 output file paths taken automatically from the command line). Return the
58 encoded string output also.
60 This is just like publish_cmdline, except that it uses
61 io.BinaryFileOutput instead of io.FileOutput.
63 Parameters: see `publish_programmatically` for the remainder.
65 - `argv`: Command-line argument list to use instead of ``sys.argv[1:]``.
66 - `usage`: Usage string, output if there's a problem parsing the command
68 - `description`: Program description, output for the "--help" option
69 (along with command-line option descriptions).
71 pub
= Publisher(reader
, parser
, writer
, settings
=settings
,
72 destination_class
=destination_class
)
73 pub
.set_components(reader_name
, parser_name
, writer_name
)
75 argv
, usage
, description
, settings_spec
, settings_overrides
,
76 config_section
=config_section
, enable_exit_status
=enable_exit_status
)
82 output
= publish_cmdline_to_binary(reader
=reader
, writer
=writer
, description
=description
)