Fix some style issues

This commit is contained in:
Sijmen 2018-07-22 11:45:15 +02:00
parent 4aa4b38617
commit 87789805fc
5 changed files with 51 additions and 42 deletions

View file

@ -1,20 +1,18 @@
import argparse
import re
import sys
from datetime import datetime
from typing import Any, Dict
import base32_crockford
import base32_crockford as base32
import api.stories
from config import Config
from util import print_wrap
from . import (COLOR_HEADER, COLOR_TITLE, COLOR_WHITE, _format_state,
_get_persons)
def __print_story(story: Dict[str, Any], persons: Dict[int, Any]) -> None:
def __print_story(story: Dict[str, Any]) -> None:
"""
Prints the title, the current state and the estimate of the story, if
available.
@ -25,7 +23,12 @@ def __print_story(story: Dict[str, Any], persons: Dict[int, Any]) -> None:
if 'current_state' in story:
state = _format_state(story['current_state'])
COLOR_HEADER.print('State:', state, end='\n\n')
COLOR_HEADER.print('State:', state, end='')
if story['current_state'] == 'accepted':
print(f" (at {story['accepted_at']})", end='')
print(end='\n\n')
if 'estimate' in story:
COLOR_HEADER.print('Estimate: ', end='')
@ -84,7 +87,7 @@ def __print_tasks(token: str, project_id: int, story_id: int) -> None:
for task in tasks:
print(end=' ')
print('[X]' if task['complete'] else '[ ]', end=' \033[34m')
print(base32_crockford.encode(task['id']), end=':\033[0m ')
print(base32.encode(task['id']), end=':\033[0m ')
print(task['description'])
print()
@ -120,7 +123,7 @@ def __print_blockers(token: str, project_id: int, story_id: int) -> None:
def blocker_repl(matchgroup: Any) -> str:
id = int(matchgroup.group(1))
code = base32_crockford.encode(id)
code = base32.encode(id)
return COLOR_HEADER.format(code)
pattern = re.compile(r'#(\d+)')
@ -130,19 +133,19 @@ def __print_blockers(token: str, project_id: int, story_id: int) -> None:
print(f' [{resolved}] {desc}')
def _stories_info(story: str) -> None:
def stories_info(story: str) -> None:
try:
token = Config['user']['api_token']
except KeyError:
sys.exit(1)
story_id = base32_crockford.decode(story)
story_id = base32.decode(story)
story = api.stories.get(token, story_id)
project_id = story['project_id']
persons = _get_persons(token, project_id)
__print_story(story, persons)
__print_story(story)
__print_owners(story, persons)
__print_description(story)
__print_labels(story)

View file

@ -1,5 +1,6 @@
import click
@click.group()
def cli():
pass

View file

@ -1,7 +1,7 @@
import sys
from typing import Dict
import base32_crockford
import base32_crockford as base32
import click
import tabulate
@ -20,18 +20,18 @@ def projects(context: click.Context) -> None:
# invoked as well. In this case, do nothing.
return
projects = api.projects.get(Config['user']['api_token'])
projects.sort(key=lambda project: project['name'])
projects_ = api.projects.get(Config['user']['api_token'])
projects_.sort(key=lambda project_: project_['name'])
aliases: Dict[int, str] = {}
for alias, alias_id in Config['project_aliases'].items():
aliases[int(alias_id)] = alias
for alias_, alias_id in Config['project_aliases'].items():
aliases[int(alias_id)] = alias_
table = []
for project in sorted(projects, key=lambda a: a['name']):
code = base32_crockford.encode(project['id'])
alias = aliases.get(project['id'])
table.append((code, project['name'], alias))
for project in sorted(projects_, key=lambda project_: project_['name']):
code = base32.encode(project['id'])
alias_ = aliases.get(project['id'])
table.append((code, project['name'], alias_))
print(tabulate.tabulate(table, headers=('Code', 'Name', 'Alias')))
@ -45,7 +45,7 @@ def alias() -> None:
@click.argument('code')
@click.argument('name')
def alias_add(code: str, name: str) -> None:
project_id = base32_crockford.decode(code)
project_id = base32.decode(code)
Config['project_aliases'][name] = str(project_id)
Config.write()

View file

@ -4,7 +4,7 @@ from collections import defaultdict
from datetime import datetime, timedelta
from typing import Any, DefaultDict, Dict, List, Sequence, Tuple, Optional
import base32_crockford
import base32_crockford as base32
import tabulate
import api.projects
@ -13,7 +13,7 @@ from config import Config
from util import require_login
from . import COLOR_HEADER, _format_state, _get_persons
from ._stories_info import _stories_info
from ._stories_info import stories_info
from .cli import cli
STATES = 'unstarted', 'planned', 'started', 'finished', 'delivered', 'accepted'
@ -23,7 +23,8 @@ Persons = Dict[int, Dict[str, Any]]
Totals = DefaultDict[int, Dict[str, int]]
def __get_row(item: Tuple[int, Dict[str, int]], persons: Persons) -> Sequence:
def __get_row(item: Tuple[int, Dict[str, int]], persons: Persons,
show_accepted: bool) -> Sequence:
owner_id, points = item
name = persons[owner_id]['name']
@ -34,15 +35,16 @@ def __get_row(item: Tuple[int, Dict[str, int]], persons: Persons) -> Sequence:
progress += f'\033[38;5;226m' + 'S' * round(points['started'])
progress += f'\033[94m' + 'F' * round(points['finished'])
progress += f'\033[38;5;208m' + 'D' * round(points['delivered'])
if show_accepted:
progress += f'\033[92m' + 'A' * round(points['accepted'])
progress += '\033[0m]'
return (name, *estimates, sum(estimates), progress)
return name, (*estimates), sum(estimates), progress
def __format_story(story: Dict[str, Any], persons: Persons, totals: Totals) \
-> Tuple[str, str, str, str, str, int]:
code = base32_crockford.encode(story['id'])
code = base32.encode(story['id'])
is_owner = False
initials = []
@ -72,26 +74,29 @@ def __format_story(story: Dict[str, Any], persons: Persons, totals: Totals) \
return code, type_, story['name'], owners, state, estimate
def __print_stories(stories: List[Dict[str, Any]], persons: Persons,
totals: Totals) -> None:
table = [__format_story(story, persons, totals) for story in stories]
def __print_stories(stories_: List[Dict[str, Any]], persons: Persons,
totals: Totals, show_accepted: bool) -> None:
table = (__format_story(story, persons, totals) for story in stories_
if show_accepted or story['current_state'] != 'accepted')
headers = 'Code', 'Type', 'Story name', 'Owners', 'State', 'Pts'
print(tabulate.tabulate(table, headers=headers), end='\n\n')
def __print_totals(totals: Totals, persons: Persons) -> None:
def __print_totals(totals: Totals, persons: Persons, show_accepted: bool) \
-> None:
COLOR_HEADER.print('Point totals:', end='\n\n')
state_headers = [_format_state(state) for state in STATES]
headers = ('Owner', *state_headers, 'Total', 'Progress')
data = [__get_row(item, persons) for item in totals.items()]
data.sort(key=lambda row: row[-2], reverse=True)
data = sorted((__get_row(item, persons, show_accepted)
for item in totals.items()),
key=lambda row: row[-2], reverse=True)
print(tabulate.tabulate(data, headers), end='\n\n')
def __print_burndown(token: str, iteration: Dict[str, Any], persons: Persons,
hide_accepted: bool = False) -> None:
def __print_burndown(token: str, iteration: Dict[str, Any],
show_accepted: bool) -> None:
COLOR_HEADER.print('Burndown:', end='\n\n')
start = datetime.strptime(iteration['start'], '%Y-%m-%dT%H:%M:%SZ')
@ -114,7 +119,7 @@ def __print_burndown(token: str, iteration: Dict[str, Any], persons: Persons,
progress = ''
if not hide_accepted:
if show_accepted:
progress += '\033[92m' + 'A' * round(counts[0] - accepted_points)
progress += '\033[38;5;208m' + 'D' * round(counts[1])
@ -132,7 +137,7 @@ def _stories_current(project: str, scope: str, show_accepted: bool) -> None:
try:
project_id = int(Config['project_aliases'][project])
except KeyError:
project_id = base32_crockford.decode(project)
project_id = base32.decode(project)
token = Config['user']['api_token']
@ -147,14 +152,14 @@ def _stories_current(project: str, scope: str, show_accepted: bool) -> None:
totals: DefaultDict[int, Dict[str, int]] = \
defaultdict(lambda: dict((state, 0) for state in STATES))
__print_stories(iteration['stories'], persons, totals)
__print_totals(totals, persons)
__print_burndown(token, iteration, persons, not show_accepted)
__print_stories(iteration['stories'], persons, totals, show_accepted)
__print_totals(totals, persons, show_accepted)
__print_burndown(token, iteration, show_accepted)
def _set_story_state(story: str, state: str) -> None:
token = Config['user']['api_token']
story_id = base32_crockford.decode(story)
story_id = base32.decode(story)
api.stories.put_story(token, story_id, current_state=state)
@ -172,6 +177,6 @@ def stories(project: str, story: Optional[str], scope: str,
if set_state is not None:
_set_story_state(story, set_state)
else:
_stories_info(story)
stories_info(story)
else:
_stories_current(project, scope, show_accepted)

View file

@ -1,3 +1,4 @@
click=6.7
appnope==0.1.0
astroid==1.6.1
autopep8==1.3.4
@ -35,4 +36,3 @@ urllib3==1.22
urwid==2.0.1
wcwidth==0.1.7
wrapt==1.10.11
click=6.7