コード例 #1
0
ファイル: text.py プロジェクト: lmregus/Portfolio
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    epilog = __('The text files are in %(outdir)s.')

    out_suffix = '.txt'
    allow_parallel = True
    default_translator_class = TextTranslator

    current_docname = None  # type: str

    def init(self):
        # type: () -> None
        # section numbers for headings in the currently visited document
        self.secnumbers = {}  # type: Dict[str, Tuple[int, ...]]

    def get_outdated_docs(self):
        # type: () -> Iterator[str]
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = path.join(self.outdir, docname + self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except OSError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        # type: (str, str) -> str
        return ''

    def prepare_writing(self, docnames):
        # type: (Set[str]) -> None
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        # type: (str, nodes.Node) -> None
        self.current_docname = docname
        self.secnumbers = self.env.toc_secnumbers.get(docname, {})
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with open(outfilename, 'w', encoding='utf-8') as f:
                f.write(self.writer.output)
        except OSError as err:
            logger.warning(__("error writing file %s: %s"), outfilename, err)

    def finish(self):
        # type: () -> None
        pass
コード例 #2
0
ファイル: text.py プロジェクト: nvmanh/plant
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    out_suffix = '.txt'
    allow_parallel = True
    default_translator_class = TextTranslator

    current_docname = None  # type: unicode

    def init(self):
        # type: () -> None
        pass

    def get_outdated_docs(self):
        # type: () -> Iterator[unicode]
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        # type: (unicode, unicode) -> unicode
        return ''

    def prepare_writing(self, docnames):
        # type: (Set[unicode]) -> None
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        # type: (unicode, nodes.Node) -> None
        self.current_docname = docname
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with codecs.open(outfilename, 'w', 'utf-8') as f:  # type: ignore
                f.write(self.writer.output)
        except (IOError, OSError) as err:
            logger.warning("error writing file %s: %s", outfilename, err)

    def finish(self):
        # type: () -> None
        pass
コード例 #3
0
ファイル: directives.py プロジェクト: k-okada/breathe
    def render(self, nodes, document):

        new_document = document.copy()

        new_document.children = nodes

        writer = TextWriter(TextBuilder(self.app))
        output = writer.write(new_document, FakeDestination())

        return output.split('\n')[0]
コード例 #4
0
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels, "building topics... ", length=len(pydoc_topic_labels)):
         if label not in self.env.domaindata["std"]["labels"]:
             self.warn("label %r not in documentation" % label)
             continue
         docname, labelid, sectname = self.env.domaindata["std"]["labels"][label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document("<section node>")
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding="utf-8")
         writer.write(document, destination)
         self.topics[label] = str(writer.output)
コード例 #5
0
ファイル: pyspecific.py プロジェクト: AkshayJoshi/python
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels, 'building topics... '):
         if label not in self.env.labels:
             self.warn('label %r not in documentation' % label)
             continue
         docname, labelid, sectname = self.env.labels[label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document('<section node>')
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding='utf-8')
         writer.write(document, destination)
         self.topics[label] = writer.output
コード例 #6
0
ファイル: text.py プロジェクト: lehmannro/sphinx-mirror
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    out_suffix = '.txt'
    allow_parallel = True

    def init(self):
        pass

    def get_outdated_docs(self):
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        return ''

    def prepare_writing(self, docnames):
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        self.current_docname = docname
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            f = codecs.open(outfilename, 'w', 'utf-8')
            try:
                f.write(self.writer.output)
            finally:
                f.close()
        except (IOError, OSError) as err:
            self.warn("error writing file %s: %s" % (outfilename, err))

    def finish(self):
        pass
コード例 #7
0
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels,
                                       'building topics... ',
                                       length=len(pydoc_topic_labels)):
         if label not in self.env.domaindata['std']['labels']:
             self.warn('label %r not in documentation' % label)
             continue
         docname, labelid, sectname = self.env.domaindata['std']['labels'][label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document('<section node>')
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding='utf-8')
         writer.write(document, destination)
         self.topics[label] = str(writer.output)
