示例#1
0
def makereadme():
    """Generate README.md from info about all cogs"""
    table_data = []
    for folder in sorted(os.listdir(ROOT)):
        if folder.startswith(".") or folder.startswith("_"):
            continue
        _version = ""
        info = None
        for file in glob.glob(f"{ROOT}/{folder}/*"):
            if not file.endswith(".py") and not file.endswith("json"):
                continue
            if file.endswith("info.json"):
                try:
                    with open(file, encoding="utf-8") as infile:
                        data = json.loads(infile.read())
                    info = InfoJson.from_json(data)
                except Exception:
                    log.exception(f"Error reading info.json {file}")
            if _version == "":
                with open(file, encoding="utf-8") as infile:
                    data = infile.read()
                    maybe_version = VER_REG.search(data)
                    if maybe_version:
                        _version = maybe_version.group(1)
        if info and not info.disabled and not info.hidden:
            to_append = [info.name.strip(), _version.strip()]
            description = f"<details><summary>{info.short}</summary>{info.description if info.description != info.short else ''}</details>"
            to_append.append(description.strip())
            to_append.append(babel_list(info.author, style="standard").strip())
            table_data.append(to_append)

    body = tabulate.tabulate(
        table_data,
        headers=[
            "Name", "Status/Version", "Description (Click to see full status)",
            "Authors"
        ],
        # headers=["Name", "Version", "Description (Click to see full info)", "Author(s)"],
        tablefmt="github",
    )
    file_content = HEADER.format(body=body)
    with open(f"{ROOT}/README.md", "r") as outfile:
        remove = string.punctuation + string.whitespace
        mapping = {ord(c): None for c in remove}
        if outfile.read().rstrip().translate(
                mapping) == file_content.rstrip().translate(mapping):
            return 1
    with open(f"{ROOT}/README.md", "w") as outfile:
        outfile.write(file_content)
    return 1
示例#2
0
def makereadme():
    """Generate README.md from info about all cogs"""
    table_data = []
    for folder in os.listdir(ROOT):
        if folder.startswith(".") or folder.startswith("_"):
            continue
        _version = ""
        info = None
        for file in glob.glob(f"{ROOT}/{folder}/*"):
            if not file.endswith(".py") and not file.endswith("json"):
                continue
            if file.endswith("info.json"):
                try:
                    with open(file, encoding="utf-8") as infile:
                        data = json.loads(infile.read())
                    info = InfoJson.from_json(data)
                except Exception:
                    log.exception(f"Error reading info.json {file}")
            if _version == "":
                with open(file, encoding="utf-8") as infile:
                    data = infile.read()
                    maybe_version = VER_REG.search(data)
                    if maybe_version:
                        _version = maybe_version.group(1)
        if info and not (info.disabled or info.hidden):
            to_append = [info.name, _version]
            description = f"<details><summary>{info.short}</summary>{info.description if info.description != info.short else ''}</details>"
            to_append.append(description)
            to_append.append(babel_list(info.author, style="standard"))
            table_data.append(to_append)

    body = tabulate.tabulate(
        table_data,
        headers=[
            "Name", "Status/Version", "Description (Click to see full status)",
            "Authors"
        ],
        tablefmt="github",
    )
    with open(f"{ROOT}/README.md", "w") as outfile:
        outfile.write(HEADER.format(body=body))
    return 1
示例#3
0
def humanize_list(items: Sequence[str],
                  *,
                  locale: Optional[str] = None,
                  style: str = "standard") -> str:
    """Get comma-separated list, with the last element joined with *and*.

    Parameters
    ----------
    items : Sequence[str]
        The items of the list to join together.
    locale : Optional[str]
        The locale to convert, if not specified it defaults to the bot's locale.
    style : str
        The style to format the list with.

        Note: Not all styles are necessarily available in all locales,
        see documentation of `babel.lists.format_list` for more details.

        standard
            A typical 'and' list for arbitrary placeholders.
            eg. "January, February, and March"
        standard-short
             A short version of a 'and' list, suitable for use with short or
             abbreviated placeholder values.
             eg. "Jan., Feb., and Mar."
        or
            A typical 'or' list for arbitrary placeholders.
            eg. "January, February, or March"
        or-short
            A short version of an 'or' list.
            eg. "Jan., Feb., or Mar."
        unit
            A list suitable for wide units.
            eg. "3 feet, 7 inches"
        unit-short
            A list suitable for short units
            eg. "3 ft, 7 in"
        unit-narrow
            A list suitable for narrow units, where space on the screen is very limited.
            eg. "3′ 7″"

    Raises
    ------
    ValueError
        The locale does not support the specified style.

    Examples
    --------
    .. testsetup::

        from redbot.core.utils.chat_formatting import humanize_list

    .. doctest::

        >>> humanize_list(['One', 'Two', 'Three'])
        'One, Two, and Three'
        >>> humanize_list(['One'])
        'One'
        >>> humanize_list(['omena', 'peruna', 'aplari'], style='or', locale='fi')
        'omena, peruna tai aplari'

    """

    return babel_list(items, style=style, locale=get_babel_locale(locale))