Пример #1
0
def cli_du_publisher(reader_name='mpe', parser=None, parser_name='rst',
        writer=None, writer_name='pseudoxml', description=''):

    """
    Simple wrapper for ``docutils.core.publish_cmdline``.
    During development, this should still be working.

    Shortcomings are it cannot load settings-specs from transforms,
    or perform processing only (without rendering).
    It does not handle stores for transforms directly as Nabu does.
    But, given that transforms could handle storage
    initialization themselves, and that the Reader/Parser/Writer 'parent'
    component can hold the settings-specs, should make it fairly easy to port
    Builder code back to work with docutils.
    """

    # XXX: how far does inline customization go? parser = Parser(inliner=Inliner())
    reader_class = comp.get_reader_class(reader_name)
    parser_class = None
    if not parser:
        parser_class = comp.get_parser_class(parser_name)
        parser = parser_class()
    if not writer:
        writer_class = comp.get_writer_class(writer_name)
        writer = writer_class()

    publish_cmdline(
            parser=parser,
            parser_name=parser_name,
            reader=reader_class(parser),
            reader_name=reader_name,
            writer=writer,
            writer_name=writer_name,
            description=description)
Пример #2
0
    def render(self, source, source_id='<render>', writer_name=None,
            overrides={}, parts=['whole']):
        """
        Invoke writer by name and return parts after publishing.
        """
        writer_name = writer_name or self.default_writer
        assert writer_name
        self.writer = comp.get_writer_class(writer_name)()
        logger.info('Rendering %r as %r with parts %r.', source_id, writer_name, parts)
        assert not overrides
        #logger.info("source-length: %i", not source or len(source))
        document = self.build(source, source_id)
        #logging.info(overrides)
        #parts = ['html_title', 'script', 'stylesheet']
        #logger.info("output-length: %i", not output or len(output))
        #logger.info([(part, self.writer.parts.get(part)) for part in parts])
        logger.info("Deps for %s: %s", source_id, self.document.settings.record_dependencies)
        output = self.writer.write(document, self.destination)
        return output

        print output
        assert self.writer.parts
        # XXX: right to the internal of the writer. Is this interface?
        assert parts
        results = [ p for p in [
            self.writer.parts.get(part) for part in parts ] if p ]
        if results:
            return ''.join(results)
Пример #3
0
 def prepare_initial_components(self):
     #self.set_components(reader_name, parser_name, writer_name)
     self.parser = self.Parser()
     self.reader = self.Reader(parser=self.parser)
     # XXX render initializes again, but we want to see the help too...
     self.writer = comp.get_writer_class(self.default_writer)()
     # FIXME: having initial writer component enables publisher src2trgt frontends
     self.components = (self.parser, self.reader, self.writer, self)
Пример #4
0
def get_publish_spec(conf):
    assert not isinstance(conf, BuilderConfiguration)
    builder = get_builder(conf.parent().builder)
    specs = (
            builder,
            builder.ReReader,
            get_writer_class(conf.writer),
        )
    return specs
Пример #5
0
#!/usr/bin/env python
import os
import sys

try:
    import locale
    locale.setlocale(locale.LC_ALL, '')
    locale.setlocale(locale.LC_CTYPE, '')
except:
    pass

from dotmpe.du import frontend, comp


reader_name = 'standalone-mpe'
parser = comp.get_parser_class('rst')()
writer = comp.get_writer_class('outline')()

frontend.cli_du_publisher(
        reader_name=reader_name,
        parser=parser,
        writer=writer)

Пример #6
0
 def test_3_get_writer_class(self):
     for Writer, names in DuComponentLoaderMonkeyPatchTest.writer:
         for name in names:
         	self.assert_( issubclass(Writer, docutils.writers.Writer),
         	        Writer )
             self.assertEquals( Writer, comp.get_writer_class(name) )
Пример #7
0
#!/usr/bin/python
"""
A minimal front end to the Docutils Publisher, producing Docutils XML.
This uses the (experimental?) Python source reader. 
TODO: there is no HTML writer compatible with it afaik

Copyleft 2009  Berend van Berkum <*****@*****.**>
This file has been placed in the Public Domain.
"""

import sys, os
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__),
    '..', 'lib')))
import dotmpe.du.ext
from dotmpe.du import comp
from dotmpe.du.ext.reader import mpe

try:
    import locale
    locale.setlocale(locale.LC_ALL, '')
except:
    pass

from docutils.core import publish_cmdline, default_description

publish_cmdline(
        reader=comp.get_reader_class('python')(), 
        writer=comp.get_writer_class('dotmpe-html')())


Пример #8
0
    def build(self, source, source_id='<build>', overrides={}, cli=False):
        """
        Build document from source, returns the document.
        This is used before a process or render.

        TODO: Use Reader, Parser, Transform and Builder for option spec.
        """
        logger.debug("Building %r.", source_id)
        source_class, parser, reader, settings = self.prepare_source(source, source_id)
        if not self.writer:
            self.writer = comp.get_writer_class('null')()
        self.components = (self.parser, self.reader, self.writer, self)
        # FIXME: get defaults for components
        if not self.settings:\
            self.settings = frontend.Values({})
        if cli:
            self.process_command_line() # replace settings for initial components
        else:
            self.build_doc()
        assert self.settings or isinstance(self.settings, frontend.Values), self.settings
        self.destination_class = docutils.io.StringOutput
        assert self.reader and self.parser and self.writer
        assert self.source or os.path.exists(self.source_id)
        if 'halt_level' not in self.settings_default_overrides:
            self.settings.halt_level = 0
        if 'report_level' not in self.settings_default_overrides:
            self.settings.report_level = 6

        # FIXME: check settingspec defaults
        #if 'warning_stream' not in self.settings_default_overrides:
        if not hasattr(self.settings, 'warning_stream'):
            self.settings.warning_stream = StringIO.StringIO()
        if not hasattr(self.settings, 'debug'):
            self.settings.debug = False
        for key in "input_encoding output_encoding error_encoding".split(' '):
            if not hasattr(self.settings, key):
                setattr(self.settings, key, 'utf-8')
        if not hasattr(self.settings, 'error_encoding_error_handler'):
            setattr(self.settings, 'error_encoding_error_handler', 'replace')

        self.settings.output_encoding_error_handler = 'backslashreplace'
        self.settings.tab_width = 4
        self.settings.language_code = 'en_US'
        self.settings.pep_references = False
        self.settings.rfc_references = False
        self.settings.smart_quotes = ''
        self.settings.id_prefix = ''

        # XXX
        #from dotmpe.du.frontend import get_option_parser
        #option_parser = get_option_parser(
        #        self.components, usage='Builder testing: build [options] ..',
        #        settings_spec=None, read_config_files = 0)
        #self.settings = option_parser.get_default_values()
        source = self.source_class(
            source=self.source, source_path=self.source_id)
        if not hasattr(self.settings, '_destination'):
            self.settings._destination = None
        self.set_destination()
        # FIXME:  encoding=self.settings.input_encoding)
        self.document = self.reader.read(source, self.parser, self.settings)
        self.document.transformer.populate_from_components(
            (source, self.reader, self.parser, self.writer, self.destination))
        self.document.transformer.apply_transforms()
        return self.document