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)
#name = sys.argv[0] #if os.sep in name: # name = os.path.basename(name) #script_names = [name] # #assert '2' in name #source_format, target_format = name.split('2') # #reader_name = 'standalone' #if source_format == 'mime': # parser = comp.get_parser_class('rst')(rfc2822=1) #else: # parser = comp.get_parser_class(source_format)() #writer_name = target_format reader_name = 'standalone-mpe' parser = comp.get_parser_class('rst')() writer_name = 'rst'#pprint' print 'Reader:', reader_name, print 'Parser:', parser, print 'Writer:', writer_name frontend.cli_du_publisher( reader_name=reader_name, parser=parser, writer_name=writer_name)
# print debug info if '--debug-du-fe' in sys.argv: sys.argv.remove('--debug-du-fe') print >>sys.stderr, """source_format: %s target_format: %s, tag: %s, action: %s""" % (source_format, target_format, tag, action) print >>sys.stderr, """reader_name: %s, parser_name: %s, writer_name: %s, builder_module: %s""" % (reader_name, parser_name, writer_name, module_name) if source_format == 'mime': parser = comp.get_parser_class('rst')(rfc2822=1) else: parser = comp.get_parser_class(parser_name)() # Main log = util.get_log(None, fout=False, stdout=True) if action == 'proc': log.info("Starting Du processor: "+tag) assert target_format == 'pseudoxml' # TODO: use source_format #frontend.cli_process( # sys.argv[1:], builder_name=module_name) frontend.cli_process(sys.argv[1:], None, 'dotmpe.du.builder.'+tag) #frontend.cli_process(
def test_2_get_parser_class(self): for Parser, names in DuComponentLoaderMonkeyPatchTest.parser: for name in names: self.assert_( issubclass(Parser, docutils.parsers.Parser), Parser ) self.assertEquals( Parser, comp.get_parser_class(name) )
def prepare_source(self, source, source_path=None): """ This (re)sets self.source_class using some argument inspection. Source should be either a string or a docutils document instance, when source_path=None, the string is tested as filename too. The keyword source_path can set a path location explicitly to prepare for file input. The source may be None or loaded already no matter in this case. Setting it to a string or False bypasses the filesystem check. source_path may be always provided to provide the global ID of the source. """ reader, parser = None, None if isinstance(source, docutils.nodes.document): assert source_path, "Need an ID, not %r" % source_path logger.info("ReReading %s", source_path) # Reread document self.source_class = docutils.io.DocTreeInput parser = comp.get_parser_class('null')() reader = self.ReReader(self.parser) if source.parse_messages: map(lambda x:logger.info(x.astext()), source.parse_messages) if source.transform_messages: map(lambda x:logger.info(x.astext()), source.transform_messages) self.settings = source.settings elif source_path: if isinstance(source_path, basestring) and os.path.exists(source_path): self.source_path = source_path self.source_class = docutils.io.FileInput self.source_id = source_path elif source and os.path.exists(source): self.source_class = docutils.io.FileInput self.source = None self.source_id = source elif source: if isinstance(source, str): source = unicode(source) assert isinstance(source, unicode), type(source) self.source = source self.source_class = docutils.io.StringInput else: assert source, "Need source to build" if not parser: parser = self.Parser() self.parser = parser if not reader: reader = self.Reader(parser=self.parser) self.reader = reader return self.source_class, self.parser, self.reader, self.settings