Exemplo n.º 1
0
def assign_command(n=-1, p=-1, t=-1):
    """
    Assign a note to a project or task, or a task to a project.
    """
    c = conn()
    if n > 0:
        # We are assigning a note to a project or task.
        if p > 0:
            element = Project.get(c, p)
        elif t > 0:
            element = Task.get(c, t)
        else:
            raise Exception("You must specify either a project id or a task id.")
        note = Note.get(c, n)
        note.assign(c, element)
    elif t > 0:
        task = Task.get(c, t)
        # We are assigning a task to a project.
        if p > 0:
            project = Project.get(c, p)
            task.assign(c, project)
        else:
            raise Exception("You must specify a project id to assign the task to.")
    else:
        raise Exception("You didn't specify anything to assign!")
Exemplo n.º 2
0
def test_create_task():
    conn = get_conn()
    task = Task.create(conn, name="My New Task", created_at = datetime.datetime.now())
    assert task.id == 1
    assert task.elapsed_seconds() < 0.01

    lookup_task = Task.get(conn, 1)
    assert lookup_task.name == "My New Task"
    assert task.elapsed_seconds() < 0.01
Exemplo n.º 3
0
def tasks_command(by="id", search=-1):
    """
    List all tasks.
    """
    c = conn()
    if search > 0:
        tasks = Task.search(c, search, by)
    else:
        tasks = Task.all(c, by)

    for task in tasks:
        print task.display_line()
    if len(tasks) == 0:
        print "No tasks found."
Exemplo n.º 4
0
def archive_command(
    n=-1, p=-1, t=-1  # id of the note to archive  # id of the project to archive  # id of the task to archive
):
    """
    Archive the note, project or task specified.
    """
    c = conn()
    if n > 0:
        Note.archive(c, n)
    elif p > 0:
        Project.archive(c, p)
    elif t > 0:
        Task.archive(c, t)
    else:
        raise Exception()
Exemplo n.º 5
0
def update_command(t=-1, p=-1, n=-1, r=-1, **kwargs):
    """
    Update a project, task or note with the supplied kwargs.
    """
    c = conn()
    if t > 0:
        Task.update(c, t, kwargs)
    elif n > 0:
        Note.update(c, n, kwargs)
    elif p > 0:
        Project.update(c, p, kwargs)
    elif r > 0:
        Recipe.update(c, r, kwargs)
    else:
        raise Exception("Must specify one of t (task), n (note), p (project) or r (recipe).")
Exemplo n.º 6
0
def delete_command(
    n=-1, p=-1, t=-1  # id of the note to delete  # id of the project to delete  # id of the task to delete
):
    """
    Delete the note, project or task specified.
    """
    c = conn()
    if n > 0:
        Note.delete(c, n)
    elif p > 0:
        Project.delete(c, p)
    elif t > 0:
        Task.delete(c, t)
    else:
        raise Exception()
Exemplo n.º 7
0
def note_command(
    note="",  # the contents of the note
    p=-1,  # the project id to link the new note to (optional)
    t=-1,  # the task id to link the new note to (optional)
):
    """
    Create a new note. If note contents are not specified, will read from
    STDIN.
    """
    c = conn()

    if len(note) == 0:
        note = sys.stdin.read().strip()
    if len(note) == 0:
        raise Exception("You didn't pass any content for your note!")

    n = Note.create(c, note=note, created_at=datetime.now())

    print "Created note", n.id

    if p > 0:
        project = Project.get(c, p)
        n.assign(c, project)
        print "Assigned to project %s" % p

    elif t > 0:
        task = Task.get(c, t)
        n.assign(c, task)
        print "Assigned to task %s" % t
Exemplo n.º 8
0
 def last_completed_task(self, conn=None):
     if not conn:
         conn = self.conn
     sql = "select * from %s where recipe_id = %s ORDER BY completed_at DESC LIMIT 1" % (Task.table_name(), self.id)
     last_completed_tasks = [Task.load(conn, row) for row in conn.execute(sql)]
     if len(last_completed_tasks) == 1:
         return last_completed_tasks[0]
Exemplo n.º 9
0
def inbox_command():
    """
    Lists all notes and tasks that are still in the 'inbox', i.e. not assigned to projects, tasks or other elements.
    """
    c = conn()
    notes = Note.inbox(c)
    for note in notes:
        print note.display_line()

    tasks = Task.inbox(c)
    for task in tasks:
        print task.display_line()
Exemplo n.º 10
0
def start_command(r=None):
    """
    Start a timer for a recipe.
    """
    c = conn()
    recipe = Recipe.get(c, r)
    recipe_id = recipe.id
    print recipe.recipe
    task = Task.create(
        c, name="Doing Recipe %s (%s)" % (recipe_id, recipe.name), recipe_id=recipe_id, context=recipe.context
    )
    time_command(task.id)
    print "Created task %s and started timer" % task.id
Exemplo n.º 11
0
def complete_command(p=-1, t=-1):  # id of the project to mark complete  # id of the task to mark complete
    """
    Mark the project or task as completed.
    """
    c = conn()
    if p > 0:
        project = Project.get(c, p)
        project.complete(c)
        Project.archive(c, project.id)
        print "Project %s marked as complete!" % p
    elif t > 0:
        task = Task.get(c, t)
        task.complete(c)
        print "Task %s marked as complete!" % t
    else:
        raise Exception()
