def interpolated_pub_handler(publisher, parameters, state): forinterp = parameters.copy().typed() result = copy.deepcopy(publisher["publish"]) for path, value in utils.leaf_iterator(publisher["publish"]): if not isinstance(value, string_types): continue if isinstance(forinterp, dict): resultval = value.format(workdir=state.readwrite[0], **forinterp) elif isinstance(forinterp, list): resultval = value.format(workdir=state.readwrite[0], *forinterp) else: resultval = value.format(workdir=state.readwrite[0], value=forinterp) globexpr = resultval if (publisher["relative_paths"] and os.path.commonprefix( [state.readwrite[0], globexpr]) == ""): globexpr = os.path.join(state.readwrite[0], resultval) if publisher["glob"]: globbed = glob2.glob(globexpr) if globbed: resultval = globbed else: # if it's a string and the full path exists replace relative path resultval = globexpr if path.path == "": # there can only ever be a single root leaf return resultval path.set(result, resultval) return result
def interpolated_pub_handler(publisher, attributes, context): forinterp = attributes.copy() forinterp.update(workdir=context['readwrite'][0]) result = copy.deepcopy(publisher['publish']) for path, value in utils.leaf_iterator(publisher['publish']): resultval = value.format(**forinterp) resultval = glob2.glob(resultval) path.set(result, resultval) return result
def test_leafit(): testdata = { 'hello':'world', 'deeply':{ 'nested':['l','i'], 'numbers':123 }, 'bool': True } leafs = set([(x.path,y) for x,y in leaf_iterator(testdata)]) assert leafs == { ('/deeply/nested/0','l'), ('/deeply/nested/1','i'), ('/deeply/numbers',123), ('/hello','world'), ('/bool',True), }
def interpolated_pub_handler(publisher, parameters, state): workdir = state.local_workdir forinterp = {} for p, v in parameters.leafs(): if isinstance(v, yadageobjstore.known_types.SimpleFile): continue p.set(forinterp, v) log.info('interpolation dict: %s', forinterp) result = copy.deepcopy(publisher['publish']) for path, value in leaf_iterator(publisher['publish']): if not isinstance(value, string_types): continue resultval = value.format(**forinterp) resultval = resultval.format(workdir=workdir) globexpr = resultval log.info('value: %s | expression %s', value, globexpr) if publisher['relative_paths'] and os.path.commonprefix( [workdir, globexpr]) == '': globexpr = os.path.join(workdir, resultval) if publisher['glob']: globbed = glob2.glob(globexpr) if globbed: resultval = [ yadageobjstore.known_types.SimpleFile(local_path=p) for p in globbed ] else: #if it's a string and the full path exists replace relative path resultval = yadageobjstore.known_types.SimpleFile( local_path=globexpr) log.info('result value: %s', resultval) path.set(result, resultval) log.info('returning result: %s', result) return TypedLeafs(result, state.datamodel)
def process_attr_pub_handler(publisher, attributes, context): outputs = copy.deepcopy(publisher['outputmap']) for path, value in utils.leaf_iterator(publisher['outputmap']): actualval = attributes[value] path.set(outputs, actualval) return outputs
def finalize_input(jsondata, context): for path, value in utils.leaf_iterator(jsondata): actualval = statecontext.contextualize_data(value, context) path.set(jsondata, actualval) return jsondata
def process_attr_pub_handler(publisher, parameters, state): outputs = copy.deepcopy(publisher["outputmap"]) for path, value in utils.leaf_iterator(publisher["outputmap"]): actualval = parameters[value] path.set(outputs, actualval) return outputs