blob: 11c6ea033c21cde9954411d8361b072dc6980274 [file] [log] [blame]
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
import sys, os
import portage
except ImportError:
from os import path as osp
sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
import portage
import re
import portage.exception
__candidatematcher__ = re.compile("^[0-9]+: \\*\\*\\* emerge ")
__noncandidatematcher__ = re.compile(" sync( |$)| clean( |$)| search( |$)|--oneshot|--fetchonly| unmerge( |$)")
def issyspkg(pkgline):
return (pkgline[0] == "*")
def iscandidate(logline):
return (__candidatematcher__.match(logline) \
and not
def getpkginfo(logline):
logline = re.sub("^[0-9]+: \\*\\*\\* emerge ", "", logline)
logline = logline.strip()
logline = re.sub("(\\S+\\.(ebuild|tbz2))|(--\\S+)|inject ", "", logline)
return logline.strip()
__uniqlist__ = []
def isunwanted(pkgline):
if pkgline in ["world", "system", "depclean", "info", "regen", ""]:
return False
elif pkgline in __uniqlist__:
return False
elif not"^[a-zA-Z<>=~]", pkgline):
return False
return True
world_file = os.path.join("/", portage.WORLD_FILE)
# show a little description if we have arguments
if len(sys.argv) >= 2 and sys.argv[1] in ["-h", "--help"]:
print "This script regenerates the portage world file by checking the portage"
print "logfile for all actions that you've done in the past. It ignores any"
print "arguments except --help. It is recommended that you make a backup of"
print "your existing world file (%s) before using this tool." % world_file
worldlist = portage.grabfile(os.path.join("/", portage.WORLD_FILE))
syslist = portage.settings.packages
syslist = filter(issyspkg, syslist)
logfile = portage.grabfile("/var/log/emerge.log")
biglist = filter(iscandidate, logfile)
biglist = map(getpkginfo, biglist)
tmplist = []
for l in biglist:
tmplist += l.split()
biglist = filter(isunwanted, tmplist)
#for p in biglist:
# print p
# resolving virtuals
realsyslist = []
for mykey in syslist:
# drop the asterix
mykey = mykey[1:]
#print "candidate:",mykey
if mylist:
if mykey not in realsyslist:
for mykey in biglist:
#print "checking:",mykey
except (portage.exception.InvalidAtom, KeyError):
if "--debug" in sys.argv:
print "* ignoring broken log entry for %s (likely injected)" % mykey
except ValueError, e:
print "* %s is an ambigous package name, candidates are:\n%s" % (mykey, e)
if mylist:
#print "mylist:",mylist
if (myfavkey not in realsyslist) and (myfavkey not in worldlist):
print "add to world:",myfavkey
portage.write_atomic(os.path.join("/", portage.WORLD_FILE),
"\n".join(sorted(worldlist)) + "\n")