Source

aodag.tasks / aodag / tasks / commands.py

Full commit
import sys
import os
from . import apis

def list_tasks(args):
    filename = args.config.get('tasks', 'file')

    if not os.path.exists(filename):
        print("{0} does'nt exists".format(filename))
        sys.exit(1)

    filters = []
    if args.state == 'new':
        filters.append(apis.is_new_task)
    if args.state == 'active':
        filters.append(apis.is_active_task)
    if args.state == 'finished':
        filters.append(apis.is_finished_task)

    with open(filename, "rb") as f:
        tasks = apis.load_tasks(f)
        for task in (t for t in tasks if all(apis.filter_many(filters, t))):
            print(apis.format_task(task))

def add_task(args):
    filename = args.config.get('tasks', 'file')

    if os.path.exists(filename):
        with open(filename, "rb") as f:
            tasks = apis.load_tasks(f)
    else:
        tasks = []

    task = apis.input_task()
    apis.add_task(tasks, task)

    with open(filename, 'wb') as f:
        apis.save_tasks(tasks, f)

def finish_task(args):
    print("finish task")