]>
Commit | Line | Data |
---|---|---|
dfff8bd5 MM |
1 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et |
2 | ||
508a95ef | 3 | import re, os |
deda9a51 | 4 | import string |
1c54a525 | 5 | import sys |
14edabbe | 6 | from io import StringIO |
deda9a51 | 7 | import chroot |
816ecd49 | 8 | import util |
73bdb36b AM |
9 | import log |
10 | ||
11 | hold = [ | |
12 | 'dev', | |
13 | 'poldek', | |
14 | 'rpm-build', | |
98dc090c | 15 | 'mksh', |
15933860 AM |
16 | 'coreutils', |
17 | 'util-linux' | |
73bdb36b AM |
18 | ] |
19 | ||
20 | def close_killset(killset): | |
21 | k = killset.keys() | |
feb26777 AM |
22 | if len(k) == 0: |
23 | return True | |
44e63f67 | 24 | rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$') |
73bdb36b | 25 | errors = "" |
129e2f73 | 26 | for p in list(k): |
73bdb36b AM |
27 | if p in hold: |
28 | del killset[p] | |
29 | errors += "cannot remove %s because it's crucial\n" % p | |
30 | else: | |
22ca9cb4 | 31 | f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root", encoding = "utf-8") |
73bdb36b AM |
32 | crucial = 0 |
33 | e = [] | |
8b63d7eb | 34 | for l in f: |
73bdb36b AM |
35 | m = rx.search(l) |
36 | if m: | |
44e63f67 | 37 | pkg = m.group('name') |
73bdb36b AM |
38 | if pkg in hold: |
39 | errors += "cannot remove %s because it's required " \ | |
40 | "by %s, that is crucial\n" % (p, pkg) | |
41 | crucial = 1 | |
42 | e.append(pkg) | |
43 | f.close() | |
44 | if crucial: | |
45 | del killset[p] | |
46 | else: | |
47 | for p in e: | |
48 | killset[p] = 2 | |
49 | return errors | |
50 | ||
51 | def upgrade_from_batch(r, b): | |
22ca9cb4 | 52 | f = chroot.popen("rpm --test -F %s 2>&1" % ' '.join(b.files), user = "root", encoding = "utf-8") |
73bdb36b | 53 | killset = {} |
44e63f67 | 54 | rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$') |
8b63d7eb | 55 | for l in f: |
73bdb36b | 56 | m = rx.search(l) |
44e63f67 | 57 | if m: killset[m.group('name')] = 1 |
73bdb36b AM |
58 | f.close() |
59 | if len(killset) != 0: | |
60 | err = close_killset(killset) | |
61 | if err != "": | |
62 | util.append_to(b.logfile, err) | |
63 | log.notice("cannot upgrade rpms") | |
64 | return False | |
524db802 | 65 | k = ' '.join(killset.keys()) |
73bdb36b AM |
66 | if True: |
67 | b.log_line("upgrade requires removal of %s" % k) | |
68 | res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root") | |
69 | if res != 0: | |
70 | b.log_line("package removal failed") | |
7280b307 | 71 | return False |
73bdb36b AM |
72 | else: |
73 | b.log_line("packages removed sucessfuly") | |
74 | else: | |
75 | b.log_line("upgrade would need removal of %s" % k) | |
76 | return False | |
77 | b.log_line("upgrading packages") | |
9366870d | 78 | logbuf = StringIO() |
524db802 | 79 | res = chroot.run("rpm -Fvh %s" % ' '.join(b.files), user = "root", logfile = b.logfile) |
73bdb36b AM |
80 | if res != 0: |
81 | b.log_line("package upgrade failed") | |
82 | logbuf.close() | |
83 | return False | |
84 | logbuf.close() | |
85 | return True | |
deda9a51 | 86 | |
301f3b7f AM |
87 | def uninstall(conflicting, b): |
88 | b.log_line("uninstalling conflicting packages") | |
89 | err = close_killset(conflicting) | |
90 | if err != "": | |
91 | util.append_to(b.logfile, err) | |
92 | b.log_line("error: conflicting packages uninstallation failed") | |
93 | return False | |
94 | else: | |
7280b307 AM |
95 | for k in conflicting.keys(): |
96 | b.log_line("removing %s" % k) | |
97 | res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root") | |
98 | if res != 0: | |
99 | b.log_line("package %s removal failed" % k) | |
301f3b7f AM |
100 | return True |
101 | ||
9c20dc6a JR |
102 | def is_rpmorg(): |
103 | f = chroot.popen("rpm --version 2>&1", encoding = "utf-8") | |
104 | v = re.compile(r'(RPM version|rpm \(RPM\)) (?P<major>\d)\.(?P<minor>\d+)(\.\d+)?') | |
105 | for l in f: | |
106 | m = v.search(l) | |
107 | if m: | |
108 | major = int(m.group('major')) | |
109 | minor = int(m.group('minor')) | |
110 | if major == 4 and minor > 5: | |
111 | f.close() | |
112 | return True | |
113 | f.close() | |
114 | return False | |
115 | ||
301f3b7f AM |
116 | def uninstall_self_conflict(b): |
117 | b.log_line("checking BuildConflict-ing packages") | |
9c20dc6a JR |
118 | if is_rpmorg(): |
119 | rpmcommand = "rpmbuild --nobuild -br" | |
120 | else: | |
121 | rpmcommand = "rpmbuild --nobuild" | |
122 | cmd = "set -e; TMPDIR=%(tmpdir)s %(rpmcommand)s %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % { | |
123 | 'rpmcommand': rpmcommand, | |
266325ca | 124 | 'tmpdir': b.tmpdir(), |
839f8b9f | 125 | 'topdir' : b.get_topdir(), |
9c20dc6a | 126 | 'rpmdefs' : b.rpmbuild_opts(), |
4e14a9bc | 127 | 'spec': b.spec, |
9c20dc6a JR |
128 | } |
129 | f = chroot.popen(cmd, encoding = "utf-8") | |
84c554a0 AM |
130 | # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src |
131 | # java-sun conflicts with soprano-2.1.67-1.src | |
b2679a62 JP |
132 | # plplot conflicts with plplot-5.15.0-4.x86_64 |
133 | rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.[^.\s]+($| .*)") | |
301f3b7f | 134 | conflicting = {} |
8b63d7eb | 135 | for l in f: |
9c20dc6a | 136 | b.log_line("rpm: %s" % l.rstrip()) |
301f3b7f | 137 | m = rx.search(l) |
acc796cd | 138 | if m: |
44e63f67 | 139 | conflicting[m.group('name')] = 1 |
301f3b7f | 140 | f.close() |
7fe3e937 | 141 | if len(conflicting) and not uninstall(conflicting, b): |
feb26777 AM |
142 | return False |
143 | b.log_line("no BuildConflicts found") | |
301f3b7f AM |
144 | return True |
145 | ||
deda9a51 | 146 | def install_br(r, b): |
638f3c7d AM |
147 | def get_missing_br(r, b): |
148 | # ignore internal rpm dependencies, see lib/rpmns.c for list | |
149 | 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)\(.*') | |
150 | ||
266325ca | 151 | tmpdir = b.tmpdir() |
e6e9e8d0 JR |
152 | if is_rpmorg(): |
153 | rpmcommand = "rpmbuild --nobuild -br" | |
154 | else: | |
155 | rpmcommand = "rpmbuild --nobuild" | |
275c43f3 | 156 | cmd = "set -e; TMPDIR=%(tmpdir)s %(rpmcommand)s %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % { |
f05867b3 | 157 | 'rpmcommand': rpmcommand, |
4e14a9bc | 158 | 'tmpdir': tmpdir, |
839f8b9f | 159 | 'topdir' : b.get_topdir(), |
4e14a9bc | 160 | 'rpmdefs' : b.rpmbuild_opts(), |
4e14a9bc ER |
161 | 'spec': b.spec, |
162 | } | |
22ca9cb4 | 163 | f = chroot.popen(cmd, encoding = "utf-8") |
638f3c7d AM |
164 | rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by") |
165 | needed = {} | |
166 | b.log_line("checking BR") | |
8b63d7eb | 167 | for l in f: |
638f3c7d AM |
168 | b.log_line("rpm: %s" % l.rstrip()) |
169 | m = rx.search(l) | |
170 | if m and not ignore_br.match(l): | |
171 | needed[m.group('name')] = 1 | |
172 | f.close() | |
638f3c7d AM |
173 | return needed |
174 | ||
175 | needed = get_missing_br(r, b); | |
83e50e5b | 176 | |
dfff8bd5 MM |
177 | if len(needed) == 0: |
178 | b.log_line("no BR needed") | |
feb26777 | 179 | return True |
638f3c7d | 180 | |
dfff8bd5 MM |
181 | nbr = "" |
182 | for bre in needed.keys(): | |
183 | nbr = nbr + " " + re.escape(bre) | |
3bdce373 | 184 | br = nbr.strip() |
caaac412 | 185 | b.log_line("updating poldek cache...") |
371eb1b9 | 186 | chroot.run("poldek --up --upa", user = "root", logfile = b.logfile) |
caaac412 AM |
187 | # check conflicts in BRed packages |
188 | b.log_line("checking conflicting packages in BRed packages") | |
22ca9cb4 | 189 | f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root", encoding = "utf-8") |
cc7a77b7 | 190 | # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686 |
e81b20ed | 191 | # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch |
3e45c3b6 | 192 | # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch |
51deed6d | 193 | rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)") |
caaac412 | 194 | conflicting = {} |
8b63d7eb | 195 | for l in f: |
05f294ad | 196 | b.log_line("poldek: %s" % l.rstrip()) |
caaac412 | 197 | m = rx.search(l) |
34226c1a | 198 | if m: conflicting[m.group('name')] = 1 |
caaac412 AM |
199 | f.close() |
200 | if len(conflicting) == 0: | |
201 | b.log_line("no conflicts found") | |
202 | else: | |
67a9d800 | 203 | if not uninstall(conflicting, b): |
301f3b7f | 204 | return False |
638f3c7d AM |
205 | |
206 | # recheck BuildRequires since above uninstallation could remove some required deps | |
207 | needed = get_missing_br(r, b); | |
208 | ||
209 | if len(needed) == 0: | |
210 | b.log_line("no BR needed") | |
211 | return True | |
e6376553 | 212 | |
638f3c7d AM |
213 | nbr = "" |
214 | for bre in needed.keys(): | |
215 | nbr = nbr + " " + re.escape(bre) | |
3bdce373 | 216 | br = nbr.strip() |
638f3c7d | 217 | |
dfff8bd5 | 218 | b.log_line("installing BR: %s" % br) |
b95ea8fe | 219 | res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), |
caaac412 AM |
220 | user = "root", |
221 | logfile = b.logfile) | |
dfff8bd5 MM |
222 | if res != 0: |
223 | b.log_line("error: BR installation failed") | |
feb26777 AM |
224 | return False |
225 | return True |