def invalidate_caches(distribution_ids, paths_list, wait_to_complete=False): """ Create and optionally wait for CloudFront cache invalidation for given paths :param distribution_ids: list of CloudFront distribution ids :param paths_list: list of paths to invalidate :param wait_to_complete: if true, waits for cache invalidation [default: false] :return: dict of distribution id: Invalidation record """ client = useboto.get_boto3_client('cloudfront') if not funcy.is_list(distribution_ids): distribution_ids = (distribution_ids, ) invalidate_requests = {} for dist_id in distribution_ids: logger.info("Creating cache invalidation for distribution %s", dist_id) response = client.create_invalidation( DistributionId=dist_id, InvalidationBatch=dict(Paths=dict(Quantity=len(paths_list), Items=paths_list), CallerReference=unique_string(dist_id))) invalidate_requests[dist_id] = response if wait_to_complete: waiter = client.get_waiter('invalidation_completed') for dist_id, invalidate_response in invalidate_requests.iteritems(): logger.info( "Waiting for cache invalidation to finish for distribution %s", dist_id) invalidation_id = invalidate_response['Invalidation']['Id'] waiter.wait(DistributionId=dist_id, Id=invalidation_id) invalidate_requests[dist_id] = client.get_invalidation( DistributionId=dist_id, Id=invalidation_id) return invalidate_requests
def parse_value(value, grammar_path, context, render_strategy=texts.render_ftemplate): if is_list(value): mode, value = get_list_setting(value, grammar_path) if mode == "reuse": return db.Database( db.choose([ parse_value(v, grammar_path, context, render_strategy=render_strategy) for v in value ]), grammar_path, context, ) elif mode == "pick": return db.Database( db.pick([ parse_value(v, grammar_path, context, render_strategy=render_strategy) for v in value ]), grammar_path, context, ) elif mode == "markov": return db.Database( db.markovify([texts.RenderedStr(v) for v in value]), grammar_path, context, ) elif mode == "ratchet": return db.Database( db.ratchet([texts.RenderedStr(v) for v in value]), grammar_path, context) elif mode == "list": return db.Datalist(grammar_path, context, [texts.RenderedStr(v) for v in value]) elif is_mapping(value): return db.Databag( grammar_path, context, { k: parse_value( v, grammar_path, context, render_strategy=render_strategy) for k, v in value.items() }, ) elif is_bool(value): return value else: return texts.RenderableText(fix_text(value), grammar_path, context, render_strategy=render_strategy)
def setup(cmd_args, suppress_output=False): """ Call a setup.py command or list of commands >>> result = setup('--name', suppress_output=True) >>> result.exitval 0 >>> result = setup('notreal') >>> result.exitval 1 """ if not funcy.is_list(cmd_args) and not funcy.is_tuple(cmd_args): cmd_args = shlex.split(cmd_args) cmd_args = [sys.executable, 'setup.py'] + [x for x in cmd_args] return call(cmd_args, suppress_output=suppress_output)
def task_test(args): suppress_output = not args['--stream-command-output'] workdir.sync() with workdir.as_cwd(): config_dict = _get_config_or_die(calling_task='test', required_params=['test_command']) test_commands = config_dict['test_command'] if not funcy.is_list(test_commands): test_commands = [test_commands] for cmd_str in test_commands: result = executor.call(cmd_str, suppress_output=suppress_output) if result.exitval: _log_failure_and_die('tests failed', result, log_full_result=suppress_output) logger.info('testing completed successfully')
def handle_item(item, env, context): root = {"linkId": item["linkId"]} if "text" in item: root["text"] = item["text"] if "itemContext" in item: data = fhirpath(context, item["itemContext"]["expression"], env) context = data if (context and "initialExpression" in item and "repeats" in item and item["repeats"] is True): answers = [] root["answer"] = answers for index, _item in enumerate(context): type = get_type(item) data = fhirpath( context, "%context[{}].{}".format( index, item["initialExpression"]["expression"]), env, ) answers.append({"value": {item["type"]: data[0]}}) elif "initialExpression" in item: data = fhirpath(context, item["initialExpression"]["expression"], env) if data and len(data): type = get_type(item) if item.get("repeats") is True: root["answer"] = [{"value": {type: d}} for d in data] else: root["answer"] = [{"value": {type: data[0]}}] elif "initial" in item: root["answer"] = item["initial"] if (item["type"] == "group" and "repeats" in item and item["repeats"] is True and is_list(context)): answer = [] for c in context: q = [] for i in item["item"]: q.append(handle_item(i, env, c)) answer.append({"item": q}) root["answer"] = answer elif "item" in item: root["item"] = [] for i in item["item"]: root["item"].append(handle_item(i, env, context)) return root
def call(cmd_args, suppress_output=False): """ Call an arbitary command and return the exit value, stdout, and stderr as a tuple Command can be passed in as either a string or iterable >>> result = call('hatchery', suppress_output=True) >>> result.exitval 0 >>> result = call(['hatchery', 'notreal']) >>> result.exitval 1 """ if not funcy.is_list(cmd_args) and not funcy.is_tuple(cmd_args): cmd_args = shlex.split(cmd_args) logger.info('executing `{}`'.format(' '.join(cmd_args))) call_request = CallRequest(cmd_args, suppress_output=suppress_output) call_result = call_request.run() if call_result.exitval: logger.error('`{}` returned error code {}'.format(' '.join(cmd_args), call_result.exitval)) return call_result
def _match(node): # Check if any potential fails here next_potential = [] for p in potential: if stack[:len(p['stack'])] != p['stack']: # Potential match can't fail matches.append(p) else: path = stack[len(p['stack']):] sub_template = get_sub_template(template, path) if node_matches(node, sub_template, p['context']): next_potential.append(p) potential[:] = next_potential # Check if template starts here context = {'names': {}, 'rev': {}, 'captures': {}} if node_matches(node, template, context): # potential.append((stack[:], node[0])) potential.append({ 'stack': stack[:], # Always refer to a first node even when template is a list 'node': node[0] if is_list(node) else node, 'context': context, }) # Go deeper if isinstance(node, ast.AST): for name, value in ast.iter_fields(node): stack.append(name) _match(value) stack.pop() elif isinstance(node, list) and node: # NOTE: we treat lists as recursive data structures here. # 0 means go to list head, 1 to tail. stack.append(0) _match(node[0]) stack.pop() stack.append(1) _match(node[1:]) stack.pop()
def handle_item(item, env, context): def init_item(): new_item = {"linkId": item["linkId"]} if "text" in item: new_item["text"] = item["text"] return new_item if "itemContext" in item: context = fhirpath(context, item["itemContext"]["expression"], env) if "itemPopulationContext" in item: context = fhirpath(context, item["itemPopulationContext"]["expression"], env) if (item["type"] == "group" and item.get("repeats", False) is True and is_list(context)): root_items = [] for c in context: populated_items = [] for i in item["item"]: populated_items.extend(handle_item(i, env, c)) root_item = init_item() root_item["item"] = populated_items root_items.append(root_item) return root_items root_item = init_item() if context and "initialExpression" in item and item.get("repeats", False) is True: answers = [] for index, _item in enumerate(context): data = fhirpath( context, "%context[{}].{}".format( index, item["initialExpression"]["expression"]), env, ) if data and len(data): type = get_type(item, data) answers.extend([{"value": {type: d}} for d in data]) if answers: root_item["answer"] = answers elif "initialExpression" in item: answers = [] data = fhirpath(context, item["initialExpression"]["expression"], env) if data and len(data): type = get_type(item, data) if item.get("repeats") is True: answers = [{"value": {type: d}} for d in data] else: answers = [{"value": {type: data[0]}}] if answers: root_item["answer"] = answers elif "initial" in item: root_item["answer"] = item["initial"] if "item" in item: populated_items = [] for i in item["item"]: populated_items.extend(handle_item(i, env, context)) root_item["item"] = populated_items return [root_item]