]>
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 | ||
102 | def uninstall_self_conflict(b): | |
103 | b.log_line("checking BuildConflict-ing packages") | |
266325ca ER |
104 | f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \ |
105 | "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % { | |
106 | 'tmpdir': b.tmpdir(), | |
4e14a9bc | 107 | 'rpmdefs' : b.rpmbuild_opts(), |
839f8b9f | 108 | 'topdir' : b.get_topdir(), |
4e14a9bc | 109 | 'spec': b.spec, |
22ca9cb4 | 110 | }, encoding = "utf-8") |
84c554a0 AM |
111 | # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src |
112 | # java-sun conflicts with soprano-2.1.67-1.src | |
44e63f67 | 113 | rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)") |
301f3b7f | 114 | conflicting = {} |
8b63d7eb | 115 | for l in f: |
301f3b7f | 116 | m = rx.search(l) |
acc796cd AM |
117 | if m: |
118 | b.log_line("rpmbuild: %s" % l.rstrip()) | |
44e63f67 | 119 | conflicting[m.group('name')] = 1 |
301f3b7f | 120 | f.close() |
7fe3e937 | 121 | if len(conflicting) and not uninstall(conflicting, b): |
feb26777 AM |
122 | return False |
123 | b.log_line("no BuildConflicts found") | |
301f3b7f AM |
124 | return True |
125 | ||
deda9a51 | 126 | def install_br(r, b): |
e6e9e8d0 | 127 | def is_rpmorg(): |
22ca9cb4 | 128 | f = chroot.popen("rpm --version 2>&1", encoding = "utf-8") |
e6e9e8d0 JR |
129 | v = re.compile(r'(RPM version|rpm \(RPM\)) (?P<major>\d)\.(?P<minor>\d+)(\.\d+)?') |
130 | for l in f: | |
131 | m = v.search(l) | |
132 | if m: | |
133 | major = int(m.group('major')) | |
134 | minor = int(m.group('minor')) | |
135 | if major == 4 and minor > 5: | |
136 | f.close() | |
137 | return True | |
138 | f.close() | |
139 | return False | |
140 | ||
638f3c7d AM |
141 | def get_missing_br(r, b): |
142 | # ignore internal rpm dependencies, see lib/rpmns.c for list | |
143 | 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)\(.*') | |
144 | ||
266325ca | 145 | tmpdir = b.tmpdir() |
e6e9e8d0 JR |
146 | if is_rpmorg(): |
147 | rpmcommand = "rpmbuild --nobuild -br" | |
148 | else: | |
149 | rpmcommand = "rpmbuild --nobuild" | |
275c43f3 | 150 | cmd = "set -e; TMPDIR=%(tmpdir)s %(rpmcommand)s %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % { |
f05867b3 | 151 | 'rpmcommand': rpmcommand, |
4e14a9bc | 152 | 'tmpdir': tmpdir, |
839f8b9f | 153 | 'topdir' : b.get_topdir(), |
4e14a9bc | 154 | 'rpmdefs' : b.rpmbuild_opts(), |
4e14a9bc ER |
155 | 'spec': b.spec, |
156 | } | |
22ca9cb4 | 157 | f = chroot.popen(cmd, encoding = "utf-8") |
638f3c7d AM |
158 | rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by") |
159 | needed = {} | |
160 | b.log_line("checking BR") | |
8b63d7eb | 161 | for l in f: |
638f3c7d AM |
162 | b.log_line("rpm: %s" % l.rstrip()) |
163 | m = rx.search(l) | |
164 | if m and not ignore_br.match(l): | |
165 | needed[m.group('name')] = 1 | |
166 | f.close() | |
638f3c7d AM |
167 | return needed |
168 | ||
169 | needed = get_missing_br(r, b); | |
83e50e5b | 170 | |
dfff8bd5 MM |
171 | if len(needed) == 0: |
172 | b.log_line("no BR needed") | |
feb26777 | 173 | return True |
638f3c7d | 174 | |
dfff8bd5 MM |
175 | nbr = "" |
176 | for bre in needed.keys(): | |
177 | nbr = nbr + " " + re.escape(bre) | |
3bdce373 | 178 | br = nbr.strip() |
caaac412 | 179 | b.log_line("updating poldek cache...") |
371eb1b9 | 180 | chroot.run("poldek --up --upa", user = "root", logfile = b.logfile) |
caaac412 AM |
181 | # check conflicts in BRed packages |
182 | b.log_line("checking conflicting packages in BRed packages") | |
22ca9cb4 | 183 | f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root", encoding = "utf-8") |
cc7a77b7 | 184 | # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686 |
e81b20ed | 185 | # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch |
3e45c3b6 | 186 | # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch |
51deed6d | 187 | rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)") |
caaac412 | 188 | conflicting = {} |
8b63d7eb | 189 | for l in f: |
05f294ad | 190 | b.log_line("poldek: %s" % l.rstrip()) |
caaac412 | 191 | m = rx.search(l) |
34226c1a | 192 | if m: conflicting[m.group('name')] = 1 |
caaac412 AM |
193 | f.close() |
194 | if len(conflicting) == 0: | |
195 | b.log_line("no conflicts found") | |
196 | else: | |
67a9d800 | 197 | if not uninstall(conflicting, b): |
301f3b7f | 198 | return False |
638f3c7d AM |
199 | |
200 | # recheck BuildRequires since above uninstallation could remove some required deps | |
201 | needed = get_missing_br(r, b); | |
202 | ||
203 | if len(needed) == 0: | |
204 | b.log_line("no BR needed") | |
205 | return True | |
e6376553 | 206 | |
638f3c7d AM |
207 | nbr = "" |
208 | for bre in needed.keys(): | |
209 | nbr = nbr + " " + re.escape(bre) | |
3bdce373 | 210 | br = nbr.strip() |
638f3c7d | 211 | |
dfff8bd5 | 212 | b.log_line("installing BR: %s" % br) |
b95ea8fe | 213 | res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), |
caaac412 AM |
214 | user = "root", |
215 | logfile = b.logfile) | |
dfff8bd5 MM |
216 | if res != 0: |
217 | b.log_line("error: BR installation failed") | |
feb26777 AM |
218 | return False |
219 | return True |