Beispiel #1
0
                    # convert_section will increment it
                    level -= 1
                convert_context = make_context(document,
                        heading_level=level,
                        skip_toc=True)
                convert(document, doctree, context=convert_context)
            # Fill TOC
            toc.fill()
        else:
            # Just convert the page as is to ODT
            doctree = resource.get_doctree()
            resolve_references(doctree, resource, context)
            resolve_images(doctree, resource, context)
            # convert_section will increment it
            heading_level = 0 if startswith_section(doctree) else 1
            document = rst2odt(doctree, template=template,
                    heading_level=heading_level)

        context.set_content_type('application/vnd.oasis.opendocument.text')
        filename = book.get('filename') if book else None
        if not filename:
            filename = '%s.odt' % resource.name
        context.set_content_disposition('attachment', filename=filename)

        output = StringIO()
        document.save(output)
        return output.getvalue()



class WikiPage_Help(STLView):
    access = 'is_allowed_to_view'
            dest="output", metavar="FILE",
            help="dump the output into the file FILE instead of the standard "
                 "output")

    # --styles
    parser.add_option("-s", "--styles", action="store", type="string",
            dest="styles_from", metavar="FILE",
            help="import the styles from the given file")

    # Parse !
    opts, args = parser.parse_args()

    # Source
    if len(args) != 1:
        parser.print_help()
        exit(1)
    source = args[0]

    template = None
    if opts.styles_from:
        template = odf_get_document(opts.styles_from)

    # Convert
    document = rst2odt(open(source).read(), template=template)

    # Save
    if opts.output is not None:
        document.save(target=opts.output)
    else:
        document.save(target=stdout)