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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/usr/bin/python
import sys
import os
import os.path
import rpm
import string
rpmFD = None
fns = {}
import comps
def cmpHeaderByName(h1, h2):
n1 = h1['name']
n2 = h2['name']
if n1 < n2:
return -1
elif n1 == n2:
return 0;
return 1
def transCB(what, amount, total, h, intf):
if (what == rpm.RPMCALLBACK_INST_OPEN_FILE):
global rpmFD
global distDir
global pkgOrder
global fns
name = h[1000000]
# we need the real header for later
rpmFD = os.open(distDir + '/RedHat/RPMS/' + name, os.O_RDONLY)
fd = os.open(distDir + '/RedHat/RPMS/' + name, os.O_RDONLY)
(newH, isSource) = rpm.headerFromPackage(fd)
os.close(fd)
pkgOrder.append(newH)
fns[newH] = name
return rpmFD
elif (what == rpm.RPMCALLBACK_INST_CLOSE_FILE):
global rpmFD
os.close (rpmFD)
if len(sys.argv) != 3:
print "splitdistro <toppath> <arch>"
sys.exit(1)
arch = sys.argv[2]
distDir = os.path.normpath(sys.argv[1])
if not os.path.isdir(distDir):
print "error: %s is not a directory" % distDir
sys.exit(1)
disc1Dir = distDir + "-disc1"
disc1SrcDir = distDir + "-srpms"
disc2Dir = distDir + "-disc2"
hdlist = comps.HeaderListFromFile(distDir + "/RedHat/base/hdlist", noscore = 1)
comps = comps.ComponentSet(distDir + "/RedHat/base/comps", hdlist,
arch = arch, matchAllLang = 1)
for comp in comps:
if comp.name != 'Everything':
comp.select(1)
for package in hdlist.keys():
if len(package) >= 7 and package[:7] == "kernel-":
hdlist[package].selected = 1
# work out the order we'd like to install everything in
pkgOrder = []
list = []
for p in hdlist.selected():
list.append(p.h)
list.sort(cmpHeaderByName)
for item in list:
pkgOrder.append(item)
list = []
for p in hdlist.packages.values():
if not p.selected:
list.append(p.h)
list.sort(cmpHeaderByName)
for item in list:
pkgOrder.append(item)
testpath = '/tmp/splitdistro-' + str (os.getpid ())
os.system ("mkdir -p " + testpath + "/var/lib/rpm")
db = rpm.opendb(1, testpath)
ts = rpm.TransactionSet(testpath, db)
for h in pkgOrder:
ts.add(h, h, 'i')
pkgOrder = []
ts.order()
problems = ts.run(rpm.RPMTRANS_FLAG_TEST, ~0, transCB, None)
for p in pkgOrder:
print fns[p]
|