~mapperr/trl

ref: f9a6cd5ee6afd98e66b2adee799ee8be0ae18b11 trl/trullo.py -rw-r--r-- 3.6 KiB
f9a6cd5e — mapperr Refactor and tests 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""Trullo

usage:
    trl b [<board_shortcut>]
    trl l [<list_shortcuts>...]
    trl ll
    trl c <card_shortcut> [o | m <list_shortcut> | e | n <list_shortcut>]
    trl c n <list_shortcut>
    trl g <api_path>
    trl -h

    -h --help  this help message


commands:
    b [<board_shortcut>]
        shows the boards you can access
        with board_shortcut you can select the board you want to work with

    l [<list_shortcuts>...]
        shows lists and cards in the board you have currently selected
        with list_shortcuts you can show only selected lists and their cards

    ll
        shows only the board's lists

    c <card_shortcut> [o | m <list_shortcut> | e]
        shows the card infos
        with o it opens the card shortLink with your default browser
        with m and a target list you can move the card to that list
        with e you can edit the card title and description in your $EDITOR

    c n <list_shortcut>
        create a new card in the list specified by list_shortcut

    g <api_path>
        make a direct api call adding auth params automatically (for debugging/hacking purpose)

env:
    you have to export this 2 variables to authenticate with trello:

    TRELLO_API_TOKEN - your trello api key
    TRELLO_TOKEN - a generated token

    you can obtain those values here: https://trello.com/app-key

"""
import logging
import pprint
import tempfile

from docopt import docopt

from trullo.printer import Printer
from trullo.shortener import Shortener
from trullo.tclient import TClient
from trullo.tconfig import TConfig
# logging.basicConfig(level=logging.DEBUG)
from trullo.usecases import Usecases

logging.basicConfig(level=logging.INFO)
logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)

logger = logging.getLogger(__name__)

if __name__ == '__main__':
    args = docopt(__doc__, version='Trullo beta')

    tclient = TClient()

    tmpdir = tempfile.gettempdir()
    selected_board_filepath = f'{tmpdir}/.trl-selected-board'

    usecases = Usecases(TConfig(selected_board_filepath),
                        TClient(),
                        Shortener(),
                        Printer())

    selected_board_id, selected_board_name = usecases.get_selected_board()

    if args['g']:
        api_path = args['<api_path>']
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(tclient.get(api_path))

    if args['b']:
        if args['<board_shortcut>']:
            board_shortcut = args['<board_shortcut>']
            usecases.select_board(board_shortcut)
        else:
            usecases.print_board_list()

    # stuff that works only if a board is selected
    if not args['b'] and selected_board_name is None:
        print(f'first select a board with `trl b`')
        exit(1)

    if args['ll']:
        usecases.print_board_lists()

    if args['l']:
        list_shortcuts = args['<list_shortcuts>']
        usecases.print_lists(list_shortcuts)

    if args['c']:
        new_command = args['n']
        if new_command:
            target_list_shortcut = args['<list_shortcut>']
            usecases.create_card(target_list_shortcut)
        else:
            card_shortcut = args['<card_shortcut>']
            open_command = args['o']
            move_command = args['m']
            edit_command = args['e']
            if open_command:
                usecases.open_card_in_browser(card_shortcut)
            elif move_command:
                target_list_shortcut = args['<list_shortcut>']
                usecases.move_card(card_shortcut, target_list_shortcut)
            elif edit_command:
                usecases.update_card(card_shortcut)
            else:
                usecases.print_card(card_shortcut)