1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
19 def close_killset(killset):
23 rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
28 errors += "cannot remove %s because it's crucial\n" % p
30 f = chroot.popen("poldek --noask --test --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\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
54 for l in f.xreadlines():
56 if m: killset[m.group('name')] = 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 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")
98 b.log_line("package %s removal failed" % k)
101 def uninstall_self_conflict(b):
102 b.log_line("checking BuildConflict-ing packages")
103 packagename = b.spec[:-5]
104 tmpdir = "/tmp/B.%s.%s" % (packagename, b.b_id[0:6])
105 chroot.run("install -m 700 -d %s" % tmpdir)
106 f = chroot.popen("set -e; TMPDIR=%(tmpdir)s rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s rpm/packages/%(package)s/%(spec)s 2>&1" % {
108 'rpmdefs' : b.rpmbuild_opts(),
109 'package' : packagename,
112 # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
113 # java-sun conflicts with soprano-2.1.67-1.src
114 rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
116 for l in f.xreadlines():
119 b.log_line("rpmbuild: %s" % l.rstrip())
120 conflicting[m.group('name')] = 1
122 if len(conflicting) and not uninstall(conflicting, b):
123 chroot.run("rm -rf %s" % tmpdir)
125 b.log_line("no BuildConflicts found")
126 chroot.run("rm -rf %s" % tmpdir)
129 def install_br(r, b):
130 def get_missing_br(r, b):
131 # ignore internal rpm dependencies, see lib/rpmns.c for list
132 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)\(.*')
134 packagename = b.spec[:-5]
135 tmpdir = "/tmp/B.%s.%s/tmp" % (packagename, b.b_id[0:6])
136 chroot.run("install -m 700 -d %s" % tmpdir)
137 cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s rpm/packages/%(package)s/%(spec)s 2>&1" % {
139 'rpmdefs' : b.rpmbuild_opts(),
140 'package' : packagename,
143 f = chroot.popen(cmd)
144 rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by")
146 b.log_line("checking BR")
147 for l in f.xreadlines():
148 b.log_line("rpm: %s" % l.rstrip())
150 if m and not ignore_br.match(l):
151 needed[m.group('name')] = 1
153 chroot.run("rm -rf %s" % tmpdir)
156 needed = get_missing_br(r, b);
159 b.log_line("no BR needed")
163 for bre in needed.keys():
164 nbr = nbr + " " + re.escape(bre)
165 br = string.strip(nbr)
166 b.log_line("updating poldek cache...")
167 chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
168 # check conflicts in BRed packages
169 b.log_line("checking conflicting packages in BRed packages")
170 f = chroot.popen("poldek --test --test --noask --caplookup -Q -v --upgrade %s" % br, user = "root")
171 # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
172 # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
173 # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
174 rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
176 for l in f.xreadlines():
177 b.log_line("poldek: %s" % l.rstrip())
179 if m: conflicting[m.group('name')] = 1
181 if len(conflicting) == 0:
182 b.log_line("no conflicts found")
184 if not uninstall(conflicting, b):
187 # recheck BuildRequires since above uninstallation could remove some required deps
188 needed = get_missing_br(r, b);
191 b.log_line("no BR needed")
195 for bre in needed.keys():
196 nbr = nbr + " " + re.escape(bre)
197 br = string.strip(nbr)
199 b.log_line("installing BR: %s" % br)
200 res = chroot.run("poldek --noask --caplookup -Q -v --upgrade %s" % br,
204 b.log_line("error: BR installation failed")