Last active
December 25, 2015 18:29
-
-
Save fffonion/7020725 to your computer and use it in GitHub Desktop.
cleanup old eclipse packages
This file contains 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 | |
import re | |
from distutils.version import LooseVersion, StrictVersion | |
#def versiontuple(v): | |
# return tuple(map(int, (v.split(".")))) | |
dir='D:\\Dev\\Java\\eclipse.x86\\plugins' | |
del_dir=os.path.join(dir,'_delete') | |
plugin=os.listdir(dir) | |
plugin_dict={} | |
for p in plugin: | |
if p=='_delete': | |
continue | |
pkg,ver=re.findall('(.+)_(.+)',p)[0] | |
ver=LooseVersion(ver) | |
if pkg in plugin_dict: | |
plugin_dict[pkg].append(ver) | |
else: | |
plugin_dict[pkg]=[ver] | |
cnt=0 | |
if not os.path.exists(del_dir): | |
os.mkdir(del_dir) | |
for p in plugin_dict: | |
if len(plugin_dict[p])>1: | |
fs=['%s_%s'%(p,sorted(plugin_dict[p])[i]) for i in range(len(plugin_dict[p])-1)] | |
for f in fs: | |
print(f) | |
os.rename(os.path.join(dir,f),os.path.join(del_dir,f)) | |
cnt+=1 | |
print('%d unused pkgs moved to %s\\_delete.'%(cnt,dir)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment