Exemple #1
0
def to_table(rooms_list: list[JsonDict]) -> Generator[str, None, None]:
    """Use this function as helper to pint the room table.

    Parameters
    ----------
    rooms_list : list of matrixctl.typehints.JsonDict
        A list of rooms from the API.

    Yields
    ------
    table_lines : str
        The table lines.

    """

    room_list: list[tuple[str, str, str, str]] = []

    for room in rooms_list:
        name = room["name"]
        members: str = str(room["joined_members"])
        alias: str = room["canonical_alias"]
        room_id: str = room["room_id"]

        room_list.append((
            name,
            members,
            alias,
            room_id,
        ))
    return table(room_list, ("Name", "Members", "Alias", "Room ID"), False)
Exemple #2
0
def to_table(user_dict: JsonDict,
             len_domain: int) -> Generator[str, None, None]:
    """Use this function as helper to pint the room table.

    Parameters
    ----------
    user_dict : matrixctl.typehints.JsonDict
        The user data from the API
    len_domain : int
        The length of the homeservers domain.

    Yields
    ------
    table_lines : str
        The table lines.

    """
    user_tables = generate_user_tables(user_dict, len_domain)

    logger.debug(f"User: {user_tables=}")

    for num, table_ in enumerate(user_tables):

        if num < 1:
            yield "User:"******"\nThreepid:"
        for line in table(table_, sep=False):
            yield line
Exemple #3
0
def print_tasks() -> None:  # static data
    """Print a list of all available tasks."""
    table_generator: Generator[str, None, None] = table(
        [
            ["vacuum", "Reclaims storage occupied by dead tuples."],
            ["compress-state", "Compress Synapse State Tables."],
        ],
        ["Task", "Description"],
        False,
    )
    for line in table_generator:
        print(line)
Exemple #4
0
def to_table(events_raw: list[JsonDict]) -> Generator[str, None, None]:
    """Use this function as helper to pint the events as table.

    Examples
    --------
    .. code-block:: console

       $ matrixctl reports
       +-----------------+----------------------------------------------+
       | ID              | 2                                            |
       | Date            | 2021-05-08                                   |
       | Time            | 21:04:55                                     |
       | Score           | -100                                         |
       | Canonical Alias | -                                            |
       | Room Name       | SomeRoom                                     |
       | Room ID         | !AbCdEfGhIjKlMnOpQr:domain.tld               |
       | Event ID        | $Q_sksd348jaidj93jf9ojwef9h329ofijewhf932h9f |
       | Defendant       | @mallory:matrix.org                          |
       | Plaintiff       | @alice:myhomeverver.tld                      |
       | Reason          | Likes JavaScript                             |
       |-----------------+----------------------------------------------|
       | ID              | 1                                            |
       | Date            | 2020-08-15                                   |
       | Time            | 09:09:57                                     |
       | Score           | -100                                         |
       | Canonical Alias | -                                            |
       | Room Name       | -                                            |
       | Room ID         | !AbCdEfGhIjKlMnOpQr:matrix.org               |
       | Event ID        | $123456789012345678901:matrix.org            |
       | Defendant       | @eve:matrix.org                              |
       | Plaintiff       | @bob:myhomeserver.tld                        |
       | Reason          | Hates The Office (US)                        |
       +-----------------+----------------------------------------------+

    Parameters
    ----------
    events_raw : list of matrixctl.typehints.JsonDict
        A list of events from the API.

    Yields
    ------
    table_lines : str
        The table lines.

    """
    events: list[tuple[str, str]] = []

    logger.debug(f"Terminal width = {get_terminal_size().columns}")

    wrapper_reason = TextWrapper(
        width=get_terminal_size().columns - 20,  # is const.
        drop_whitespace=True,
        break_long_words=True,
    )

    for event in events_raw:
        dt: str = timestamp_to_dt(event["received_ts"], "\n")
        canonical_alias: str = (
            event["canonical_alias"]
            if event["canonical_alias"] is not None
            else "-"
        )

        events.append(
            (
                "\n".join(
                    (
                        "ID",
                        "Date",
                        "Time",
                        "Score",
                        "Canonical Alias",
                        "Room Name",
                        "Room ID",
                        "Event ID",
                        "Defendant",
                        "Plaintiff",
                        "Reason",
                    )
                ),
                (
                    f"{event['id']}\n"
                    f"{dt}\n"
                    f"{event['score']}\n"
                    f"{canonical_alias}\n"
                    f"{event['name'] if event['name'] else '-'}\n"
                    f"{event['room_id']}\n"
                    f"{event['event_id']}\n"
                    f"{event['sender']}\n"
                    f"{event['user_id']}\n"
                    f"{wrapper_reason.fill(text=event['reason'])}"
                ),
            )
        )
    return table(events)
Exemple #5
0
def to_table(
    users_list: list[JsonDict], len_domain: int
) -> Generator[str, None, None]:
    """Use this function as helper to pint the users table.

    Examples
    --------
    .. code-block:: console

       $ matrixctl users
       +---------+-------------+---------------+-------+-------+--------------+
       | Name    | Deactivated | Shadow-Banned | Admin | Guest | Display Name |
       |---------+-------------+---------------+-------+-------|--------------+
       | dwight  | No          | No            | Yes   | No    | Dwight       |
       | pam     | No          | No            | No    | No    | Pam          |
       | jim     | No          | No            | No    | No    | Jim          |
       | creed   | No          | Yes           | No    | No    | Creed        |
       | stanley | No          | No            | No    | No    | Stanley      |
       | kevin   | No          | No            | No    | No    | Cookie       |
       | angela  | No          | No            | No    | No    | Angela       |
       | phyllis | No          | No            | No    | No    | Phyllis      |
       | tobi    | No          | No            | No    | No    | TobiHR       |
       | michael | No          | No            | Yes   | No    | Best Boss    |
       | andy    | No          | No            | No    | No    | Andy         |
       +---------+-------------+---------------+-------+-------+--------------+

    Parameters
    ----------
    users_list : list of matrixctl.typehints.JsonDict
        A list of rooms from the API.
    len_domain : int
        The length of the homeservers domain.

    Yields
    ------
    table_lines : str
        The table lines.

    """

    user_list: list[tuple[str, str, str, str, str, str]] = []

    for user in users_list:
        name = user["name"][1:-len_domain]
        deactivated: str = human_readable_bool(user["deactivated"])
        shadow_banned: str = human_readable_bool(user["shadow_banned"])
        admin: str = human_readable_bool(user["admin"])
        guest: str = human_readable_bool(user["is_guest"])
        display_name = user["displayname"]

        user_list.append(
            (
                name,
                deactivated,
                shadow_banned,
                admin,
                guest,
                display_name,
            )
        )
    return table(
        user_list,
        (
            "Name",
            "Deactivated",
            "Shadow-Banned",
            "Admin",
            "Guest",
            "Display Name",
        ),
        False,
    )