#NEWLINE# def delete( self , path , recursive = False ) : #NEWLINE# #INDENT# 'Deletes a node (optionally its children) from this filesystem.' #NEWLINE# path = self . normpath ( path ) #NEWLINE# node = self . _fetch_node ( path , normalized = True ) #NEWLINE# if ( ( node is self . _root ) and ( not recursive ) ) : #NEWLINE# #INDENT# raise ValueError ( ( "Can not delete '%s'" % self . _root . item ) ) #NEWLINE# #UNINDENT# if recursive : #NEWLINE# #INDENT# child_paths = ( child . metadata [ 'path' ] for child in node . bfs_iter ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# node_child_count = node . child_count ( ) #NEWLINE# if node_child_count : #NEWLINE# #INDENT# raise ValueError ( ( "Can not delete '%s', it has %s children" % ( path , node_child_count ) ) ) #NEWLINE# #UNINDENT# child_paths = [ ] #NEWLINE# #UNINDENT# if ( node is self . _root ) : #NEWLINE# #INDENT# paths = child_paths #NEWLINE# drop_nodes = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# paths = itertools . chain ( [ path ] , child_paths ) #NEWLINE# drop_nodes = [ node ] #NEWLINE# #UNINDENT# for path in paths : #NEWLINE# #INDENT# self . _reverse_mapping . pop ( path , None ) #NEWLINE# #UNINDENT# for node in drop_nodes : #NEWLINE# #INDENT# node . disassociate ( )