当前位置: 首页>>代码示例>>Python>>正文


Python frontend.OptionParser类代码示例

本文整理汇总了Python中docutils.frontend.OptionParser的典型用法代码示例。如果您正苦于以下问题:Python OptionParser类的具体用法?Python OptionParser怎么用?Python OptionParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OptionParser类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

    def run(self):
        env = self.state.document.settings.env
        baseurl = env.config.rss_baseurl
        assert baseurl, "rss_baseurl must be defined in your config.py"

        source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)

        rss_doc = utils.new_document(b("<rss>"), self.state.document.settings)
        Parser().parse("\n".join(self.content), rss_doc)

        rst_suffix = env.config.source_suffix
        path = os.path.relpath(source, env.srcdir).replace(rst_suffix, ".html")

        builder = env.app.builder
        docwriter = HTMLWriter(self)
        docsettings = OptionParser(defaults=env.settings, components=(docwriter,)).get_default_values()
        docsettings.compact_lists = bool(env.config.html_compact_lists)

        dest = os.path.join(env.app.outdir, os_path(env.docname) + ".rss")
        pageurl = "%s/%s" % (baseurl, path)
        with open(dest, "w") as rss:
            title = self.options.get("title", "")
            description = self.options.get("description", None)
            rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
            rss.write('<rss version="2.0">\n')
            rss.write("<channel>\n")
            rss.write("<title>%s</title>\n" % cgi.escape(title))
            rss.write("<link>%s</link>\n" % pageurl)
            if description:
                rss.write("<description>%s</description>\n" % cgi.escape(description))

            for child in rss_doc.children:
                if not isinstance(child, nodes.section):
                    continue

                title_index = child.first_child_matching_class(nodes.title)
                if title_index is None:
                    continue

                node = nodes.paragraph()
                node.extend(child.children[title_index + 1 :])

                sec_doc = utils.new_document(b("<rss-section>"), docsettings)
                sec_doc.append(node)
                visitor = RssTranslator(builder, sec_doc)
                sec_doc.walkabout(visitor)

                title = child.children[title_index].astext()
                sectionurl = "%s#%s" % (pageurl, child.get("ids")[0])
                description = "".join(visitor.body)

                rss.write("<item>\n")
                rss.write("<title>%s</title>\n" % cgi.escape(title))
                rss.write("<link>%s</link>\n" % sectionurl)
                rss.write("<description><![CDATA[%s]]></description>\n" % description)
                rss.write("</item>\n")
            rss.write("</channel>\n")
            rss.write("</rss>\n")

        return []
开发者ID:EmuxEvans,项目名称:eclim,代码行数:60,代码来源:rss.py

示例2: setup

def setup():
    global _parser, _settings
    _parser = Parser()
    _settings = OptionParser().get_default_values()
    _settings.tab_width = 8
    _settings.pep_references = False
    _settings.rfc_references = False
    app = FakeSphinx()
    plantuml.setup(app)
开发者ID:SalesSeek,项目名称:d5a41636-09bb-499a-8eba-cdce0fa4c791,代码行数:9,代码来源:test_directive.py

示例3: write

 def write(self, *ignored):
     self.init_document_data()
     for entry in self.document_data:
         docname, targetname, title, author = entry[:4]
         targetname += '.texi'
         direntry = description = category = ''
         if len(entry) > 6:
             direntry, description, category = entry[4:7]
         toctree_only = False
         if len(entry) > 7:
             toctree_only = entry[7]
         destination = FileOutput(
             destination_path=path.join(self.outdir, targetname),
             encoding='utf-8')
         self.info("processing " + targetname + "... ", nonl=1)
         doctree = self.assemble_doctree(docname, toctree_only,
             appendices=(self.config.texinfo_appendices or []))
         self.info("writing... ", nonl=1)
         self.post_process_images(doctree)
         docwriter = TexinfoWriter(self)
         settings = OptionParser(
             defaults=self.env.settings,
             components=(docwriter,)).get_default_values()
         settings.author = author
         settings.title = title
         settings.texinfo_filename = targetname[:-5] + '.info'
         settings.texinfo_elements = self.config.texinfo_elements
         settings.texinfo_dir_entry = direntry or ''
         settings.texinfo_dir_category = category or ''
         settings.texinfo_dir_description = description or ''
         settings.docname = docname
         doctree.settings = settings
         docwriter.write(doctree, destination)
         self.info("done")
