Ejemplo n.º 1
0
def delete_cards(config, force, noninteractive, tags, no_tags, match, listname, attachments, has_due):
    '''Delete a set of cards specified
    '''
    _, board, _ = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    method = 'delete' if force else 'archive'
    if noninteractive:
        if force:
            [c.delete() for c in cards]
        else:
            [c.set_closed(True) for c in cards]
    else:
        for card in cards:
            display.show_card(card)
            if prompt_for_confirmation('Delete this card?'):
                if force:
                    card.delete()
                else:
                    card.set_closed(True)
                click.secho('Card {}d!'.format(method), fg='red')
Ejemplo n.º 2
0
def show_soon(config, json, tsv):
    _, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    cards = BoardTool.filter_cards(board, has_due_date=True)
    display.show_cards(cards, use_json=json, tsv=tsv, sort='due')
Ejemplo n.º 3
0
def delete_cards(config, force, noninteractive, tags, no_tags, match, listname, attachments, has_due):
    '''Delete a set of cards specified
    '''
    _, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    method = 'delete' if force else 'archive'
    if noninteractive:
        if force:
            [c.delete() for c in cards]
        else:
            [c.set_closed(True) for c in cards]
    else:
        for card in cards:
            display.show_card(card)
            if prompt_for_confirmation('Delete this card?'):
                if force:
                    card.delete()
                else:
                    card.set_closed(True)
                click.secho('Card {}d!'.format(method), fg='red')
Ejemplo n.º 4
0
def grep(config, pattern, insensitive, count, regexp, by, fields, json):
    '''egrep through titles of cards on this board. This command attemps to replicate a couple of grep flags
    faithfully, so if you're a power-user of grep this command will feel familiar.
    One deviation from grep is the --json flag, which outputs all matching cards in full JSON format.
    '''
    if not (pattern or regexp):
        click.secho(
            'No pattern provided to grep: use either the argument or -e',
            fg='red')
        raise GTDException(1)
    # Merge together the different regex arguments
    final_pattern = '|'.join(regexp) if regexp else ''
    if pattern and final_pattern:
        final_pattern = final_pattern + '|' + pattern
    elif pattern:
        final_pattern = pattern
    flags = re.I if insensitive else 0
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board,
                                   title_regex=final_pattern,
                                   regex_flags=flags)
    if count:
        print(sum(1 for _ in cards))
        return
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    display.show_cards(cards, use_json=json, sort=by, table_fields=fields)
Ejemplo n.º 5
0
def grep(config, pattern, insensitive, count, regexp):
    '''egrep through titles of cards on this board. This command attemps to replicate a couple of grep flags
    faithfully, so if you're a power-user of grep this command will feel familiar.
    '''
    if not (pattern or regexp):
        click.secho('No pattern provided to grep: use either the argument or -e', fg='red')
        raise GTDException(1)
    # Merge together the different regex arguments
    final_pattern = '|'.join(regexp) if regexp else ''
    if pattern and final_pattern:
        final_pattern = final_pattern + '|' + pattern
    elif pattern:
        final_pattern = pattern
    flags = re.I if insensitive else 0
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        title_regex=final_pattern,
        regex_flags=flags
    )
    if count:
        print(sum(1 for _ in cards))
        raise GTDException(0)
    display = Display(config.color)
    if config.banner:
        display.banner()
    display.show_cards(cards)
Ejemplo n.º 6
0
def review(config, tags, no_tags, match, listname, attachments, has_due,
           by_due):
    '''show a smart, command-line based menu for each card selected.
    This menu will prompt you to add tags to untagged cards, to attach the title
    of cards which have a link in the title, and gives you all the other functionality combined.
    '''
    connection, board = BoardTool.start(config)
    if by_due:
        cards = BoardTool.filter_cards(board, has_due_date=True)
        cards = sorted(cards, key=lambda c: c.due)
    else:
        cards = BoardTool.filter_cards(
            board,
            tags=tags,
            no_tags=no_tags,
            title_regex=match,
            list_regex=listname,
            has_attachments=attachments,
            has_due_date=has_due,
        )
    list_lookup = BoardTool.list_lookup(board)
    label_lookup = BoardTool.label_lookup(board)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        CardTool.smart_menu(card,
                            display.show_card,
                            list_lookup,
                            label_lookup,
                            color=config.color)
    click.echo('All done, have a great day!')
