Exemple #1
0
def time_command(t=-1, description=""):
    """
    Starts a timer, optionally give a description and specify the task id you are working on.
    """
    c = conn()
    active_timers = Timer.active_timers(c)
    if len(active_timers) > 0:
        # List the existing timer(s) and show elapsed times
        for timer in active_timers:
            if timer.description:
                description = timer.description
            else:
                description = ""

            if timer.task_id:
                task_id = "Task %4d." % timer.task_id
            else:
                task_id = "No task assigned."
            print "Timer %04d.    %s   %s %s" % (timer.id, timer.elapsed_time(), task_id, description)
    else:
        # Create a new timer.
        if t > 0:
            task_id = t
        else:
            task_id = None

        if len(description) == 0:
            description = None

        if not description and not task_id:
            print "No active timers. To create a new timer please specify either a description or a task id."
        else:
            time = Timer.create(c, task_id=task_id, description=description, started_at=datetime.now())
            print "Timer %s Started" % time.id
Exemple #2
0
def stop_command(t=-1):
    c = conn()
    if t > 0:
        # stop the particular timer specified
        timers = [t]
    else:
        # stop all timers (there's probably just 1)
        timers = Timer.active_timers(c)

    if len(timers) == 0:
        print "No timers running."

    for timer in timers:
        Timer.stop(c, timer.id)
        print "Stopped timer %04d total time %s" % (timer.id, timer.elapsed_time())
Exemple #3
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"