Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created July 22, 2017 11:28
Show Gist options
  • Save pandada8/8a328f722a6aeef50e1676864fd7ff34 to your computer and use it in GitHub Desktop.
Save pandada8/8a328f722a6aeef50e1676864fd7ff34 to your computer and use it in GitHub Desktop.
Clean Meteor Old Packages With Python 3
import os
from distutils.version import LooseVersion
import shutil
path = os.path.expanduser('~/.meteor/packages')
for root, dirs, files in os.walk(path):
if root == path:
continue
version = sorted([i for i in dirs if i[0] != '.'], key=LooseVersion)
if len(version) > 1:
print(root)
for i in version[:-1]:
link = os.readlink(os.path.join(root, i))
print(i, link)
shutil.rmtree(os.path.join(root, link))
os.unlink(os.path.join(root, i))
dirs[:] = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment