]>
Commit | Line | Data |
---|---|---|
dfff8bd5 MM |
1 | # vi: encoding=utf-8 ts=8 sts=4 sw=4 et |
2 | ||
deda9a51 MM |
3 | import re |
4 | import string | |
73bdb36b | 5 | import StringIO |
deda9a51 MM |
6 | |
7 | import chroot | |
816ecd49 | 8 | import util |
73bdb36b AM |
9 | import log |
10 | ||
11 | hold = [ | |
12 | 'dev', | |
13 | 'poldek', | |
14 | 'rpm-build', | |
15 | 'pdksh', | |
16 | 'coreutils' | |
17 | ] | |
18 | ||
19 | def close_killset(killset): | |
20 | k = killset.keys() | |
21 | rx = re.compile(r' marks ([^\s]+)-[^-]+-[^-]+$') | |
22 | errors = "" | |
23 | for p in k: | |
24 | if p in hold: | |
25 | del killset[p] | |
26 | errors += "cannot remove %s because it's crucial\n" % p | |
27 | else: | |
28 | f = chroot.popen("poldek --noask --test --erase %s" % p, user = "root") | |
29 | crucial = 0 | |
30 | e = [] | |
31 | for l in f.xreadlines(): | |
32 | m = rx.search(l) | |
33 | if m: | |
34 | pkg = m.group(1) | |
35 | if pkg in hold: | |
36 | errors += "cannot remove %s because it's required " \ | |
37 | "by %s, that is crucial\n" % (p, pkg) | |
38 | crucial = 1 | |
39 | e.append(pkg) | |
40 | f.close() | |
41 | if crucial: | |
42 | del killset[p] | |
43 | else: | |
44 | for p in e: | |
45 | killset[p] = 2 | |
46 | return errors | |
47 | ||
48 | def upgrade_from_batch(r, b): | |
49 | f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root") | |
50 | killset = {} | |
51 | rx = re.compile(r' \(installed\) ([^\s]+)-[^-]+-[^-]+$') | |
52 | for l in f.xreadlines(): | |
53 | m = rx.search(l) | |
54 | if m: killset[m.group(1)] = 1 | |
55 | f.close() | |
56 | if len(killset) != 0: | |
57 | err = close_killset(killset) | |
58 | if err != "": | |
59 | util.append_to(b.logfile, err) | |
60 | log.notice("cannot upgrade rpms") | |
61 | return False | |
62 | k = string.join(killset.keys()) | |
63 | if True: | |
64 | b.log_line("upgrade requires removal of %s" % k) | |
65 | res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root") | |
66 | if res != 0: | |
67 | b.log_line("package removal failed") | |
68 | return False | |
69 | else: | |
70 | b.log_line("packages removed sucessfuly") | |
71 | else: | |
72 | b.log_line("upgrade would need removal of %s" % k) | |
73 | return False | |
74 | b.log_line("upgrading packages") | |
75 | logbuf = StringIO.StringIO() | |
76 | res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile) | |
77 | if res != 0: | |
78 | b.log_line("package upgrade failed") | |
79 | logbuf.close() | |
80 | return False | |
81 | logbuf.close() | |
82 | return True | |
deda9a51 MM |
83 | |
84 | def install_br(r, b): | |
83e50e5b AM |
85 | # ignore internal rpm dependencies, see lib/rpmns.c for list |
86 | 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)\(.*') | |
87 | ||
cbaf0a71 AM |
88 | tmpdir = "/tmp/BR." + b.b_id[0:6] |
89 | chroot.run("install -m 700 -d %s" % tmpdir) | |
90 | cmd = "cd rpm/SPECS; TMPDIR=%s rpmbuild --nobuild %s %s 2>&1" \ | |
91 | % (tmpdir, b.bconds_string(), b.spec) | |
dfff8bd5 MM |
92 | f = chroot.popen(cmd) |
93 | rx = re.compile(r"^\s*([^\s]+) .*is needed by") | |
94 | needed = {} | |
95 | b.log_line("checking BR") | |
96 | for l in f.xreadlines(): | |
05f294ad | 97 | b.log_line("rpm: %s" % l.rstrip()) |
dfff8bd5 | 98 | m = rx.search(l) |
83e50e5b AM |
99 | if m and not ignore_br.match(l): |
100 | needed[m.group(1)] = 1 | |
dfff8bd5 | 101 | f.close() |
cbaf0a71 | 102 | chroot.run("rm -rf %s" % tmpdir) |
dfff8bd5 MM |
103 | if len(needed) == 0: |
104 | b.log_line("no BR needed") | |
105 | return | |
106 | nbr = "" | |
107 | for bre in needed.keys(): | |
108 | nbr = nbr + " " + re.escape(bre) | |
109 | br = string.strip(nbr) | |
caaac412 | 110 | b.log_line("updating poldek cache...") |
371eb1b9 | 111 | chroot.run("poldek --up --upa", user = "root", logfile = b.logfile) |
caaac412 AM |
112 | # check conflicts in BRed packages |
113 | b.log_line("checking conflicting packages in BRed packages") | |
21d99552 | 114 | f = chroot.popen("poldek --test --noask --caplookup -Q -v --upgrade %s" % br, user = "root") |
bb1d3f62 | 115 | rx = re.compile(r".*conflicts with installed ([^\s]+)-[^-]+-[^-]+$") |
caaac412 AM |
116 | conflicting = {} |
117 | for l in f.xreadlines(): | |
05f294ad | 118 | b.log_line("poldek: %s" % l.rstrip()) |
caaac412 AM |
119 | m = rx.search(l) |
120 | if m: conflicting[m.group(1)] = 1 | |
121 | f.close() | |
122 | if len(conflicting) == 0: | |
123 | b.log_line("no conflicts found") | |
124 | else: | |
caaac412 | 125 | b.log_line("uninstalling conflicting packages") |
73bdb36b | 126 | err = close_killset(conflicting) |
816ecd49 AM |
127 | if err != "": |
128 | util.append_to(b.logfile, err) | |
caaac412 | 129 | b.log_line("error: conflicting packages uninstallation failed") |
276f0940 | 130 | else: |
66eeddcc | 131 | k = string.join(conflicting.keys()) |
276f0940 AM |
132 | b.log_line("removing %s" % k) |
133 | res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root") | |
134 | if res != 0: | |
135 | b.log_line("package removal failed") | |
136 | return res | |
dfff8bd5 | 137 | b.log_line("installing BR: %s" % br) |
711d8238 | 138 | res = chroot.run("poldek --noask --caplookup -Q -v --upgrade %s" % br, |
caaac412 AM |
139 | user = "root", |
140 | logfile = b.logfile) | |
dfff8bd5 MM |
141 | if res != 0: |
142 | b.log_line("error: BR installation failed") | |
143 | return res |