示例#1
0
文件: __init__.py 项目: ananelson/ado
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!")
示例#2
0
文件: __init__.py 项目: ananelson/ado
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
示例#3
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
示例#4
0
文件: __init__.py 项目: ananelson/ado
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()
示例#5
0
文件: __init__.py 项目: ananelson/ado
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.")
示例#6
0
文件: __init__.py 项目: ananelson/ado
def tasktime_command(t=None):
    c = conn()
    task = Task.get(c, t)
    print task.total_time(c)
示例#7
0
文件: __init__.py 项目: ananelson/ado
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