2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
10 sys.path.insert(0, "/usr/lib/portage/pym")
14 __candidatematcher__ = re.compile("^[0-9]+: \\*\\*\\* emerge ")
15 __noncandidatematcher__ = re.compile(" sync( |$)| clean( |$)| search( |$)|--oneshot|--fetchonly| unmerge( |$)")
17 def issyspkg(pkgline):
18 return (pkgline[0] == "*")
20 def iscandidate(logline):
21 return (__candidatematcher__.match(logline) \
22 and not __noncandidatematcher__.search(logline))
24 def getpkginfo(logline):
25 logline = re.sub("^[0-9]+: \\*\\*\\* emerge ", "", logline)
26 logline = logline.strip()
27 logline = re.sub("(\\S+\\.(ebuild|tbz2))|(--\\S+)|inject ", "", logline)
28 return logline.strip()
31 def isunwanted(pkgline):
32 if pkgline in ["world", "system", "depclean", "info", "regen", ""]:
34 elif pkgline in __uniqlist__:
36 elif not re.search("^[a-zA-Z<>=~]", pkgline):
39 __uniqlist__.append(pkgline)
42 # show a little description if we have arguments
43 if len(sys.argv) >= 2 and sys.argv[1] in ["-h", "--help"]:
44 print "This script regenerates the portage world file by checking the portage"
45 print "logfile for all actions that you've done in the past. It ignores any"
46 print "arguments except --help. It is recommended that you make a backup of"
47 print "your existing world file (%s) before using this tool." % portage.WORLD_FILE
50 worldlist = portage.grabfile(os.path.join("/", portage.WORLD_FILE))
51 syslist = portage.settings.packages
52 syslist = filter(issyspkg, syslist)
54 logfile = portage.grabfile("/var/log/emerge.log")
55 biglist = filter(iscandidate, logfile)
56 biglist = map(getpkginfo, biglist)
60 biglist = filter(isunwanted, tmplist)
70 #print "candidate:",mykey
71 mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
73 mykey=portage.cpv_getkey(mylist[0])
74 if mykey not in realsyslist:
75 realsyslist.append(mykey)
78 #print "checking:",mykey
80 mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
82 if "--debug" in sys.argv:
83 print "* ignoring broken log entry for %s (likely injected)" % mykey
85 print "* %s is an ambigous package name, candidates are:\n%s" % (mykey, e)
88 #print "mylist:",mylist
89 myfavkey=portage.cpv_getkey(mylist[0])
90 if (myfavkey not in realsyslist) and (myfavkey not in worldlist):
91 print "add to world:",myfavkey
92 worldlist.append(myfavkey)
94 portage.write_atomic(os.path.join("/", portage.WORLD_FILE), "\n".join(worldlist))