Skip to content

Instantly share code, notes, and snippets.

@fffonion
Last active December 25, 2015 18:29
Show Gist options
  • Save fffonion/7020725 to your computer and use it in GitHub Desktop.
Save fffonion/7020725 to your computer and use it in GitHub Desktop.
cleanup old eclipse packages
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