def recipe_handler(args, remainder, config): """Runs recipes. All functionality remains the same as the deprecated adr.cli:cli. :param Namespace args: Namespace object produced by main(). :param Configuration config: Config objects :param list remainder: List of unknown arguments. """ recipes = [os.path.splitext(item)[0] for item in os.listdir( RECIPE_DIR) if item != '__init__.py' and item.endswith('.py')] _set_logging_verbosity(config.verbose) if args.list: _list(recipes) else: _check_tasks_exist(args.task) if len(args.task) == 2 and args.task[1] == '--help': print('Usage for adr ' + args.task[0] + ':') run_recipe(args.task[0], [args.task[1]], config) sys.exit() for recipe in args.task: if recipe not in recipes: log.error("recipe '{}' not found!".format(recipe)) continue print(run_recipe(recipe, remainder, config))
def _help(items, request_list, config, parser, request_type): if len(items) == 0: parser.print_help() else: for request in items: if request not in request_list: log.error("{} '{}' not found!".format(request_type, request)) continue if request_type == "recipe": print('Usage for adr ' + request + ':') run_recipe(request, ['--help'], config) else: print('Usage for adr query ' + request + ':') format_query(request, config, ['--help']) return
def recipe_handler(args, remainder): """Runs recipes. All functionality remains the same as the deprecated adr.cli:cli. :param Namespace args: Namespace object produced by main(). :param list remainder: List of unknown arguments. """ recipes = [ os.path.splitext(item)[0] for item in os.listdir(RECIPE_DIR) if item != '__init__.py' and item.endswith('.py') ] _set_logging_verbosity(args.verbose) if args.list: _list(recipes) else: _check_tasks_exist(args.task) for recipe in args.task: if recipe not in recipes: log.error("recipe '{}' not found!".format(recipe)) continue print(run_recipe(recipe, remainder, fmt=args.fmt))
def runrecipe(recipename): """ :param list recipename:the name of the selected recipe file :returns: template """ config.fmt = 'markdown' result_md = run_recipe(recipename, [], config) table_html = markdown.markdown(result_md, extensions=['markdown.extensions.tables']) return render_template('home.html', recipes=recipe_names, format=Markup(table_html))
def handle_recipe(remainder): if config.recipe not in sources.recipes: logger.error(f"recipe '{config.recipe}' not found!") return data = run_recipe(config.recipe, remainder) if config.output_file: print(data, file=open(config.output_file, "w")) return data
def handle_recipe(remainder): if config.recipe not in get_recipes(): log.error("recipe '{}' not found!".format(config.recipe)) return data = run_recipe(config.recipe, remainder) if config.output_file: print(data, file=open(config.output_file, 'w')) return data
def format_request(request, config, remainder, request_type): if request_type == "query": data, url = format_query(request, config, remainder) else: data = run_recipe(request, remainder, config) url = None if config.output_file: print(data, file=open(config.output_file, 'w')) return data, url
def run_recipe(recipe_name, request, fmt='json'): recipe_contexts = recipe.get_recipe_contexts(recipe_name) args = request.args.to_dict(flat=True) for key, value in recipe_contexts.items(): if "default" in value[1]: args.setdefault(key, value[1]["default"]) for key, value in args.items(): context = recipe_contexts[key][1] if context.get('type') == 'number': args[key] = int(value) config.fmt = fmt return recipe.run_recipe(recipe_name, args, False)
def cli(args=sys.argv[1:]): parser = ArgumentParser() parser.add_argument("recipe", help="Recipe to generate test for") args, remainder = parser.parse_known_args(args) orig_run_query = query.run_query query_results = [] def new_run_query(name, args): args.limit = 10 result = orig_run_query(name, args) mock_result = deepcopy(result) mock_result.pop("meta") query_results.append(mock_result) return result query.run_query = new_run_query config.set(fmt="json") config.set(recipe=args.recipe) result = run_recipe(args.recipe, remainder) test = OrderedDict() test["recipe"] = args.recipe test["args"] = remainder test["queries"] = query_results test["expected"] = json.loads(result) # get pyyaml to preserve ordering of dict keys def represent_ordereddict(dumper, data): value = [] for item_key, item_value in data.items(): node_key = dumper.represent_data(item_key) node_value = dumper.represent_data(item_value) value.append((node_key, node_value)) return yaml.nodes.MappingNode(u"tag:yaml.org,2002:map", value) yaml.add_representer(OrderedDict, represent_ordereddict) test_dir = sources.active_source.recipe_dir.parent / "test" / "recipe_tests" if not test_dir.is_dir(): os.makedirs(test_dir) path = os.path.join(test_dir, "{}.test".format(args.recipe)) with open(path, "a") as fh: yaml.dump(test, fh)
def cli(args=sys.argv[1:]): parser = ArgumentParser() parser.add_argument('recipe', help='Recipe to generate test for') args, remainder = parser.parse_known_args(args) orig_run_query = query.run_query query_results = [] def new_run_query(name, config, **context): context['limit'] = 10 qgen = orig_run_query(name, config, **context) for result in qgen: mock_result = deepcopy(result) mock_result.pop('meta') query_results.append(mock_result) yield result query.run_query = new_run_query cfg = Configuration(os.path.join(os.path.dirname(here), 'config.yml')) cfg.fmt = 'json' result = run_recipe(args.recipe, remainder, cfg) test = OrderedDict() test['recipe'] = args.recipe test['args'] = remainder test['queries'] = query_results test['expected'] = json.loads(result) # get pyyaml to preserve ordering of dict keys def represent_ordereddict(dumper, data): value = [] for item_key, item_value in data.items(): node_key = dumper.represent_data(item_key) node_value = dumper.represent_data(item_value) value.append((node_key, node_value)) return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value) yaml.add_representer(OrderedDict, represent_ordereddict) path = os.path.join(test_dir, '{}.test'.format(args.recipe)) with open(path, 'a') as fh: yaml.dump(test, fh)