Ejemplo n.º 7
0
def add_card(config, title, message, edit, listname):
    '''Add a new card. If no title is provided, $EDITOR will be opened so you can write one.'''
    connection, board = BoardTool.start(config)
    if listname is None:
        inbox = BoardTool.get_inbox_list(connection, config)
    else:
        pattern = re.compile(listname, flags=re.I)
        target_lists = filter(lambda x: pattern.search(x.name),
                              board.get_lists('open'))
        try:
            inbox = next(target_lists)
        except StopIteration:
            click.secho('No list names matched by {}'.format(listname),
                        fg='red')
            raise GTDException(1)
    if not title:
        title = click.edit(require_save=True, text='<Title here>')
        if title is None:  # No changes were made in $EDITOR
            click.secho('No title entered for the new card!', fg='red')
            raise GTDException(1)
        else:
            title = title.strip()
    returned = inbox.add_card(name=title, desc=message)
    if edit:
        display = Display(config.color)
        list_lookup = BoardTool.list_lookup(board)
        label_lookup = BoardTool.label_lookup(board)
        CardTool.smart_menu(returned,
                            display.show_card,
                            list_lookup,
                            label_lookup,
                            color=config.color)
    else:
        click.secho('Successfully added card {0}!'.format(returned),
                    fg='green')
Ejemplo n.º 8
0
def show_cards(config, json, tsv, tags, no_tags, match, listname, attachments, has_due, assigned, completed, include_closed):
    '''Display cards
    The show command prints a table of all the cards with fields that will fit on the terminal you're using.
    You can change this formatting by passing one of --tsv or --json, which will output as a tab-separated value sheet or JSON.
    This command along with the batch & review commands share a flexible argument scheme for getting card information.
    Mutually exclusive arguments include -t/--tags & --no-tags along with -j/--json & --tsv
    '''
    _, board, current_user = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        current_user=current_user,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
        assigned=assigned,
        completed=completed,
        include_closed=include_closed
    )
    display.show_cards(cards, use_json=json, tsv=tsv)
Ejemplo n.º 9
0
def grep(config, pattern, insensitive, count, regexp):
    '''egrep through titles of cards on this board. This command attemps to replicate a couple of grep flags
    faithfully, so if you're a power-user of grep this command will feel familiar.
    '''
    if not (pattern or regexp):
        click.secho('No pattern provided to grep: use either the argument or -e', fg='red')
        raise GTDException(1)
    # Merge together the different regex arguments
    final_pattern = '|'.join(regexp) if regexp else ''
    if pattern and final_pattern:
        final_pattern = final_pattern + '|' + pattern
    elif pattern:
        final_pattern = pattern
    flags = re.I if insensitive else 0
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        title_regex=final_pattern,
        regex_flags=flags
    )
    if count:
        print(sum(1 for _ in cards))
        raise GTDException(0)
    display = Display(config.color)
    if config.banner:
        display.banner()
    display.show_cards(cards)
Ejemplo n.º 10
0
def batch_attach(config):
    '''Extract HTTP links from card titles'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board, title_regex=VALID_URL_REGEX)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Attach title?', True):
            CardTool.title_to_link(card)
Ejemplo n.º 11
0
def batch_attach(config):
    '''Extract HTTP links from card titles'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board, title_regex=VALID_URL_REGEX)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Attach title?', True):
            CardTool.title_to_link(card)
Ejemplo n.º 12
0
def batch_tag(config, tags, no_tags, match, listname, attachments, has_due):
    '''Change tags on each card selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board,
                                   tags=tags,
                                   no_tags=no_tags,
                                   title_regex=match,
                                   list_regex=listname,
                                   has_attachments=attachments,
                                   has_due_date=has_due)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        CardTool.add_labels(card)
Ejemplo n.º 13
0
def show_unresponded(config, json):
    '''Display all unresponded comments for current account'''
    connection, _, current_user = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    comments = get_unresponded_comments(connection, current_user)
    display.show_comments(comments, use_json=json)
Ejemplo n.º 14
0
def batch_due(config, tags, no_tags, match, listname, attachments, has_due):
    '''Set due date for all cards selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board,
                                   tags=tags,
                                   no_tags=no_tags,
                                   title_regex=match,
                                   list_regex=listname,
                                   has_attachments=attachments,
                                   has_due_date=has_due)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Set due date?'):
            CardTool.set_due_date(card)
Ejemplo n.º 15
0
def batch_move(config, tags, no_tags, match, listname, attachments, has_due):
    '''Change the list of each card selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(board,
                                   tags=tags,
                                   no_tags=no_tags,
                                   title_regex=match,
                                   list_regex=listname,
                                   has_attachments=attachments,
                                   has_due_date=has_due)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Want to move this one?', True):
            CardTool.move_to_list(card)
Ejemplo n.º 16
0
def show_tags(config, json):
    '''Display all tags on this board'''
    _, board, _ = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    tag_names = [t.name for t in board.get_labels()]
    display.show_raw(tag_names, use_json=json)
Ejemplo n.º 17
0
def show_tags(config, json):
    '''Display all tags on this board'''
    _, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    tag_names = [t.name for t in board.get_labels()]
    display.show_raw(tag_names, use_json=json)
Ejemplo n.º 18
0
def batch_tag(config, tags, no_tags, match, listname, attachments, has_due):
    '''Change tags on each card selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        CardTool.add_labels(card)
