#NEWLINE# def select_files_from_tree( file_tree ) : #NEWLINE# #INDENT# '\n    Select a file from every depth of a file_tree. This implementation relies on:\n      - every folder has a subtree of equal depth (i.e. any folder selection is\n      adequate to select a file from the maximum depth)\n    The file_tree_factory fulfills this condition.\n    ' #NEWLINE# selected = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# stack = [ file_tree ] #NEWLINE# while len ( stack ) : #NEWLINE# #INDENT# file_node = stack . pop ( 0 ) #NEWLINE# target_files = [ f for f in file_node [ 'children' ] if ( f [ 'kind' ] == 'file' ) ] #NEWLINE# if target_files : #NEWLINE# #INDENT# target_file = target_files [ 0 ] #NEWLINE# selected [ target_file [ 'extra' ] [ 'hashes' ] [ 'sha256' ] ] = target_file #NEWLINE# #UNINDENT# target_folders = [ f for f in file_node [ 'children' ] if ( f [ 'kind' ] == 'folder' ) ] #NEWLINE# if target_folders : #NEWLINE# #INDENT# stack . append ( target_folders [ 0 ] ) #NEWLINE# #UNINDENT# #UNINDENT# return selected