@ -1,28 +1,29 @@
""" This module contains classes and functions to contain the kanban board information """
import sys
import numpy as np
import yaml
import os
import glob
class Task :
""" This class represents each task,
"""
""" This class represents each task,"""
def __init__ ( self , summary , score , description ) :
""" Initialize the task class
"""
""" Initialize the task class """
# Each task has the following properties
self . summary = summary # Summary of the task
self . score = score # Score for ticket
self . description = description # Description of ticket
self . summary = summary # Summary of the task
self . score = score # Score for ticket
self . description = description # Description of ticket
class Board :
def __init__ ( self , file = None ) :
""" Initialize the Board class, this class has three important class variables.
These are :
self . sprint | str - name of the current sprint
def __init__ ( self , file = None ) :
""" Initialize the Board class, this class has three important class variables.
These are : self . sprint | str - name of the current sprint
self . columns | list ( str ) - columns in kanban board
self . tasks | list ( list ( ) ) - tasks in each column
"""
self . sprint = None
self . columns = list ( )
@ -33,49 +34,54 @@ class Board:
if file :
self . read_yaml ( file )
def read_yaml ( self , file ) :
""" Read the yaml file in and set up the data
""" Read the yaml file in and set up the data
Arguments :
file - yaml file to read in
"""
# Read in the data
with open ( file , ' r ' ) as f :
with open ( file , " r " ) as f :
data = yaml . safe_load ( f )
# Assign the data to board variables
self . columns = data [ ' columns ' ]
self . columns = data [ " columns " ]
self . tasks = [ [ ] for col in self . columns ]
for task in data [ ' tasks ' ] :
self . tasks [ self . columns . index ( task [ ' column ' ] ) ] . append (
Task ( task [ ' summary ' ] , task [ ' score ' ] , task [ ' description ' ] ) )
for task in data [ " tasks " ] :
self . tasks [ self . columns . index ( task [ " column " ] ) ] . append (
Task ( task [ " summary " ] , task [ " score " ] , task [ " description " ] )
)
def write_yaml ( self , file ) :
""" Write the yaml file
""" Write the yaml file
Arguments :
file - yaml file to write to
"""
# Set up data to write out
# Set up data to write out
data = dict ( )
data [ ' columns ' ] = self . columns
data [ ' tasks ' ] = list ( )
for col , task_list in zip ( self . columns , self . tasks ) :
data [ " columns " ] = self . columns
data [ " tasks " ] = list ( )
for col , task_list in zip ( self . columns , self . tasks ) :
for task in task_list :
data [ ' tasks ' ] . append ( { ' column ' : col , ' summary ' : task . summary , ' score ' : task . score ,
' description ' : task . description } )
with open ( file , ' w ' ) as f :
data [ " tasks " ] . append (
{
" column " : col ,
" summary " : task . summary ,
" score " : task . score ,
" description " : task . description ,
}
)
with open ( file , " w " ) as f :
yaml . dump ( data , f )
def move_task ( self , col_index , task_index , direction ) :
""" This class method moves tasks between columns by incrementing/decrementing the column
""" This class method moves tasks between columns by incrementing/decrementing the column
index
Arguments :
col_index - index of the column we are in
task_index - index of the task we are changing in the column
@ -85,41 +91,66 @@ class Board:
moved - True if a task was moved else false
"""
task = self . tasks [ col_index ] [ task_index ]
if col_index + direction > = 0 and col_index + direction < len ( self . columns ) :
self . tasks [ col_index + direction ] . append ( task )
if col_index + direction > = 0 and col_index + direction < len ( self . columns ) :
self . tasks [ col_index + direction ] . append ( task )
del self . tasks [ col_index ] [ task_index ]
return True
else :
else :
return False
def print_board_items ( self ) :
for i , col in enumerate ( self . columns ) :
print ( col )
print ( self . tasks [ i ] )
def get_columns ( self ) :
""" Return columns"""
""" Return columns"""
return self . columns
def get_tasks ( self ) :
""" Return tasks"""
""" Return tasks"""
return self . tasks
def get_task ( self , icol , itask ) :
""" Return a task based on column and task index"""
""" Return a task based on column and task index"""
return self . tasks [ icol ] [ itask ]
def update_task ( self , icol , itask , task ) :
""" Update the task based on text """
def update_task ( self , icol , itask , task ) :
""" Update the task based on text"""
self . tasks [ icol ] [ itask ] = task
def add_task ( self , icol , task ) :
def add_task ( self , icol , task ) :
""" Add a task to icol """
self . tasks [ icol ] . append ( task )
def del_task ( self , icol , itask ) :
del self . tasks [ icol ] [ itask ]
class BoardList :
""" This class is used to process the full list of boards """
def __init__ ( self ) :
self . boards = self . get_boards ( )
def get_boards ( self ) :
""" This function returns the boards that have been created """
configpath = os . path . join (
os . environ . get ( " APPDATA " )
or os . environ . get ( " XDG_CONFIG_HOME " )
or os . path . join ( os . environ [ " HOME " ] , " .config " ) ,
" pykban " ,
)
boards = list ( )
for board in glob . glob ( os . path . join ( configpath , " (*.yaml) " ) ) :
with open ( board , " r " ) as f :
data = yaml . safe_load ( f )
try :
boards . append ( ( data [ " name " ] , board ) )
except KeyError :
print ( " Board yaml file is missing the name attribute " )
sys . exit ( )
return boards