开发者ID:aras0,项目名称:porownywarka-ofert,代码行数:34,代码来源:texinfo.py

示例4: main

def main():
    # process cmdline arguments:
    inputFile, outputFile, outputFormat, optargs = getArgs()
    settings = OptionParser(components=(Parser,)).get_default_values()
    settings.debug = optargs['debug']
    parser = Parser()
    input = inputFile.read()
    document = new_document(inputFile.name, settings)
    parser.parse(input, document)
    output = format(outputFormat, input, document, optargs)
    outputFile.write(output)
    if optargs['attributes']:
        import pprint
        pprint.pprint(document.__dict__)
开发者ID:ellbur,项目名称:docutils,代码行数:14,代码来源:quicktest.py

示例5: get_settings

def get_settings():
  settings = OptionParser().get_default_values()
  ## parser settings
  settings.tab_width = 2
  settings.pep_references = None
  settings.rfc_references = None
  ## html settinfgs
  settings.xml_declaration = None
  settings.stylesheet = None
  settings.stylesheet_path = None
  settings.initial_header_level = 1
  settings.math_output = "X"
  settings.template = Writer.default_template_path
  return settings
开发者ID:bossjones,项目名称:etc-python,代码行数:14,代码来源:simple2.py

示例6: __init__

    def __init__(self, document, docstring_linker):
        # Set the document's settings.
        if self.settings is None:
            settings = OptionParser([LaTeXWriter()]).get_default_values()
            settings.output_encoding = 'utf-8'
            self.__class__.settings = settings
        document.settings = self.settings

        LaTeXTranslator.__init__(self, document)
        self._linker = docstring_linker

        # Start at section level 3.  (Unfortunately, we now have to
        # set a private variable to make this work; perhaps the standard
        # latex translator should grow an official way to spell this?)
        self.section_level = 3
        self._section_number = [0]*self.section_level
开发者ID:antlong,项目名称:epydoc,代码行数:16,代码来源:restructuredtext.py

示例7: write

    def write(self, *ignored):
        # type: (Any) -> None
        docwriter = ManualPageWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True).get_default_values()  # type: Any

        logger.info(bold(__('writing... ')), nonl=True)

        for info in self.config.man_pages:
            docname, name, description, authors, section = info
            if docname not in self.env.all_docs:
                logger.warning(__('"man_pages" config value references unknown '
                                  'document %s'), docname)
                continue
            if isinstance(authors, str):
                if authors:
                    authors = [authors]
                else:
                    authors = []

            docsettings.title = name
            docsettings.subtitle = description
            docsettings.authors = authors
            docsettings.section = section

            targetname = '%s.%s' % (name, section)
            logger.info(darkgreen(targetname) + ' { ', nonl=True)
            destination = FileOutput(
                destination_path=path.join(self.outdir, targetname),
                encoding='utf-8')

            tree = self.env.get_doctree(docname)
            docnames = set()  # type: Set[str]
            largetree = inline_all_toctrees(self, docnames, docname, tree,
                                            darkgreen, [docname])
            largetree.settings = docsettings
            logger.info('} ', nonl=True)
            self.env.resolve_references(largetree, docname, self)
            # remove pending_xref nodes
            for pendingnode in largetree.traverse(addnodes.pending_xref):
                pendingnode.replace_self(pendingnode.children)

            docwriter.write(largetree, destination)
        logger.info('')
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:46,代码来源:manpage.py

示例8: write_latex_document

    def write_latex_document(self, latex_document_node,
                             all_latex_document_nodes):
        output_filename = latex_document_node["multilatex-filename"]
        variables       = latex_document_node["multilatex-variables"]
        content         = latex_document_node["multilatex-content"]
        options         = latex_document_node["multilatex-options"]
        docname         = latex_document_node["multilatex-docname"]
        doctree         = latex_document_node["multilatex-doctree"]

        if not output_filename.endswith(".tex"):
            output_filename += ".tex"
        self.info("processing {0}...".format(output_filename), nonl=1)

#        for node in doctree.traverse(latex_document):
#            node.parent.remove(node)
#        parent_node = latex_document_node.parent
#        parent_node.remove(latex_document_node)

        self.post_process_images(doctree)

        self.info("writing...", nonl=1)
        docwriter = LaTeXWriter(self)
        option_parser = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True)

        doctree.settings = option_parser.get_default_values()
        settings = doctree.settings
        settings.contentsname = None
        settings.docname = docname
        for name, value in options.items():
            setattr(settings, name, value)
        settings.multilatex_options = options
        settings.multilatex_variables = variables
        settings.multilatex_content = content
        settings.multilatex_output_filename = output_filename
        settings.multilatex_all_latex_document_nodes = all_latex_document_nodes

        destination = FileOutput(
            destination_path=os.path.join(self.outdir, output_filename),
            encoding="utf-8")

        docwriter.write(doctree, destination)
        self.info("done")