Ejemplo n.º 19
0
def show_lists(config, json, show_all):
    '''Display all lists on this board'''
    _, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    list_filter = 'all' if show_all else 'open'
    list_names = [l.name for l in board.get_lists(list_filter)]
    display.show_raw(list_names, use_json=json)
Ejemplo n.º 20
0
def show_lists(config, json, show_all):
    '''Display all lists on this board'''
    _, board, _ = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    list_filter = 'all' if show_all else 'open'
    list_names = [l.name for l in board.get_lists(list_filter)]
    display.show_raw(list_names, use_json=json)
Ejemplo n.º 21
0
def batch_due(config, tags, no_tags, match, listname, attachments, has_due):
    '''Set due date for all cards selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Set due date?'):
            CardTool.set_due_date(card)
Ejemplo n.º 22
0
def batch_move(config, tags, no_tags, match, listname, attachments, has_due):
    '''Change the list of each card selected'''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        display.show_card(card)
        if prompt_for_confirmation('Want to move this one?', True):
            CardTool.move_to_list(card)
Ejemplo n.º 23
0
def add_card(config, title, message, edit):
    '''Add a new card. If no title is provided, $EDITOR will be opened so you can write one.'''
    connection, board = BoardTool.start(config)
    inbox = BoardTool.get_inbox_list(connection, config)
    if not title:
        title = click.edit(require_save=True, text='<Title here>')
        if title is None:  # No changes were made in $EDITOR
            click.secho('No title entered for the new card!', fg='red')
            raise GTDException(1)
        else:
            title = title.strip()
    returned = inbox.add_card(name=title, desc=message)
    if edit:
        display = Display(config.color)
        list_lookup = BoardTool.list_lookup(board)
        label_lookup = BoardTool.label_lookup(board)
        CardTool.smart_menu(returned, display.show_card, list_lookup, label_lookup, Colors.yellow)
    else:
        click.secho('Successfully added card {0}!'.format(returned), fg='green')
Ejemplo n.º 24
0
def add_card(config, title, message, edit):
    '''Add a new card. If no title is provided, $EDITOR will be opened so you can write one.'''
    connection, board = BoardTool.start(config)
    inbox = BoardTool.get_inbox_list(connection, config)
    if not title:
        title = click.edit(require_save=True, text='<Title here>')
        if title is None:  # No changes were made in $EDITOR
            click.secho('No title entered for the new card!', fg='red')
            raise GTDException(1)
        else:
            title = title.strip()
    returned = inbox.add_card(name=title, desc=message)
    if edit:
        display = Display(config.color)
        list_lookup = BoardTool.list_lookup(board)
        label_lookup = BoardTool.label_lookup(board)
        CardTool.smart_menu(returned, display.show_card, list_lookup, label_lookup, Colors.yellow)
    else:
        click.secho('Successfully added card {0}!'.format(returned), fg='green')
Ejemplo n.º 25
0
def delete_list(config, name, noninteractive):
    '''Delete a list by name'''
    _, board = BoardTool.start(config)
    lists = [l for l in board.get_lists('open') if l.name == name]
    if not lists:
        click.secho('No such list {}'.format(name), fg='red')
    for l in lists:
        if noninteractive or prompt_for_confirmation('Close list "{}"?'.format(
                l.name)):
            l.close()
            click.secho('Closed {}!'.format(l.name), fg='green')
Ejemplo n.º 26
0
def delete_tag(config, name, noninteractive):
    '''Delete a tag by name'''
    _, board = BoardTool.start(config)
    tags = [l for l in board.get_labels() if l.name == name]
    if not tags:
        click.secho('No such tag {}'.format(name), fg='red')
    for t in tags:
        if noninteractive or prompt_for_confirmation('Delete tag "{}"?'.format(
                t.name)):
            board.delete_label(t.id)
            click.secho('Deleted {}!'.format(t.name), fg='green')
Ejemplo n.º 27
0
def delete_lists(config, name, noninteractive):
    '''Delete lists containing the substring <name>
    '''
    _, board, _ = BoardTool.start(config)
    lists = [l for l in board.get_lists('open') if name in l.name]
    if noninteractive:
        [l.set_closed() for l in lists]
    else:
        for l in lists:
            if prompt_for_confirmation('Close this list?'):
                l.set_closed()
                click.secho('Closed!', fg='green')
Ejemplo n.º 28
0
def show_cards(config, json, tsv, tags, no_tags, match, listname, attachments, has_due):
    '''Display cards
    The show command prints a table of all the cards with fields that will fit on the terminal you're using.
    You can change this formatting by passing one of --tsv or --json, which will output as a tab-separated value sheet or JSON.
    This command along with the batch & review commands share a flexible argument scheme for getting card information.
    Mutually exclusive arguments include -t/--tags & --no-tags along with -j/--json & --tsv
    '''
    _, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    display.show_cards(cards, use_json=json, tsv=tsv)
Ejemplo n.º 29
0
def delete_lists(config, name, noninteractive):
    '''Delete lists containing the substring <name>
    '''
    _, board = BoardTool.start(config)
    lists = [l for l in board.get_lists('open') if name in l.name]
    if noninteractive:
        [l.set_closed() for l in lists]
    else:
        for l in lists:
            if prompt_for_confirmation('Close this list?'):
                l.set_closed()
                click.secho('Closed!', fg='green')
Ejemplo n.º 30
0
def review(config, tags, no_tags, match, listname, attachments, has_due):
    '''show a smart, command-line based menu for each card selected.
    This menu will prompt you to add tags to untagged cards, to attach the title
    of cards which have a link in the title, and gives you all the other functionality combined.
    '''
    connection, board = BoardTool.start(config)
    cards = BoardTool.filter_cards(
        board,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due
    )
    list_lookup = BoardTool.list_lookup(board)
    label_lookup = BoardTool.label_lookup(board)
    display = Display(config.color)
    if config.banner:
        display.banner()
    for card in cards:
        CardTool.smart_menu(card, display.show_card, list_lookup, label_lookup, Colors.yellow)
    click.echo('All done, have a great day!')
Ejemplo n.º 31
0
def show_boards(config, json, tsv, by, show_all):
    '''Show all boards your account can access'''
    connection, board = BoardTool.start(config)
    display = Display(config.color)
    if config.banner and not json:
        display.banner()
    if show_all:
        boards = connection.trello.fetch_json('/members/me/boards/?filter=all')
    else:
        boards = connection.boards
    if json:
        display.show_raw(boards, use_json=json)
        return
    # Set up a table to hold our boards
    board_columns = ['name', 'activity', 'members', 'permission', 'url']
    if by not in board_columns:
        click.secho('Field {} is not a valid field: {}'.format(
            by, ','.join(board_columns)),
                    fg='red')
        raise GTDException(1)
    table = prettytable.PrettyTable()
    table.field_names = board_columns
    table.align = 'l'
    if tsv:
        table.set_style(prettytable.PLAIN_COLUMNS)
    else:
        table.hrules = prettytable.FRAME
    for b in boards:
        table.add_row([
            b['name'],
            b['dateLastActivity'] or '',
            len(b['memberships']),
            b['prefs']['permissionLevel'],
            b['shortUrl'],
        ])
    try:
        table[0]
    except IndexError:
        click.secho('You have no boards!', fg='red')
    print(table.get_string(sortby=by))
Ejemplo n.º 32
0
def add_board(config, boardname):
    connection, _ = BoardTool.start(config)
    if connection.trello.add_board(boardname):
        click.secho('Added board {}'.format(boardname), fg='green')
Ejemplo n.º 33
0
def add_tag(config, tagname, color):
    '''Add a new tag'''
    connection, board = BoardTool.start(config)
    label = board.add_label(tagname, color)
    click.secho('Successfully added tag {0}!'.format(label), color='green')
Ejemplo n.º 34
0
def add_board(config, boardname):
    connection, _ = BoardTool.start(config)
    if connection.trello.add_board(boardname):
        click.secho('Added board {}'.format(boardname), fg='green')
Ejemplo n.º 35
0
def add_list(config, listname):
    '''Add a new list'''
    connection, board = BoardTool.start(config)
    l = board.add_list(listname)
    click.secho('Successfully added list {0}!'.format(l), color='green')
Ejemplo n.º 36
0
def add_tag(config, tagname, color):
    '''Add a new tag'''
    connection, board = BoardTool.start(config)
    label = board.add_label(tagname, color)
    click.secho('Successfully added tag {0}!'.format(label), color='green')
Ejemplo n.º 37
0
def add_list(config, listname):
    '''Add a new list'''
    connection, board = BoardTool.start(config)
    l = board.add_list(listname)
    click.secho('Successfully added list {0}!'.format(l), color='green')