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
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
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"
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