<s> import logging <EOL> import collections <EOL> import datetime as dt <EOL> import flask <EOL> from kozmic import docker <EOL> logger = logging . getLogger ( __name__ ) <EOL> def clean_dependencies_cache ( verbose = True ) : <EOL> images_by_projects = collections . defaultdict ( list ) <EOL> limit = flask . current_app . config [ '<STR_LIT>' ] <EOL> for image_data in docker . images ( ) : <EOL> created_at = image_data [ '<STR_LIT>' ] <EOL> for repo_tag in image_data [ '<STR_LIT>' ] : <EOL> if not repo_tag . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> try : <EOL> repository , tag = repo_tag . split ( '<STR_LIT::>' ) <EOL> except ValueError : <EOL> continue <EOL> try : <EOL> project_id = int ( tag ) <EOL> except ValueError : <EOL> continue <EOL> images_by_projects [ project_id ] . append ( ( created_at , image_data [ '<STR_LIT>' ] ) ) <EOL> break <EOL> for project_id , timestamped_images in images_by_projects . iteritems ( ) : <EOL> images_to_remove = [ image for _ , image in <EOL> sorted ( timestamped_images ) [ : - limit ] ] <EOL> for image in images_to_remove : <EOL> docker . remove_image ( image ) <EOL> logger . info ( '<STR_LIT>' , image ) </s>
