# removeoldpackages.py

# use is python removeoldpackages.py
# using this will make you unhappy if you have PGK_PATH defined
# and at the moment the machine type is hard-coded

import os
import fileinput
import string
import subprocess

print "Initializing removeoldpackages.py"
home=os.environ["HOME"]
packagedirectory="/usr/ports/packages/i386/all"
logfile=home+"/packagelogfile"

p=subprocess.Popen("pkg_add -u -D update",cwd=packagedirectory,shell=True)
for line in fileinput.input():
	if string.find(line,"---"):
		continue
	if string.find(line,"Can't install") and string.find(line, ": conflicts"):
		deadfilename=string.split(string.split(line,":")[0],"install")[1]
		print deadfilename
		q=subprocess.Popen("rm "+deadfilename,shell=True,cwd=packagedirectory)
		q.wait()
		continue
p.wait()

			
	