开发者ID:t4ngo,项目名称:sphinxcontrib-multilatex,代码行数:45,代码来源:builder.py

示例9: __init__

    def __init__(self, document, docstring_linker=None, directory=None,
                 docindex=None, context=None):
        # Set the document's settings.
        if self.settings is None:
            settings = OptionParser([LaTeXWriter()]).get_default_values()
            settings.output_encoding = 'utf-8'
            
            # This forces eg \EpydocUserSection rather than
            # \EpydocUserSEction*:
            settings.use_latex_toc = True
            
            self.__class__.settings = settings
        document.settings = self.settings

        LaTeXTranslator.__init__(self, document)
        self._linker = docstring_linker
        self._directory = directory
        self._docindex = docindex
        self._context = context

        # Use custom section names.
        self.d_class = _EpydocDocumentClass()
开发者ID:jlerouge,项目名称:epydoc,代码行数:22,代码来源:restructuredtext.py

示例10: parse_testplan

def parse_testplan(source, parsed, is_spec,check_errors=False):
    register_testplan_directives()
    oldstderr = sys.stderr
    docutils_out = StringIO.StringIO()
#    sys.stderr = docutils_out    
    valid = True
    reader_class=docutils.readers.get_reader_class("standalone")
    reader=reader_class(None,"rst")
    option_parser = OptionParser(
        components=(reader.parser, reader),
        defaults=[], read_config_files=1,
        usage="", description="")
    settings = option_parser.get_default_values()
#    try:
    reader.source = source
    reader.settings = settings
    reader.input = reader.source.read()
    reader.document = doc = reader.new_document()
    doc.parsed = parsed
    doc.check_errors = check_errors
    reader.parser.parse(reader.input, doc)
    doc.current_source = doc.current_line = None
    parsed = doc.parsed
#    except:
#        valid = False
#        parsed = None
    sys.stderr = oldstderr    
    err_msg = docutils_out.getvalue()
    
    if 'feature' in parsed:
        for f in parsed['feature']:
            try:
                f.from_spec
            except:
                f.from_spec = is_spec

    return (valid and err_msg.find("ERROR") == -1), err_msg, parsed
开发者ID:AVB-USER-6667,项目名称:xcommon,代码行数:37,代码来源:testplan.py

示例11: write

    def write(self, *ignored):
        # type: (Any) -> None
        self.init_document_data()
        for entry in self.document_data:
            docname, targetname, title, author = entry[:4]
            targetname += '.texi'
            direntry = description = category = ''
            if len(entry) > 6:
                direntry, description, category = entry[4:7]
            toctree_only = False
            if len(entry) > 7:
                toctree_only = entry[7]
            destination = FileOutput(
                destination_path=path.join(self.outdir, targetname),
                encoding='utf-8')
            with progress_message(__("processing %s") % targetname):
                appendices = self.config.texinfo_appendices or []
                doctree = self.assemble_doctree(docname, toctree_only, appendices=appendices)

            with progress_message(__("writing")):
                self.post_process_images(doctree)
                docwriter = TexinfoWriter(self)
                settings = OptionParser(
                    defaults=self.env.settings,
                    components=(docwriter,),
                    read_config_files=True).get_default_values()  # type: Any
                settings.author = author
                settings.title = title
                settings.texinfo_filename = targetname[:-5] + '.info'
                settings.texinfo_elements = self.config.texinfo_elements
                settings.texinfo_dir_entry = direntry or ''
                settings.texinfo_dir_category = category or ''
                settings.texinfo_dir_description = description or ''
                settings.docname = docname
                doctree.settings = settings
                docwriter.write(doctree, destination)
                self.copy_image_files(targetname[:-5])
开发者ID:lmregus,项目名称:Portfolio,代码行数:37,代码来源:texinfo.py

