示例#1
0
def checkseclevel(ui, doc, name, initlevel):
    ui.note(('checking "%s"\n') % name)
    if not isinstance(doc, bytes):
        doc = doc.encode('utf-8')
    blocks, pruned = minirst.parse(doc, 0, ['verbose'])
    errorcnt = 0
    curlevel = initlevel
    for block in blocks:
        if block[b'type'] != b'section':
            continue
        mark = block[b'underline']
        title = block[b'lines'][0]
        if (mark not in mark2level) or (mark2level[mark] <= initlevel):
            ui.warn((('invalid section mark %r for "%s" of %s\n') %
                     (mark * 4, title, name)).encode('utf-8'))
            showavailables(ui, initlevel)
            errorcnt += 1
            continue
        nextlevel = mark2level[mark]
        if curlevel < nextlevel and curlevel + 1 != nextlevel:
            ui.warn(('gap of section level at "%s" of %s\n') % (title, name))
            showavailables(ui, initlevel)
            errorcnt += 1
            continue
        ui.note(('appropriate section level for "%s %s"\n') %
                (mark * (nextlevel * 2), title))
        curlevel = nextlevel

    return errorcnt
def checkseclevel(doc, name, initlevel):
    verbose('checking "%s"' % name)
    blocks, pruned = minirst.parse(doc, 0, ['verbose'])
    errorcnt = 0
    curlevel = initlevel
    for block in blocks:
        if block['type'] != 'section':
            continue
        mark = block['underline']
        title = block['lines'][0]
        if (mark not in mark2level) or (mark2level[mark] <= initlevel):
            error('invalid section mark %r for "%s" of %s' %
                  (mark * 4, title, name))
            showavailables(initlevel)
            errorcnt += 1
            continue
        nextlevel = mark2level[mark]
        if curlevel < nextlevel and curlevel + 1 != nextlevel:
            error('gap of section level at "%s" of %s' %
                  (title, name))
            showavailables(initlevel)
            errorcnt += 1
            continue
        verbose('appropriate section level for "%s %s"' %
                (mark * (nextlevel * 2), title))
        curlevel = nextlevel

    return errorcnt
示例#3
0
def checkseclevel(doc, name, initlevel):
    verbose('checking "%s"' % name)
    blocks, pruned = minirst.parse(doc, 0, ['verbose'])
    errorcnt = 0
    curlevel = initlevel
    for block in blocks:
        if block['type'] != 'section':
            continue
        mark = block['underline']
        title = block['lines'][0]
        if (mark not in mark2level) or (mark2level[mark] <= initlevel):
            error('invalid section mark %r for "%s" of %s' %
                  (mark * 4, title, name))
            showavailables(initlevel)
            errorcnt += 1
            continue
        nextlevel = mark2level[mark]
        if curlevel < nextlevel and curlevel + 1 != nextlevel:
            error('gap of section level at "%s" of %s' %
                  (title, name))
            showavailables(initlevel)
            errorcnt += 1
            continue
        verbose('appropriate section level for "%s %s"' %
                (mark * (nextlevel * 2), title))
        curlevel = nextlevel

    return errorcnt
def checkseclevel(ui, doc, name, initlevel):
    ui.note(('checking "%s"\n') % name)
    blocks, pruned = minirst.parse(doc, 0, ["verbose"])
    errorcnt = 0
    curlevel = initlevel
    for block in blocks:
        if block["type"] != "section":
            continue
        mark = block["underline"]
        title = block["lines"][0]
        if (mark not in mark2level) or (mark2level[mark] <= initlevel):
            ui.warn(('invalid section mark %r for "%s" of %s\n') % (mark * 4, title, name))
            showavailables(ui, initlevel)
            errorcnt += 1
            continue
        nextlevel = mark2level[mark]
        if curlevel < nextlevel and curlevel + 1 != nextlevel:
            ui.warn(('gap of section level at "%s" of %s\n') % (title, name))
            showavailables(ui, initlevel)
            errorcnt += 1
            continue
        ui.note(('appropriate section level for "%s %s"\n') % (mark * (nextlevel * 2), title))
        curlevel = nextlevel

    return errorcnt