コード例 #8
0
ファイル: text.py プロジェクト: akhildp/newDoc
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    out_suffix = '.txt'
    allow_parallel = True

    def init(self):
        pass

    def get_outdated_docs(self):
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        return ''

    def prepare_writing(self, docnames):
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        self.current_docname = docname
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with codecs.open(outfilename, 'w', 'utf-8') as f:
                f.write(self.writer.output)
        except (IOError, OSError) as err:
            self.warn("error writing file %s: %s" % (outfilename, err))

    def finish(self):
        pass
コード例 #9
0
    def format_description(self, lines: List[str]) -> str:
        """Format tables and fields descriptions from ReST to plain text."""

        # Unwrap lines
        unwrapped_lines = []
        for line in lines:
            empty = not unwrapped_lines or not unwrapped_lines[-1] or not line
            list_item = line and line.startswith('- ')
            block_start = (line and line.startswith('  ') and not empty
                           and not unwrapped_lines[-1].startswith('  '))
            if empty or list_item or block_start:
                unwrapped_lines.append(line)
            else:
                unwrapped_lines[-1] += ' ' + line.lstrip()

        # Manually format and remove useless information
        clean_lines = []
        for line in unwrapped_lines:
            line = line.replace(':class:', '')
            if not line:
                if clean_lines and clean_lines[-1]:
                    clean_lines.append(line)
                continue
            elif re.match('^:[A-Za-z ]*:', line):
                continue
            elif line.startswith('.. versionadded::'):
                continue
            elif line.startswith('See '):
                continue
            clean_lines.append(line)
        source = '\n'.join(clean_lines).strip()

        # Transform ReST into plain text
        writer = TextWriter(self)
        plain_text = publish_string(source=source.encode('utf-8'),
                                    writer=writer).decode('utf-8')
        plain_text = plain_text.replace('\n\n* ',
                                        '\n− ')  # Use hyphens as list bullets

        # Split description and points of interest
        lines = plain_text.split('\n')
        if len(lines) > 2 and lines[1] == '':
            return lines[0].strip(), '\n'.join(lines[2:]).strip()
        else:
            return '\n'.join(lines).strip(), None
コード例 #10
0
 def prepare_writing(self, docnames):
     # type: (Set[unicode]) -> None
     self.writer = TextWriter(self)
コード例 #11
0
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    epilog = __('The text files are in %(outdir)s.')

    out_suffix = '.txt'
    allow_parallel = True
    default_translator_class = TextTranslator

    current_docname = None  # type: unicode

    def init(self):
        # type: () -> None
        # section numbers for headings in the currently visited document
        self.secnumbers = {}  # type: Dict[unicode, Tuple[int, ...]]

    def get_outdated_docs(self):
        # type: () -> Iterator[unicode]
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        # type: (unicode, unicode) -> unicode
        return ''

    def prepare_writing(self, docnames):
        # type: (Set[unicode]) -> None
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        # type: (unicode, nodes.Node) -> None
        self.current_docname = docname
        self.secnumbers = self.env.toc_secnumbers.get(docname, {})
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir,
                                os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with codecs.open(outfilename, 'w', 'utf-8') as f:  # type: ignore
                f.write(self.writer.output)
        except (IOError, OSError) as err:
            logger.warning(__("error writing file %s: %s"), outfilename, err)

    def finish(self):
        # type: () -> None
        pass
コード例 #12
0
ファイル: text.py プロジェクト: czelsa/porownywarka-ofert
 def prepare_writing(self, docnames):
     self.writer = TextWriter(self)
コード例 #13
0
ファイル: text.py プロジェクト: jfbu/sphinx
 def prepare_writing(self, docnames: Set[str]) -> None:
     self.writer = TextWriter(self)
コード例 #14
0
ファイル: text.py プロジェクト: nwf/sphinx
 def prepare_writing(self, docnames):
     # type: (Set[unicode]) -> None
     self.writer = TextWriter(self)
コード例 #15
0
ファイル: rst.py プロジェクト: etarasenko/sphinx-rstbuilder
 def __init__(self, builder):
     TextWriter.__init__(self, builder)
     self.translator_class = self.builder.translator_class or RstTranslator