~mapperr/trl

ref: 3af86c0080c0675344c7940f9cb7003f1274dde1 trl/trullo/printer.py -rw-r--r-- 3.2 KiB
3af86c00 — mapperr Use names as bases for shortcuts 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from typing import List

import attr

from trullo.shortener import Shortener
from trullo.trl_board import TrlBoard
from trullo.trl_card import TrlCard


@attr.s(auto_attribs=True)
class Printer:
    @staticmethod
    def print_boards(boards: List[TrlBoard]):
        symbol_count = Shortener. \
            get_min_symbols_to_uniq([board.get_normalized_name()
                                     for board in boards])
        print(f'symbol count is {symbol_count}')
        for board in boards:
            print(
                f"[{board.get_normalized_name()[0:symbol_count].lower()}] "
                f"{board.raw_data['name']}")

    @staticmethod
    def print_board(board: TrlBoard, list_shortcut: str = None):
        cards_names = [card.get_normalized_name() for card in board.cards]
        board_lists_names = \
            [list_.get_normalized_name() for list_ in board.lists]

        symbol_count_cards = Shortener.get_min_symbols_to_uniq(cards_names)
        symbol_count_lists = \
            Shortener.get_min_symbols_to_uniq(board_lists_names)

        print(f"{board.raw_data['shortUrl']}")
        print('------------------------------')
        print(f"{board.raw_data['name']}")
        print()
        if board.lists is not None:
            for list_ in board.lists:
                if list_shortcut is not None \
                        and not \
                        list_.get_normalized_name().startswith(list_shortcut):
                    continue
                shortcut = \
                    list_.get_normalized_name()[0:symbol_count_lists].lower()
                print(f"[{shortcut}] {list_.raw_data['name']}")
                for card in board.cards:
                    if card.raw_data['idList'] == list_.id:
                        card_shortcut = card.get_normalized_name()[
                                        0:symbol_count_cards].lower()
                        print(f"\t[{card_shortcut}] "
                              f"{card.raw_data['name']}")
        print()

    @staticmethod
    def print_board_lists(board: TrlBoard):
        symbol_count_lists = Shortener.get_min_symbols_to_uniq(
            [list_.get_normalized_name() for list_ in board.lists])
        print(f"{board.raw_data['shortUrl']}")
        print('------------------------------')
        print(f"{board.raw_data['name']}")
        print()
        if board.lists is not None:
            for list_ in board.lists:
                list_shortcut = \
                    list_.get_normalized_name()[0:symbol_count_lists].lower()
                print(f"[{list_shortcut}] {list_.raw_data['name']}")
        print()

    @staticmethod
    def print_card(card: TrlCard):
        d = card.raw_data
        formatted_desc = '\t' + str(d['desc']).replace('\n', '\n\t')

        print(f'{d["shortUrl"]}')
        print('-------------------------------------')
        print(f'{d["name"]}')
        if len(d['labels']) > 0:
            print()
        for label in d['labels']:
            label_name = label["name"] \
                if label["name"] is not None and label["name"] != "" \
                else label["color"]
            print(f'({label_name})  ', end='')
        print()
        print(formatted_desc)
        print()