def _helper(root_directory, current_directory, meta_data_tree, visited_info_file_set): info_file_path = get_info_file(current_directory) if info_file_path in visited_info_file_set: msg = "Info file '{info_file_path}' has already been visited and will be skipped, this is indicative of a path or symlink loop" logging.warning(msg.format(info_file_path=info_file_path)) return info = parse_yaml_info_file(info_file_path) visited_info_file_set.add(info_file_path) for item_file_name, item_meta_data in info.items(): item_file_path = join_and_normalize(current_directory, item_file_name) raise_if_not_exist(item_file_path) if os.path.isdir(item_file_path): _helper(root_directory, item_file_path, meta_data_tree, visited_info_file_set) elif os.path.isfile(item_file_path): pass else: msg = "Path '{item_file_path}' is neither a file, a directory, nor a symlink to a file/directory and will be skipped" logging.warning(msg.format(item_file_path=item_file_path)) continue pp = get_path_parts_after_prefix(item_file_path, root_directory) node = get_node(meta_data_tree, *pp) if item_meta_data is None: node.metadata = {} else: node.metadata.update(item_meta_data)
def index_children(meta_tree, field_name, *key_trail): def _helper(node, field_name): meta_data = node.metadata if field_name in meta_data: return listify(meta_data[field_name]) else: child_agg = None for key in node.keys(): child_ret = _helper(node[key], field_name) if child_ret is not None: if child_agg is None: child_agg = [] child_agg += child_ret return listify(child_agg) node = get_node(meta_tree, *key_trail) ret = None for key in node.keys(): child_agg = _helper(node[key], field_name) if child_agg is not None: if ret is None: ret = [] ret += child_agg return listify(ret)