#NEWLINE# def clean_source_index( self ) : #NEWLINE# #INDENT# "\n        Cleanup broken symbolic links in the local source distribution index.\n\n        The purpose of this method requires some context to understand. Let me\n        preface this by stating that I realize I'm probably overcomplicating\n        things, but I like to preserve forward / backward compatibility when\n        possible and I don't feel like dropping everyone's locally cached\n        source distribution archives without a good reason to do so. With that\n        out of the way:\n\n        - Versions of pip-accel based on pip 1.4.x maintained a local source\n          distribution index based on a directory containing symbolic links\n          pointing directly into pip's download cache. When files were removed\n          from pip's download cache, broken symbolic links remained in\n          pip-accel's local source distribution index directory. This resulted\n          in very confusing error messages. To avoid this\n          :func:`clean_source_index()` cleaned up broken symbolic links\n          whenever pip-accel was about to invoke pip.\n\n        - More recent versions of pip (6.x) no longer support the same style of\n          download cache that contains source distribution archives that can be\n          re-used directly by pip-accel. To cope with the changes in pip 6.x\n          new versions of pip-accel tell pip to download source distribution\n          archives directly into the local source distribution index directory\n          maintained by pip-accel.\n\n        - It is very reasonable for users of pip-accel to have multiple\n          versions of pip-accel installed on their system (imagine a dozen\n          Python virtual environments that won't all be updated at the same\n          time; this is the situation I always find myself in :-). These\n          versions of pip-accel will be sharing the same local source\n          distribution index directory.\n\n        - All of this leads up to the local source distribution index directory\n          containing a mixture of symbolic links and regular files with no\n          obvious way to atomically and gracefully upgrade the local source\n          distribution index directory while avoiding fights between old and\n          new versions of pip-accel :-).\n\n        - I could of course switch to storing the new local source distribution\n          index in a differently named directory (avoiding potential conflicts\n          between multiple versions of pip-accel) but then I would have to\n          introduce a new configuration option, otherwise everyone who has\n          configured pip-accel to store its source index in a non-default\n          location could still be bitten by compatibility issues.\n\n        For now I've decided to keep using the same directory for the local\n        source distribution index and to keep cleaning up broken symbolic\n        links. This enables cooperating between old and new versions of\n        pip-accel and avoids trashing user's local source distribution indexes.\n        The main disadvantage is that pip-accel is still required to clean up\n        broken symbolic links...\n        " #NEWLINE# cleanup_timer = Timer ( ) #NEWLINE# cleanup_counter = 0 #NEWLINE# for entry in os . listdir ( self . config . source_index ) : #NEWLINE# #INDENT# pathname = os . path . join ( self . config . source_index , entry ) #NEWLINE# if ( os . path . islink ( pathname ) and ( not os . path . exists ( pathname ) ) ) : #NEWLINE# #INDENT# logger . warn ( 'Cleaning up broken symbolic link: %s' , pathname ) #NEWLINE# os . unlink ( pathname ) #NEWLINE# cleanup_counter += 1 #NEWLINE# #UNINDENT# #UNINDENT# logger . debug ( 'Cleaned up %i broken symbolic links from source index in %s.' , cleanup_counter , cleanup_timer )