]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/install.py
- split package list for head and longterm builds
[projects/pld-builder.new.git] / PLD_Builder / install.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
508a95ef 3import re, os
deda9a51 4import string
73bdb36b 5import StringIO
deda9a51
MM
6
7import chroot
816ecd49 8import util
73bdb36b
AM
9import log
10
11hold = [
12 'dev',
13 'poldek',
14 'rpm-build',
15 'pdksh',
16 'coreutils'
17]
18
19def close_killset(killset):
20 k = killset.keys()
feb26777
AM
21 if len(k) == 0:
22 return True
44e63f67 23 rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
73bdb36b
AM
24 errors = ""
25 for p in k:
26 if p in hold:
27 del killset[p]
28 errors += "cannot remove %s because it's crucial\n" % p
29 else:
64dbb5be 30 f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
73bdb36b
AM
31 crucial = 0
32 e = []
33 for l in f.xreadlines():
34 m = rx.search(l)
35 if m:
44e63f67 36 pkg = m.group('name')
73bdb36b
AM
37 if pkg in hold:
38 errors += "cannot remove %s because it's required " \
39 "by %s, that is crucial\n" % (p, pkg)
40 crucial = 1
41 e.append(pkg)
42 f.close()
43 if crucial:
44 del killset[p]
45 else:
46 for p in e:
47 killset[p] = 2
48 return errors
49
50def upgrade_from_batch(r, b):
51 f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
52 killset = {}
44e63f67 53 rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
73bdb36b
AM
54 for l in f.xreadlines():
55 m = rx.search(l)
44e63f67 56 if m: killset[m.group('name')] = 1
73bdb36b
AM
57 f.close()
58 if len(killset) != 0:
59 err = close_killset(killset)
60 if err != "":
61 util.append_to(b.logfile, err)
62 log.notice("cannot upgrade rpms")
63 return False
64 k = string.join(killset.keys())
65 if True:
66 b.log_line("upgrade requires removal of %s" % k)
67 res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root")
68 if res != 0:
69 b.log_line("package removal failed")
7280b307 70 return False
73bdb36b
AM
71 else:
72 b.log_line("packages removed sucessfuly")
73 else:
74 b.log_line("upgrade would need removal of %s" % k)
75 return False
76 b.log_line("upgrading packages")
77 logbuf = StringIO.StringIO()
78 res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile)
79 if res != 0:
80 b.log_line("package upgrade failed")
81 logbuf.close()
82 return False
83 logbuf.close()
84 return True
deda9a51 85
301f3b7f
AM
86def uninstall(conflicting, b):
87 b.log_line("uninstalling conflicting packages")
88 err = close_killset(conflicting)
89 if err != "":
90 util.append_to(b.logfile, err)
91 b.log_line("error: conflicting packages uninstallation failed")
92 return False
93 else:
7280b307
AM
94 for k in conflicting.keys():
95 b.log_line("removing %s" % k)
96 res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root")
97 if res != 0:
98 b.log_line("package %s removal failed" % k)
301f3b7f
AM
99 return True
100
101def uninstall_self_conflict(b):
102 b.log_line("checking BuildConflict-ing packages")
266325ca
ER
103 f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
104 "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
105 'tmpdir': b.tmpdir(),
4e14a9bc 106 'rpmdefs' : b.rpmbuild_opts(),
266325ca 107 'topdir' : b._topdir,
4e14a9bc
ER
108 'spec': b.spec,
109 })
84c554a0
AM
110 # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
111 # java-sun conflicts with soprano-2.1.67-1.src
44e63f67 112 rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
301f3b7f
AM
113 conflicting = {}
114 for l in f.xreadlines():
301f3b7f 115 m = rx.search(l)
acc796cd
AM
116 if m:
117 b.log_line("rpmbuild: %s" % l.rstrip())
44e63f67 118 conflicting[m.group('name')] = 1
301f3b7f 119 f.close()
7fe3e937 120 if len(conflicting) and not uninstall(conflicting, b):
feb26777
AM
121 return False
122 b.log_line("no BuildConflicts found")
301f3b7f
AM
123 return True
124
deda9a51 125def install_br(r, b):
638f3c7d
AM
126 def get_missing_br(r, b):
127 # ignore internal rpm dependencies, see lib/rpmns.c for list
128 ignore_br = re.compile(r'^\s*(rpmlib|cpuinfo|getconf|uname|soname|user|group|mounted|diskspace|digest|gnupg|macro|envvar|running|sanitycheck|vcheck|signature|verify|exists|executable|readable|writable)\(.*')
129
266325ca 130 tmpdir = b.tmpdir()
266325ca 131 cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
4e14a9bc 132 'tmpdir': tmpdir,
266325ca 133 'topdir' : b._topdir,
4e14a9bc 134 'rpmdefs' : b.rpmbuild_opts(),
4e14a9bc
ER
135 'spec': b.spec,
136 }
638f3c7d
AM
137 f = chroot.popen(cmd)
138 rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by")
139 needed = {}
140 b.log_line("checking BR")
141 for l in f.xreadlines():
142 b.log_line("rpm: %s" % l.rstrip())
143 m = rx.search(l)
144 if m and not ignore_br.match(l):
145 needed[m.group('name')] = 1
146 f.close()
638f3c7d
AM
147 return needed
148
149 needed = get_missing_br(r, b);
83e50e5b 150
dfff8bd5
MM
151 if len(needed) == 0:
152 b.log_line("no BR needed")
feb26777 153 return True
638f3c7d 154
dfff8bd5
MM
155 nbr = ""
156 for bre in needed.keys():
157 nbr = nbr + " " + re.escape(bre)
158 br = string.strip(nbr)
caaac412 159 b.log_line("updating poldek cache...")
371eb1b9 160 chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
caaac412
AM
161 # check conflicts in BRed packages
162 b.log_line("checking conflicting packages in BRed packages")
64dbb5be 163 f = chroot.popen("poldek --test --test --noask --caplookup -Q -v --upgrade %s" % br, user = "root")
cc7a77b7 164 # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
e81b20ed 165 # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
3e45c3b6 166 # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
51deed6d 167 rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
caaac412
AM
168 conflicting = {}
169 for l in f.xreadlines():
05f294ad 170 b.log_line("poldek: %s" % l.rstrip())
caaac412 171 m = rx.search(l)
34226c1a 172 if m: conflicting[m.group('name')] = 1
caaac412
AM
173 f.close()
174 if len(conflicting) == 0:
175 b.log_line("no conflicts found")
176 else:
67a9d800 177 if not uninstall(conflicting, b):
301f3b7f 178 return False
638f3c7d
AM
179
180 # recheck BuildRequires since above uninstallation could remove some required deps
181 needed = get_missing_br(r, b);
182
183 if len(needed) == 0:
184 b.log_line("no BR needed")
185 return True
e6376553 186
638f3c7d
AM
187 nbr = ""
188 for bre in needed.keys():
189 nbr = nbr + " " + re.escape(bre)
190 br = string.strip(nbr)
191
dfff8bd5 192 b.log_line("installing BR: %s" % br)
711d8238 193 res = chroot.run("poldek --noask --caplookup -Q -v --upgrade %s" % br,
caaac412
AM
194 user = "root",
195 logfile = b.logfile)
dfff8bd5
MM
196 if res != 0:
197 b.log_line("error: BR installation failed")
feb26777
AM
198 return False
199 return True
This page took 0.537945 seconds and 4 git commands to generate.