Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_taskwarrior(self, **kwargs):
tw_kwargs = dict(
data_location=self.tmp,
taskrc_location='/',
)
tw_kwargs.update(kwargs)
return TaskWarrior(**tw_kwargs)
def upload_new_tw_tasks(trello_lists, project_name, board_name, todo_list_name, doing_list_name, done_list_name):
"""
Upload new TaskWarrior tasks that never uploaded before
:trello_lists: the set of lists
:project_name: the project name
:board_name: the name of Trello board
:todo_list_name: name of list for todo taks
:doing_list_name: name of list for active tasks
:done_list_name: name of list for done tasks
"""
task_warrior = TaskWarrior(taskrc_location=taskwarrior_taskrc_location, data_location=taskwarrior_data_location)
tw_pending_tasks = task_warrior.tasks.pending().filter(project=project_name, trelloid=None)
tw_completed_tasks = task_warrior.tasks.completed().filter(project=project_name, trelloid=None)
for tw_pending_task in tw_pending_tasks:
if tw_pending_task.active:
upload_tw_task(tw_pending_task, get_trello_list(board_name, trello_lists, doing_list_name))
tw_pending_task['trellolistname'] = doing_list_name
tw_pending_task.save()
else:
if tw_pending_task['trellolistname']:
upload_tw_task(tw_pending_task, get_trello_list(board_name, trello_lists, tw_pending_task['trellolistname']))
else:
upload_tw_task(tw_pending_task, get_trello_list(board_name, trello_lists, todo_list_name))
tw_pending_task['trellolistname'] = todo_list_name
tw_pending_task.save()
for tw_completed_task in tw_completed_tasks:
upload_tw_task(tw_completed_task, get_trello_list(board_name, trello_lists, done_list_name))
def get_tw_task_by_trello_id(trello_id):
"""
Get a task by Trello ID
Trello ID must be unique, if not this raise an error
:project_name: the project name
:trello_id: Trello card ID
"""
tw_tasks = TaskWarrior(taskrc_location=taskwarrior_taskrc_location, data_location=taskwarrior_data_location).tasks.filter(trelloid=trello_id)
if len(tw_tasks) == 0:
return None
elif len(tw_tasks) == 1:
return tw_tasks[0]
else:
raise ValueError('Duplicated Trello ID {0} in Taskwarrior tasks. Trello IDs must be unique, please fix it before sync.'.format(trello_id))
def sync_trello_tw(trello_lists, project_name, board_name, todo_list_name, doing_list_name, done_list_name):
"""
Download from Trello all cards and sync with TaskWarrior tasks
:trello_lists: the set of lists
:project_name: the project name
:board_name: the name of Trello board
:todo_list_name: name of list for todo taks
:doing_list_name: name of list for active tasks
:done_list_name: name of list for done tasks
"""
task_warrior = TaskWarrior(taskrc_location=taskwarrior_taskrc_location, data_location=taskwarrior_data_location)
# Get all Task Warrior deleted tasks and seek for ones that have trelloid (locally deleted)
tw_deleted_tasks = task_warrior.tasks.filter(project=project_name,status='deleted')
for tw_deleted_task in tw_deleted_tasks:
if tw_deleted_task['trelloid']:
delete_trello_card(tw_deleted_task['trelloid'])
tw_deleted_task['trelloid'] = None
tw_deleted_task.save()
# Compare and sync Trello with Task Warrior
trello_dic_cards = get_trello_dic_cards(trello_lists)
trello_cards_ids = []
for list_name in trello_dic_cards:
for trello_card in trello_dic_cards[list_name]:
# Fech all data from card
trello_card.fetch(False)
trello_cards_ids.append(trello_card.id)
tw_task = get_tw_task_by_trello_id(trello_card.id)