summaryrefslogtreecommitdiff
blob: a55d021df8b82059183844ac30ab280f8dea148d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/bin/db-update.py,v 1.9 2004/10/11 04:01:00 jstubbs Exp $

import os,sys,string
sys.path = ["/usr/lib/portage/pym"]+sys.path

import portage

os.chdir(portage.root+portage.VDB_PATH)
myvirts=portage.grabdict(portage.root+"var/cache/edb/virtuals")
mypvirts={}
if portage.profiledir:
	mypvirts=portage.grabdict(portage.profiledir+"/virtuals")
mydict={}
myvalidargs=[]
origkey={}
for x in sys.argv[1:]:
	myparts=string.split(x,"/")
	x=myparts[1]+"/"+myparts[2]
	try:
		myfile=open(x+"/VIRTUAL","r")
	except SystemExit, e:
		raise # Needed else the app won't quit
	except:
		continue
	myline=myfile.readline()
	mykey=string.join(string.split(myline))
	if portage.isspecific(x):
		mysplit=portage.catpkgsplit(x)
		newkey=mysplit[0]+"/"+mysplit[1]
		origkey[newkey]=x
		x=newkey
	else:
		origkey[x]=x
	if portage.isspecific(mykey):
		mysplit=portage.catpkgsplit(mykey)
		mykey=mysplit[0]+"/"+mysplit[1]
	myvalidargs.append(x)
	mydict[x]=mykey
for x in mydict.keys():
	if mypvirts.has_key(x) and len(mypvirts[x])>=1 and mypvirts[x][0]==mydict[x]:
		#this is a default setting; don't record
		continue
	if myvirts.has_key(x):
		if mydict[x] not in myvirts[x]:
			myvirts[x][0:0]=[mydict[x]]
	else:
		myvirts[x]=[mydict[x]]
print ">>> Database upgrade..."
print ">>> Writing out new virtuals file..."
portage.writedict(myvirts,portage.root+"var/cache/edb/virtuals")
if not os.path.exists("/tmp/db-upgrade-bak"):
	os.mkdir("/tmp/db-upgrade-bak")
print ">>> Backing up to /tmp/db-upgrade-bak..."
for myarg in myvalidargs:
	print ">>> Backing up",portage.root+portage.VDB_PATH+"/"+origkey[myarg]
	os.system("mv "+portage.root+portage.VDB_PATH+"/"+origkey[myarg]+" /tmp/db-upgrade-bak")
print ">>> Done."