示例12: write

    def write(self, *ignored):
        # type: (Any) -> None
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True).get_default_values()  # type: Any

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=path.join(self.outdir, targetname),
                                           encoding='utf-8', overwrite_if_changed=True)
            logger.info(__("processing %s..."), targetname, nonl=1)
            toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
            if toctrees:
                if toctrees[0].get('maxdepth') > 0:
                    tocdepth = toctrees[0].get('maxdepth')
                else:
                    tocdepth = None
            else:
                tocdepth = None
            doctree = self.assemble_doctree(
                docname, toctree_only,
                appendices=((docclass != 'howto') and self.config.latex_appendices or []))
            doctree['tocdepth'] = tocdepth
            self.apply_transforms(doctree)
            self.post_process_images(doctree)
            self.update_doc_context(title, author)

            logger.info(__("writing... "), nonl=1)
            docsettings.author = author
            docsettings.title = title
            docsettings.contentsname = self.get_contentsname(docname)
            docsettings.docname = docname
            docsettings.docclass = docclass

            doctree.settings = docsettings
            docwriter.write(doctree, destination)
            logger.info("done")
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:45,代码来源:__init__.py

示例13: run

    def run(self):
        env = self.state.document.settings.env
        baseurl = env.config.rss_baseurl
        assert baseurl, 'rss_baseurl must be defined in your config.py'

        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)

        rss_doc = utils.new_document('<rss>', self.state.document.settings)
        Parser().parse('\n'.join(self.content), rss_doc)

        path = os.path.relpath(source, env.srcdir)

        suffixes = env.config.source_suffix
        # retain backwards compatibility with sphinx < 1.3
        if isinstance(suffixes, basestring):
            suffixes = [suffixes]

        for suffix in suffixes:
            if path.endswith(suffix):
                path = '%s.html' % path[:-len(suffix)]
                break

        builder = env.app.builder
        docwriter = HTMLWriter(self)
        docsettings = OptionParser(
            defaults=env.settings,
            components=(docwriter,)).get_default_values()
        docsettings.compact_lists = bool(env.config.html_compact_lists)

        dest = os.path.join(env.app.outdir, os_path(env.docname) + '.rss')
        pageurl = '%s/%s' % (baseurl, path)
        with open(dest, 'w') as rss:
            title = self.options.get('title', '')
            description = self.options.get('description', None)
            rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
            rss.write('<rss version="2.0">\n')
            rss.write('<channel>\n')
            rss.write('<title>%s</title>\n' % cgi.escape(title))
            rss.write('<link>%s</link>\n' % pageurl)
            if description:
                rss.write('<description>%s</description>\n' % cgi.escape(description))

            for child in rss_doc.children:
                if not isinstance(child, nodes.section):
                    continue

                title_index = child.first_child_matching_class(nodes.title)
                if title_index is None:
                    continue

                node = nodes.paragraph()
                node.extend(child.children[title_index + 1:])

                sec_doc = utils.new_document('<rss-section>', docsettings)
                sec_doc.append(node)
                visitor = RssTranslator(builder, sec_doc)
                sec_doc.walkabout(visitor)

                title = child.children[title_index].astext()
                sectionurl = '%s#%s' % (pageurl, child.get('ids')[0])
                description = ''.join(visitor.body)

                rss.write('<item>\n')
                rss.write('<title>%s</title>\n' % cgi.escape(title))
                rss.write('<link>%s</link>\n' % sectionurl)
                rss.write('<description><![CDATA[%s]]></description>\n' % description)
                rss.write('</item>\n')
            rss.write('</channel>\n')
            rss.write('</rss>\n')

        return []
开发者ID:SobolSigizmund,项目名称:eclim,代码行数:72,代码来源:rss.py

示例14: Writer

__docformat__ = 'reStructuredText'

import sys
from package import parse_package_or_module
import transform
from docutils.writers.html4css1 import Writer
from docutils.frontend import OptionParser

usage = '%prog [options] [<package-directory> | <python-file> [html-file]]'
description = ('Generates .html documentation for the given Python package'
               ' or module.')

writer = Writer()

option_parser = OptionParser(components=[writer],
                             usage=usage,description=description)

settings = option_parser.parse_args(sys.argv[1:])

source_path = settings._source
target_path = settings._destination

nodes = parse_package_or_module(source_path)

# That then needs converting to a docutils tree
document = transform.make_document(nodes,settings)

# And *that* wants converting to the appropriate output format
try:
    target = open(target_path,"w")
    writer.write(document,target)
开发者ID:Distrotech,项目名称:docutils,代码行数:31,代码来源:pysrc2html.py


注:本文中的docutils.frontend.OptionParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。