示例#5
0
def parsenotesfromrevisions(repo, directives, revs):
    notes = parsedreleasenotes()

    for rev in revs:
        ctx = repo[rev]

        blocks, pruned = minirst.parse(ctx.description(),
                                       admonitions=directives)

        for i, block in enumerate(blocks):
            if block['type'] != 'admonition':
                continue

            directive = block['admonitiontitle']
            title = block['lines'][0].strip() if block['lines'] else None

            if i + 1 == len(blocks):
                raise error.Abort(
                    _('changeset %s: release notes directive %s '
                      'lacks content') % (ctx, directive))

            # Now search ahead and find all paragraphs attached to this
            # admonition.
            paragraphs = []
            for j in range(i + 1, len(blocks)):
                pblock = blocks[j]

                # Margin blocks may appear between paragraphs. Ignore them.
                if pblock['type'] == 'margin':
                    continue

                if pblock['type'] == 'admonition':
                    break

                if pblock['type'] != 'paragraph':
                    repo.ui.warn(
                        _('changeset %s: unexpected block in release '
                          'notes directive %s\n') % (ctx, directive))

                if pblock['indent'] > 0:
                    paragraphs.append(pblock['lines'])
                else:
                    break

            # TODO consider using title as paragraph for more concise notes.
            if not paragraphs:
                repo.ui.warn(
                    _("error parsing releasenotes for revision: "
                      "'%s'\n") % node.hex(ctx.node()))
            if title:
                notes.addtitleditem(directive, title, paragraphs)
            else:
                notes.addnontitleditem(directive, paragraphs)

    return notes
示例#6
0
def debugformat(text, form, **kwargs):
    blocks, pruned = minirst.parse(text, **kwargs)
    if form == b'html':
        print("html format:")
        out = minirst.format(text, style=form, **kwargs)
    else:
        print("%d column format:" % form)
        out = minirst.format(text, width=form, **kwargs)

    print("-" * 70)
    print(out[:-1].decode('utf8'))
    if kwargs.get('keep'):
        print("-" * 70)
        print(stringutil.pprint(pruned).decode('utf8'))
    print("-" * 70)
    print()
示例#7
0
def parsereleasenotesfile(sections, text):
    """Parse text content containing generated release notes."""
    notes = parsedreleasenotes()

    blocks = minirst.parse(text)[0]

    def gatherparagraphsbullets(offset, title=False):
        notefragment = []

        for i in range(offset + 1, len(blocks)):
            block = blocks[i]

            if block['type'] == 'margin':
                continue
            elif block['type'] == 'section':
                break
            elif block['type'] == 'bullet':
                if block['indent'] != 0:
                    raise error.Abort(_('indented bullet lists not supported'))
                if title:
                    lines = [l[1:].strip() for l in block['lines']]
                    notefragment.append(lines)
                    continue
                else:
                    lines = [[l[1:].strip() for l in block['lines']]]

                    for block in blocks[i + 1:]:
                        if block['type'] in ('bullet', 'section'):
                            break
                        if block['type'] == 'paragraph':
                            lines.append(block['lines'])
                    notefragment.append(lines)
                    continue
            elif block['type'] != 'paragraph':
                raise error.Abort(_('unexpected block type in release notes: '
                                    '%s') % block['type'])
            if title:
                notefragment.append(block['lines'])

        return notefragment

    currentsection = None
    for i, block in enumerate(blocks):
        if block['type'] != 'section':
            continue

        title = block['lines'][0]

        # TODO the parsing around paragraphs and bullet points needs some
        # work.
        if block['underline'] == '=':  # main section
            name = sections.sectionfromtitle(title)
            if not name:
                raise error.Abort(_('unknown release notes section: %s') %
                                  title)

            currentsection = name
            bullet_points = gatherparagraphsbullets(i)
            if bullet_points:
                for para in bullet_points:
                    notes.addnontitleditem(currentsection, para)

        elif block['underline'] == '-':  # sub-section
            if title == BULLET_SECTION:
                bullet_points = gatherparagraphsbullets(i)
                for para in bullet_points:
                    notes.addnontitleditem(currentsection, para)
            else:
                paragraphs = gatherparagraphsbullets(i, True)
                notes.addtitleditem(currentsection, title, paragraphs)
        else:
            raise error.Abort(_('unsupported section type for %s') % title)

    return notes