def resman(): """Create a recipe manager.""" man = RecipeManager() man.add_recipe_folder( os.path.join(os.path.dirname(__file__), 'test_recipes')) # includes recipe.yaml return man
def test_recipe_manager_import(): rm = RecipeManager() assert rm.is_valid_action('WaitStep') assert rm.is_valid_action('PromptStep') rm.add_recipe_folder(os.path.join(os.path.dirname(__file__), 'test_recipes')) # includes recipe.yaml assert rm.is_valid_recipe('test_basic_recipe')
def main(argv=None): """Main entry point for iotile-ship recipe runner. This is the iotile-ship command line program. Args: argv (list of str): An optional set of command line parameters. If not passed, these are taken from sys.argv. """ if argv is None: argv = sys.argv[1:] parser = build_args() args = parser.parse_args(args=argv) recipe_name, _ext = os.path.splitext(os.path.basename(args.recipe)) rm = RecipeManager() rm.add_recipe_folder(os.path.dirname(args.recipe), whitelist=[os.path.basename(args.recipe)]) recipe = rm.get_recipe(recipe_name) if args.archive is not None: print("Archiving recipe into %s" % args.archive) recipe.archive(args.archive) return 0 if args.info: print(recipe) return 0 variables = load_variables(args.define, args.config) success = 0 start_time = time.time() if args.loop is None: try: recipe.run(variables) success += 1 except IOTileException as exc: print("Error running recipe: %s" % str(exc)) return 1 else: while True: value = input( "Enter value for loop variable %s (return to stop): " % args.loop) if value == '': break local_vars = dict(**variables) local_vars[args.loop] = value try: recipe.run(local_vars) success += 1 except IOTileException as exc: print("--> ERROR processing loop variable %s: %s" % (value, str(exc))) end_time = time.time() total_time = end_time - start_time if success == 0: per_time = 0.0 else: per_time = total_time / success print("Performed %d runs in %.1f seconds (%.1f seconds / run)" % (success, total_time, per_time)) return 0