Start task handle
This commit is contained in:
123
task.py
Normal file
123
task.py
Normal file
@@ -0,0 +1,123 @@
|
||||
# import sqlite3
|
||||
import os
|
||||
import argparse
|
||||
import json
|
||||
import getpass
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import action
|
||||
|
||||
def handle_task(args, last_action, conn):
|
||||
logging.info('> handle task')
|
||||
logging.debug('args: ' + str(args))
|
||||
|
||||
active_project_id = None
|
||||
if last_action:
|
||||
active_project_id = last_action[0]
|
||||
|
||||
active_task_id = None
|
||||
if last_action:
|
||||
active_task_id = last_action[1]
|
||||
|
||||
do_something = False
|
||||
|
||||
if args.create_name:
|
||||
do_something = True
|
||||
create_task(args, active_project_id, conn)
|
||||
|
||||
if args.delete_id:
|
||||
do_something = True
|
||||
delete_task(args.delete_id, conn)
|
||||
|
||||
if args.moving_id:
|
||||
do_something = True
|
||||
moving_task(args)
|
||||
|
||||
if args.edit_id:
|
||||
do_something = True
|
||||
edit_task(args, args.edit_id, conn)
|
||||
|
||||
if not do_something:
|
||||
list_task(active_task_id, conn)
|
||||
|
||||
def create_task(args, active_project_id, conn):
|
||||
logging.info('>> Create task')
|
||||
|
||||
query = """
|
||||
INSERT INTO task (project_id, username, name, status, priority, date, time, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
"""
|
||||
|
||||
status = 'open'
|
||||
priority = 'normal'
|
||||
# TODO Date & time
|
||||
date = ''
|
||||
time = ''
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (active_project_id, getpass.getuser(), args.create_name, status, priority, date, time, datetime.datetime.now(),))
|
||||
|
||||
task_id = cursor.lastrowid
|
||||
|
||||
action.create_action(cursor, project_id=active_project_id, task_id=task_id)
|
||||
|
||||
print('created task {}: {} (status: {})'.format(task_id, args.create_name, status))
|
||||
|
||||
def edit_task(args, task_id, conn):
|
||||
logging.info('>> Edit task')
|
||||
|
||||
update_args = {}
|
||||
if args.status:
|
||||
update_args['status'] = args.status
|
||||
if args.edit_name:
|
||||
update_args['name'] = args.edit_name
|
||||
|
||||
query = 'UPDATE task SET {} WHERE id = ?'
|
||||
query = query.format(', '.join("%s = '%s'" % (k, v) for k, v in update_args.items()))
|
||||
logging.debug('update task query: ' + query)
|
||||
|
||||
cursor = conn.cursor()
|
||||
if update_args:
|
||||
logging.debug('Do a task update')
|
||||
cursor.execute(query, (task_id,))
|
||||
|
||||
log_args = ', '.join("%s: '%s'" % (k, v) for k, v in update_args.items())
|
||||
print('updated task {}: ({})'.format(task_id, log_args))
|
||||
else:
|
||||
print('updated task {}: set active task')
|
||||
|
||||
action.create_action(cursor, task_id, message = 'update ' + str(update_args))
|
||||
|
||||
def moving_task(args):
|
||||
print('moving')
|
||||
|
||||
def delete_task(task_id, conn):
|
||||
logging.info('>> Remove task')
|
||||
|
||||
query = """
|
||||
DELETE FROM task
|
||||
WHERE id = ?;
|
||||
"""
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (task_id,))
|
||||
if cursor.rowcount != 1:
|
||||
logging.error('DELETE FAILED')
|
||||
print('deleted task {}: {}'.format(task_id, 'task_name'))
|
||||
|
||||
def list_task(active_task_id, conn):
|
||||
logging.info('>> No arguments')
|
||||
query = "SELECT id, username, status, priority, name FROM task;" #TODO Date & time
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
for row in cursor.fetchall():
|
||||
nb_note = 0
|
||||
task_id, username, status, priority, name = row
|
||||
current_task = ''
|
||||
if active_task_id and active_task_id == task_id: current_task = '*'
|
||||
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.format(current_task, task_id, username, status, priority, name, nb_note))
|
||||
|
||||
# 2: (budd) |open| |normal| test (0 notes)
|
||||
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
||||
Reference in New Issue
Block a user