예제 #1
0
 def do_playrecipe(self, line):
   try:
     if not os.path.exists(self.recipe_directory):
       raise ValueError("Recipe directory points to an invalid location")
     abs_filename = os.path.join(self.recipe_directory, line.strip().lower())
     f = open(abs_filename, "r")
     recipe = Recipe(json_string=f.read())
     f.close()
     print "This recipe will take " + str(datetime.timedelta(seconds=recipe.get_total_time())) + " secs"
     sous_chef = SousChef(utensil_index=recipe.utensil_size)
     for step in recipe.steps:
       if step.name == "lid":
         if step.step_args[0] == 'open':
           sous_chef.open_lid()
         elif step.step_args[0] == 'close':
           sous_chef.close_lid()
         else:
           raise ValueError("Invalid Recipe. Options to lid must be one of {open, close}. ")
       elif step.name == "addwater":
         sous_chef.add_water_in_cups(step.step_args[0])
       elif step.name == "addoil":
         sous_chef.add_oil_in_tbsp(step.step_args[0])
       elif step.name == "stir":
         if step.step_args[0] == "circular":
           sous_chef.stir_circular(step.step_args[1], step.step_args[2], step.step_args[3])
         elif step.step_args[0] == "linear":
           sous_chef.stir_linear(step.step_args[1], step.step_args[2])
         else:
           raise ValueError("Invalid stir type" + step.step_args[0])
       elif step.name == "temp":
         sous_chef.set_temperature_in_celcius(step.step_args[0])
       elif step.name == "knobpos":
         sous_chef.set_knobpos(step.step_args[0])
       elif step.name == "addcup":
         sous_chef.add_cup(step.step_args[0])
       elif step.name == "delay":
         time.sleep(step.step_args[0])
       elif step.name == "done":
         sous_chef.shutdown()
       else:
         raise ValueError("Invalid step in recipe:" + step.name)
   except Exception, e:
     print "Error:" + str(e)
예제 #2
0
class MakeRecipeCommand(cmd.Cmd):
  def __init__(self, prompt, utensil_size,
               recipe_name, recipe_storage_location):
    cmd.Cmd.__init__(self)
    self.prompt = prompt
    self.ruler = '='
    self.recipe_storage_location = recipe_storage_location
    self.recipe = Recipe(utensil_size, recipe_name.strip())
    self.sous_chef = SousChef(utensil_index=utensil_size)
    self.intro = """    You are now in the recipe maker. Type help to get all
    the available commands. Use help <command> to get help about
    a specific command. All the commands that are SUCCESSFULLY
    executed on SousChef are also logged into the recipe.
    Use the 'done' command when you're done to save the recipe
    and exit out of the recipe maker mode."""

    if not os.path.isdir(self.recipe_storage_location):
      raise ValueError("Recipe storage location needs to be a directory:" + self.recipe_storage_location)

  ## Command definitions ##
  def do_hist(self, args):
    """Print a list of commands that have been entered"""
    print self._hist

  def preloop(self):
    """Initialization before prompting user for commands.
       Despite the claims in the Cmd documentaion, Cmd.preloop() is not a stub.
    """
    cmd.Cmd.preloop(self)   ## sets up command completion
    self._hist    = []      ## No history yet
    self._locals  = {}      ## Initialize execution namespace for user
    self._globals = {}
    self.start_time = get_curr_time_in_secs()
    self.previous_time = get_curr_time_in_secs()

  def add_time_step_to_recipe(self):
    curr_time = get_curr_time_in_secs()
    time_delta = curr_time - self.previous_time
    self.previous_time = curr_time
    self.recipe.add_step(Step("delay", [time_delta]))

  def do_name(self, line):
    recipe_name = string.capwords(line.strip())
    self.recipe.set_name(recipe_name)

  def help_name(self):
    print """ Command to set the name of the recipe """

  def do_utensil(self, line):
    try:
      utensil_size = int(line)
      self.recipe.set_utensil_size(utensil_size)
    except Exception, e:
      print "Error:" + str(e)
예제 #3
0
  def __init__(self, prompt, utensil_size,
               recipe_name, recipe_storage_location):
    cmd.Cmd.__init__(self)
    self.prompt = prompt
    self.ruler = '='
    self.recipe_storage_location = recipe_storage_location
    self.recipe = Recipe(utensil_size, recipe_name.strip())
    self.sous_chef = SousChef(utensil_index=utensil_size)
    self.intro = """    You are now in the recipe maker. Type help to get all
    the available commands. Use help <command> to get help about
    a specific command. All the commands that are SUCCESSFULLY
    executed on SousChef are also logged into the recipe.
    Use the 'done' command when you're done to save the recipe
    and exit out of the recipe maker mode."""

    if not os.path.isdir(self.recipe_storage_location):
      raise ValueError("Recipe storage location needs to be a directory:" + self.recipe_storage_location)