1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
19 def close_killset(killset):
23 rx = re.compile(r'^.* marks ([^\s]+?)-[^-]+-[^-]+\s.*$')
28 errors += "cannot remove %s because it's crucial\n" % p
30 f = chroot.popen("poldek --noask --test --erase %s" % p, user = "root")
33 for l in f.xreadlines():
38 errors += "cannot remove %s because it's required " \
39 "by %s, that is crucial\n" % (p, pkg)
50 def upgrade_from_batch(r, b):
51 f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
53 rx = re.compile(r' \(installed\) ([^\s]+)-[^-]+-[^-]+$')
54 for l in f.xreadlines():
56 if m: killset[m.group(1)] = 1
59 err = close_killset(killset)
61 util.append_to(b.logfile, err)
62 log.notice("cannot upgrade rpms")
64 k = string.join(killset.keys())
66 b.log_line("upgrade requires removal of %s" % k)
67 res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root")
69 b.log_line("package removal failed")
72 b.log_line("packages removed sucessfuly")
74 b.log_line("upgrade would need removal of %s" % k)
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)
80 b.log_line("package upgrade failed")
86 def uninstall(conflicting, b):
87 b.log_line("uninstalling conflicting packages")
88 err = close_killset(conflicting)
90 util.append_to(b.logfile, err)
91 b.log_line("error: conflicting packages uninstallation failed")
94 k = string.join(conflicting.keys())
95 b.log_line("removing %s" % k)
96 res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root")
98 b.log_line("package removal failed")
102 def uninstall_self_conflict(b):
103 b.log_line("checking BuildConflict-ing packages")
104 rpmbuild_opt = "%s %s %s" % (b.target_string(), b.kernel_string(), b.bconds_string())
105 tmpdir = "/tmp/BR." + b.b_id[0:6]
106 f = chroot.popen("cd rpm/SPECS; TMPDIR=%s rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %s %s 2>&1" \
107 % (tmpdir, rpmbuild_opt, b.spec))
108 # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
109 # java-sun conflicts with soprano-2.1.67-1.src
110 rx = re.compile(r"\s+([\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src$")
112 for l in f.xreadlines():
115 b.log_line("rpmbuild: %s" % l.rstrip())
116 conflicting[m.group(1)] = 1
118 if len(conflicting) and not uninstall(conflicting, b):
120 b.log_line("no BuildConflicts found")
123 def install_br(r, b):
124 # ignore internal rpm dependencies, see lib/rpmns.c for list
125 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)\(.*')
127 tmpdir = "/tmp/BR." + b.b_id[0:6]
128 chroot.run("install -m 700 -d %s" % tmpdir)
129 cmd = "cd rpm/SPECS; TMPDIR=%s rpmbuild --nobuild %s %s 2>&1" \
130 % (tmpdir, b.bconds_string(), b.spec)
131 f = chroot.popen(cmd)
132 rx = re.compile(r"^\s*([^\s]+) .*is needed by")
134 b.log_line("checking BR")
135 for l in f.xreadlines():
136 b.log_line("rpm: %s" % l.rstrip())
138 if m and not ignore_br.match(l):
139 needed[m.group(1)] = 1
141 chroot.run("rm -rf %s" % tmpdir)
143 b.log_line("no BR needed")
146 for bre in needed.keys():
147 nbr = nbr + " " + re.escape(bre)
148 br = string.strip(nbr)
149 b.log_line("updating poldek cache...")
150 chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
151 # check conflicts in BRed packages
152 b.log_line("checking conflicting packages in BRed packages")
153 f = chroot.popen("poldek --test --noask --caplookup -Q -v --upgrade %s" % br, user = "root")
154 rx = re.compile(r".*conflicts with installed ([^\s]+)-[^-]+-[^-]+ .*")
156 for l in f.xreadlines():
157 b.log_line("poldek: %s" % l.rstrip())
159 if m: conflicting[m.group(1)] = 1
161 if len(conflicting) == 0:
162 b.log_line("no conflicts found")
164 if not uninstall(conflicting, b):
166 b.log_line("installing BR: %s" % br)
167 res = chroot.run("poldek --noask --caplookup -Q -v --upgrade %s" % br,
171 b.log_line("error: BR installation failed")