Exemplo n.º 12
0
def blotter_command():
    """
    Starts a timer. Records everything written to STDIN. Stops timer when
    ctrl+d is typed. Creates a task with last line of blotter as name, rest of
    blotter as description.
    """
    c = conn()
    created_at = datetime.now()
    description = ""
    print "Type ctrl+d to save task (might need to type it twice). ctrl+c to cancel."
    print "Started at %s" % created_at
    try:
        while True:
            line = sys.stdin.readline()
            if len(line) > 1:
                timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                description += "%s:: %s" % (timestamp, line)
            elif len(line) == 1:
                description += line
            else:
                break

        name = raw_input("name of task: ")
        context = raw_input("context for task (defaults to @computer): ")
        if not context:
            context = "@computer"
        worktype = raw_input("type of work (defaults to 'adhoc'): ")

        description = description.strip()
        completed_at = datetime.now()
        task = Task.create(
            c,
            name=name,
            context=context,
            worktype=worktype,
            description=description,
            created_at=created_at,
            completed_at=completed_at,
        )
        Timer.create(c, task_id=task.id, started_at=created_at, finished_at=completed_at, description=task.description)
        print task.id
    except KeyboardInterrupt:
        print "cancelled"
Exemplo n.º 13
0
def show_command(
    t=-1,  # id of task to show detail on
    n=-1,  # id of note to show detail on
    p=-1,  # id of project to show detail on
    portfolio=-1,  # id of portfolio to show detail on
):
    """
    Print detailed information for a project, task, note or portfolio.
    """
    c = conn()
    if t > 0:
        task = Task.get(c, t)
        print task.show()
    elif n > 0:
        note = Note.get(c, n)
        print note.show()
    elif p > 0:
        project = Project.get(c, p)
        print project.show()
    elif portfolio > 0:
        portfolio = Portfolio.get(c, portfolio)
        print portfolio.show()
    else:
        raise Exception("Must specify one of t (task), n (note), p (project) or portfolio.")
Exemplo n.º 14
0
def tasktime_command(t=None):
    c = conn()
    task = Task.get(c, t)
    print task.total_time(c)
Exemplo n.º 15
0
            "title" : project.description,
            "state" : "child"
            }

def dict_for_portfolio(portfolio):
    return {
            "name" : "[%d] %s" % (portfolio.id, portfolio.name),
            "title" : portfolio.description,
            "state" : "child"
            }

inbox = {
        "name" : "inbox",
        "children" : [{
            "name" : "inbox",
            "children" : [dict_for_task(t) for t in Task.inbox(conn)]
            }]
        }

data = {
    "name" : 'ado',
    "children" : [inbox]
    }


for portfolio in Portfolio.all(conn):
    projects = []
    for project in portfolio.projects():
        tasks = [dict_for_task(t) for t in project.tasks()]

        project_info = dict_for_project(project)
Exemplo n.º 16
0
 def tasks(self, sort_by=None):
     return Task.all(conn(), sort_by)
Exemplo n.º 17
0
def task_command(
    name=None,  # The name for this task
    context=None,  # The @context in which task can be done
    complete=False,  # Whether task is already complete.
    p=-1,  # project id this task is part of
    r=-1,  # recipe this task corresponds to
    description="",  # optional longer description for this task
    due=-1,  # due date in YYYY-MM-DD format
    estimate=-1,  # estimate of time this will take, in minutes
    waiting=-1,  # the id of another task that must be completed first
    worktype="adhoc",  # type of work this is
):
    """
    Create a new task.
    """
    c = conn()

    if due > 0:
        if re.match("[0-9]{4}-[0-9]{2}-[0-9]{2}", due):
            f = "%Y-%m-%d"
            due_at = datetime.strptime(due, f)
        else:
            raise Exception("I don't know how to parse dates like %s" % due)
    else:
        due_at = None

    if estimate < 0:
        estimate = None

    if setting("enforce-worktypes") and not worktype in setting("worktypes"):
        raise Exception("Acceptable worktypes are %s" % ", ".join(setting("worktypes")))

    if setting("enforce-worktypes") and worktype == "maintenance" and r < 0:
        raise Exception("You must specify a recipe in order to designate a task as 'maintenance'")

    if waiting > 0:
        waiting_for_task = Task.get(c, waiting)
        waiting_for_task_id = waiting_for_task.id
        if p < 0:
            # Get the project id based on the task we are waiting for.
            project_id = waiting_for_task.project_id
        else:
            project_id = p
    else:
        waiting_for_task_id = None
        if p > 0:
            project_id = p
        else:
            print "putting new task into inbox"
            project_id = None

    if complete:
        completed_at = datetime.now()
    else:
        completed_at = None

    task = Task.create(
        c,
        due_at=due_at,
        name=name,
        context=context,
        description=description,
        estimate=estimate,
        project_id=project_id,
        worktype=worktype,
        waiting_for_task_id=waiting_for_task_id,
        created_at=datetime.now(),
        completed_at=completed_at,
    )
    print "Created task", task.id