Created
July 22, 2017 11:28
-
-
Save pandada8/8a328f722a6aeef50e1676864fd7ff34 to your computer and use it in GitHub Desktop.
Clean Meteor Old Packages With Python 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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