<s> import re <EOL> from os import listdir <EOL> from os . path import join , isdir , split <EOL> from . utils import get_dvar <EOL> def _walk ( root , top , ignore_files = None , ignore_dirs = None ) : <EOL> dirs_to_visit = [ ] <EOL> try : <EOL> dir_list = sorted ( listdir ( join ( root , top ) ) , key = lambda r : ( len ( r ) , r ) ) <EOL> except OSError : <EOL> pass <EOL> else : <EOL> for name in dir_list : <EOL> path = join ( top , name ) <EOL> fullpath = join ( root , top , name ) <EOL> if isdir ( fullpath ) : <EOL> if not ignore_dirs or not ignore_dirs . match ( path ) : <EOL> dirs_to_visit . append ( path ) <EOL> else : <EOL> if not ignore_files or not ignore_files . match ( path ) : <EOL> yield name , path , root , top , fullpath <EOL> for path in dirs_to_visit : <EOL> for p in _walk ( root , path , ignore_files , ignore_dirs ) : <EOL> yield p <EOL> def get_files ( root , cache = None , keep_top = False ) : <EOL> if cache is not None : <EOL> try : <EOL> return cache [ root ] <EOL> except KeyError : <EOL> pass <EOL> ignore_files = re . compile ( '<STR_LIT>' . format ( <EOL> '<STR_LIT:|>' . join ( r'<STR_LIT>' . format ( r ) <EOL> for r in get_dvar ( '<STR_LIT>' ) ) ) ) <EOL> ignore_dirs = re . compile ( '<STR_LIT>' . format ( '<STR_LIT:|>' . join ( <EOL> get_dvar ( '<STR_LIT>' ) ) ) ) <EOL> fcache = [ ] <EOL> if keep_top : <EOL> root , top = split ( root ) <EOL> else : <EOL> root , top = root , '<STR_LIT>' <EOL> def filler ( ) : <EOL> for r in _walk ( root , top , ignore_files , ignore_dirs ) : <EOL> fcache . append ( r ) <EOL> yield r <EOL> if cache is not None : <EOL> cache [ root ] = fcache <EOL> return filler ( ) </s>
