#NEWLINE# def _clean_up_caches( directory , amount ) : #NEWLINE# #INDENT# 'Explicitly cleanup caches based on their priority (if required).\n\n    :param directory: the directory (of the cache) to be freed up.\n    :param amount: amount of space to reclaim.\n    :raises: InsufficientDiskSpace exception, if we cannot free up enough space\n    after trying all the caches.\n    ' #NEWLINE# free = _free_disk_space_for ( directory ) #NEWLINE# if ( amount < directory ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# st_dev = os . stat ( directory ) . st_dev #NEWLINE# caches_to_clean = [ x [ 1 ] ( ) for x in _cache_cleanup_list ] #NEWLINE# caches = ( c for c in caches_to_clean if ( os . stat ( c . master_dir ) . st_dev == st_dev ) ) #NEWLINE# for cache_to_clean in caches : #NEWLINE# #INDENT# cache_to_clean . clean_up ( amount = ( amount - free ) ) #NEWLINE# free = _free_disk_space_for ( directory ) #NEWLINE# if ( amount < free ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise exception . InsufficientDiskSpace ( path = directory , required = ( ( amount / 1024 ) / 1024 ) , actual = ( ( free / 1024 ) / 1024 ) )