<commit_before>#!/usr/bin/env python
from trello import TrelloApi
from prettytable import PrettyTable

import sys
import os
import click
import re
import webbrowser


def load_cfg_vars_as_dict():
    sys.path.append(os.getcwd())
    import cyklecfg
    return {
        'trello_apikey': getattr(cyklecfg, 'TRELLO_APIKEY'),
        'trello_token': getattr(cyklecfg, 'TRELLO_TOKEN'),
        'trello_org': getattr(cyklecfg, 'TRELLO_ORG'),
        'trello_board_id': getattr(cyklecfg, 'TRELLO_BOARD_ID'),
        'github_owner': getattr(cyklecfg, 'GITHUB_OWNER'),
        'github_repo': getattr(cyklecfg, 'GITHUB_REPO')
    }


@click.group()
@click.pass_context
def cli(ctx):
    pass


@cli.command(name='init-cykle')
@click.pass_context
def init_cykle(ctx):
    try:
        cfgfile = open('cyklecfg.py', 'r')
    except IOError:
        pass
    else:
        print 'Cykle is already initialized'
        exit(0)

    trello_apikey = raw_input('Trello API Key: ')
    trello_api = TrelloApi(trello_apikey)
    token_url = trello_api.get_token_url('Cykle', expires='30days', write_access=True)
    webbrowser.open(token_url)

    trello_token = raw_input('Trello Token: ')
    trello_orgnization = raw_input('Trello Organization: ')
    trello_board_name = raw_input('Trello Board Name: ')

    trello_api = TrelloApi(trello_apikey, trello_token)
    boards = trello_api.organizations.get_board(trello_orgnization)
    for b in boards:
        if b['name'] == trello_board_name:
            trello_board_id = b['id']

    github_owner_name = raw_input('Github Owner Name: ')
    github_repository = raw_input('Github Repository: ')

    cfgtext_templ = \
        "TRELLO_APIKEY = '%s'\n" + \
        "TRELLO_TOKEN = '%s'\n" + \
        "TRELLO_ORG = '%s'\n" + \
        "TRELLO_BOARD_ID = '%s'\n" + \
        "GITHUB_OWNER = '%s'\n" + \
        "GITHUB_REPO = '%s'\n"

    cfgtext = cfgtext_templ % (
        trello_apikey,
        trello_token,
        trello_orgnization,
        trello_board_id,
        github_owner_name,
        github_repository
    )

    cfgfile = open('cyklecfg.py', 'w')
    cfgfile.write(cfgtext)


@cli.group()
@click.pass_context
def trello(ctx):
    ctx.obj.update(load_cfg_vars_as_dict())
    ctx.obj.update({'trello_api': TrelloApi(ctx.obj['trello_apikey'], ctx.obj['trello_token'])})


@trello.command(name='list-board')
@click.argument('org_name', default='')
@click.pass_context
def list_board(ctx, org_name):
    if not org_name:
        org_name = ctx.obj['trello_org']

    boards = ctx.obj['trello_api'].organizations.get_board(org_name)

    pt = PrettyTable(['board id', 'board name'])
    pt.align['board id'] = 'l'
    pt.align['board name'] = 'l'

    for b in boards:
        pt.add_row([b['id'], b['name']])

    print pt


@trello.command(name='setup-board')
@click.pass_context
def setup_board(ctx):
    lists = ['to_do', 'in_progress', 'code_review', 'to_deploy', 'live_qa', 'closed']
    for l in reversed(lists):
        ctx.obj['trello_api'].lists.new(l, ctx.obj['trello_board_id'])


@trello.command(name='list-card')
@click.argument('list_name', default='')
@click.pass_context
def list_card(ctx, list_name):
    cards = ctx.obj['trello_api'].boards.get_card(ctx.obj['trello_board_id'])

    pt = PrettyTable(['card id', 'card name', 'list name', 'members'])
    pt.align['card id'] = 'l'
    pt.align['card name'] = 'l'<commit_msg>issue#5: removed list board command<commit_after>#!/usr/bin/env python
from trello import TrelloApi
from prettytable import PrettyTable

import sys
import os
import click
import re
import webbrowser


def load_cfg_vars_as_dict():
    sys.path.append(os.getcwd())
    import cyklecfg
    return {
        'trello_apikey': getattr(cyklecfg, 'TRELLO_APIKEY'),
        'trello_token': getattr(cyklecfg, 'TRELLO_TOKEN'),
        'trello_org': getattr(cyklecfg, 'TRELLO_ORG'),
        'trello_board_id': getattr(cyklecfg, 'TRELLO_BOARD_ID'),
        'github_owner': getattr(cyklecfg, 'GITHUB_OWNER'),
        'github_repo': getattr(cyklecfg, 'GITHUB_REPO')
    }


@click.group()
@click.pass_context
def cli(ctx):
    pass


@cli.command(name='init-cykle')
@click.pass_context
def init_cykle(ctx):
    try:
        cfgfile = open('cyklecfg.py', 'r')
    except IOError:
        pass
    else:
        print 'Cykle is already initialized'
        exit(0)

    trello_apikey = raw_input('Trello API Key: ')
    trello_api = TrelloApi(trello_apikey)
    token_url = trello_api.get_token_url('Cykle', expires='30days', write_access=True)
    webbrowser.open(token_url)

    trello_token = raw_input('Trello Token: ')
    trello_orgnization = raw_input('Trello Organization: ')

    trello_board_name = raw_input('Trello Board Name: ')
    trello_api = TrelloApi(trello_apikey, trello_token)
    boards = trello_api.organizations.get_board(trello_orgnization)
    for b in boards:
        if b['name'] == trello_board_name:
            trello_board_id = b['id']

    github_owner_name = raw_input('Github Owner Name: ')
    github_repository = raw_input('Github Repository: ')

    cfgtext_templ = \
        "TRELLO_APIKEY = '%s'\n" + \
        "TRELLO_TOKEN = '%s'\n" + \
        "TRELLO_ORG = '%s'\n" + \
        "TRELLO_BOARD_ID = '%s'\n" + \
        "GITHUB_OWNER = '%s'\n" + \
        "GITHUB_REPO = '%s'\n"

    cfgtext = cfgtext_templ % (
        trello_apikey,
        trello_token,
        trello_orgnization,
        trello_board_id,
        github_owner_name,
        github_repository
    )

    cfgfile = open('cyklecfg.py', 'w')
    cfgfile.write(cfgtext)


@cli.group()
@click.pass_context
def trello(ctx):
    ctx.obj.update(load_cfg_vars_as_dict())
    ctx.obj.update({'trello_api': TrelloApi(ctx.obj['trello_apikey'], ctx.obj['trello_token'])})


@trello.command(name='setup-board')
@click.pass_context
def setup_board(ctx):
    lists = ['to_do', 'in_progress', 'code_review', 'to_deploy', 'live_qa', 'closed']
    for l in reversed(lists):
        ctx.obj['trello_api'].lists.new(l, ctx.obj['trello_board_id'])


@trello.command(name='list-card')
@click.argument('list_name', default='')
@click.pass_context
def list_card(ctx, list_name):
    cards = ctx.obj['trello_api'].boards.get_card(ctx.obj['trello_board_id'])

    pt = PrettyTable(['card id', 'card name', 'list name', 'members'])
    pt.align['card id'] = 'l'
    pt.align['card name'] = 'l'
{'fraction_non_alphanumeric': 0.14594168636721827, 'fraction_numerical': 0.001103230890464933, 'mean_word_length': 3.5720461095100866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6995187', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2364, 'n_words': 400}