def create_directory_children(dirs, parent): '''Create the following relationship: (p:Directory)<-[:PARENT]-(d:Directory) where dirs is a list of strings and parent is a py2neo node.''' batch = WriteBatch(graph_db) for d in dirs: dir_node = batch.create({'name': d, '_id': uuid.uuid4().hex}) batch.add_labels(dir_node, "Directory") batch.create(rel(dir_node, "PARENT", parent)) batch.run()
def create_file_children(files, parent, root_path): '''Create (p:Directory)<-{:PARENT]-(f:File) for all files to the given parent. Also stores the file's contents in the content property.''' batch = WriteBatch(graph_db) for f in files: file_content = get_file_content(f, root_path) file_node = batch.create({'name': f, '_id': uuid.uuid4().hex, 'content': file_content}) batch.add_labels(file_node, 'File') batch.create(rel(file_node, "PARENT", parent)) batch.run()