Beispiel #1
0
def do_command(r=False):
    """
    Do a recipe.
    """
    c = ado.commands.conn()
    if not r:
        Recipe.printall(c)
        raw_r = ado.commands.clean_input("Choose a recipe number: ")
        if raw_r:
            r = int(raw_r)
        else:
            sys.stderr.write("No recipe chosen.\n")
            sys.exit(1)

    print "You chose recipe '%s'" % r
    recipe = Recipe.get(c, r)
    print recipe.description

    doing = DoingRecipe.create(
            c,
            started_at = datetime.now(),
            recipe_id=recipe.id)

    for i, step in enumerate(recipe.steps()):
        started_at = datetime.now()
        print "Step %s) %s" % (i+1, step.description)
        description = ado.commands.clean_input("notes> ")
        completed_at = datetime.now()
        elapsed = completed_at - started_at
        print "Completed Step %s in %s" % (i+1, elapsed)
        DoingStep.create(c,
                started_at = started_at,
                completed_at = completed_at,
                step_description = step.description,
                description = description,
                step_id = step.id,
                doing_recipe_id = doing.id)