Skip to content

Instantly share code, notes, and snippets.

@marciomazza
Created July 9, 2012 01:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciomazza/3073752 to your computer and use it in GitHub Desktop.
Save marciomazza/3073752 to your computer and use it in GitHub Desktop.
Strips the buildout cache from older egg versions
#!/usr/bin/python
import os
from itertools import groupby
from shutil import rmtree
from pkg_resources import parse_version
def main():
"""Strips the buildout cache from older egg versions
"""
cache_dir = os.getenv("HOME") + '/.buildout/eggs'
eggs = sorted(os.listdir(cache_dir), key=parse_version, reverse=True)
print "Removing old eggs from buildout cache:"
for _, g in groupby(eggs, lambda x: x.split('-')[0]):
g.next() # skip the one with the highest version (or single one)
for egg in g:
rmtree(os.path.join(cache_dir, egg))
print "- %s" % egg
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment