]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/install.py
Uninstall BuildConflicting packages.
[projects/pld-builder.new.git] / PLD_Builder / install.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import re
4 import string
5 import StringIO
6
7 from config import config, init_conf
8 import chroot
9 import util
10 import log
11
12 hold = [
13     'dev',
14     'poldek',
15     'rpm-build',
16     'pdksh',
17     'coreutils'
18 ]
19
20 def close_killset(killset):
21     k = killset.keys()
22     rx = re.compile(r' marks ([^\s]+)-[^-]+-[^-]+$')
23     errors = ""
24     for p in k:
25         if p in hold:
26             del killset[p]
27             errors += "cannot remove %s because it's crucial\n" % p
28         else:
29             f = chroot.popen("poldek --noask --test --erase %s" % p, user = "root")
30             crucial = 0
31             e = []
32             for l in f.xreadlines():
33                 m = rx.search(l)
34                 if m:
35                     pkg = m.group(1)
36                     if pkg in hold:
37                         errors += "cannot remove %s because it's required " \
38                                   "by %s, that is crucial\n" % (p, pkg)
39                         crucial = 1
40                     e.append(pkg)
41             f.close()
42             if crucial:
43                 del killset[p]
44             else:
45                 for p in e:
46                     killset[p] = 2
47     return errors
48
49 def upgrade_from_batch(r, b):
50     f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
51     killset = {}
52     rx = re.compile(r' \(installed\) ([^\s]+)-[^-]+-[^-]+$')
53     for l in f.xreadlines():
54         m = rx.search(l)
55         if m: killset[m.group(1)] = 1
56     f.close()
57     if len(killset) != 0:
58         err = close_killset(killset)
59         if err != "":
60             util.append_to(b.logfile, err)
61             log.notice("cannot upgrade rpms")
62             return False
63         k = string.join(killset.keys())
64         if True:
65             b.log_line("upgrade requires removal of %s" % k)
66             res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root")
67             if res != 0:
68                 b.log_line("package removal failed")
69                 return False
70             else:
71                 b.log_line("packages removed sucessfuly")
72         else:
73             b.log_line("upgrade would need removal of %s" % k)
74             return False
75     b.log_line("upgrading packages")
76     logbuf = StringIO.StringIO()
77     res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile)
78     if res != 0:
79         b.log_line("package upgrade failed")
80         logbuf.close()
81         return False
82     logbuf.close()
83     return True
84
85 def uninstall(conflicting, b):
86     b.log_line("uninstalling conflicting packages")
87     err = close_killset(conflicting)
88     if err != "":
89         util.append_to(b.logfile, err)
90         b.log_line("error: conflicting packages uninstallation failed")
91         return False
92     else:
93         k = string.join(conflicting.keys())
94         b.log_line("removing %s" % k)
95         res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root")
96         if res != 0:
97             b.log_line("package removal failed")
98             return False
99     return True
100
101 def uninstall_self_conflict(b):
102     b.log_line("checking BuildConflict-ing packages")
103     rpmbuild_opt = "%s %s %s" % (b.target_string(), b.kernel_string(), b.bconds_string())
104     f = chroot.popen("cd rpm/SPECS; TMPDIR=%s rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %s %s 2>&1" \
105             % (tmpdir, config.nice, rpmbuild_opt, b.spec))
106     rx = re.compile(r".*conflicts with ([^\s]+-[^-]+-[^-]+)\.src$")
107     conflicting = {}
108     for l in f.xreadlines():
109         b.log_line("rpmbuild: %s" % l.rstrip())
110         m = rx.search(l)
111         if m: conflicting[m.group(1)] = 1
112     f.close()
113     if len(conflicting) == 0:
114         b.log_line("no BuildConflicts found")
115     else:
116         if not uninstall(conflicting):
117             return False
118     return True
119
120 def install_br(r, b):
121     # ignore internal rpm dependencies, see lib/rpmns.c for list
122     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)\(.*')
123
124     tmpdir = "/tmp/BR." + b.b_id[0:6]
125     chroot.run("install -m 700 -d %s" % tmpdir)
126     cmd = "cd rpm/SPECS; TMPDIR=%s rpmbuild --nobuild %s %s 2>&1" \
127                 % (tmpdir, b.bconds_string(), b.spec)
128     f = chroot.popen(cmd)
129     rx = re.compile(r"^\s*([^\s]+) .*is needed by")
130     needed = {}
131     b.log_line("checking BR")
132     for l in f.xreadlines():
133         b.log_line("rpm: %s" % l.rstrip())
134         m = rx.search(l)
135         if m and not ignore_br.match(l):
136             needed[m.group(1)] = 1
137     f.close()
138     chroot.run("rm -rf %s" % tmpdir)
139     if len(needed) == 0:
140         b.log_line("no BR needed")
141         return
142     nbr = ""
143     for bre in needed.keys():
144         nbr = nbr + " " + re.escape(bre)
145     br = string.strip(nbr)
146     b.log_line("updating poldek cache...")
147     chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
148     # check conflicts in BRed packages
149     b.log_line("checking conflicting packages in BRed packages")
150     f = chroot.popen("poldek --test --noask --caplookup -Q -v --upgrade %s" % br, user = "root")
151     rx = re.compile(r".*conflicts with installed ([^\s]+)-[^-]+-[^-]+$")
152     conflicting = {}
153     for l in f.xreadlines():
154         b.log_line("poldek: %s" % l.rstrip())
155         m = rx.search(l)
156         if m: conflicting[m.group(1)] = 1
157     f.close()
158     if len(conflicting) == 0:
159         b.log_line("no conflicts found")
160     else:
161         if not uninstall(conflicting):
162             return False
163     b.log_line("installing BR: %s" % br)
164     res = chroot.run("poldek --noask --caplookup -Q -v --upgrade %s" % br,
165             user = "root",
166             logfile = b.logfile)
167     if res != 0:
168         b.log_line("error: BR installation failed")
169     return res
This page took 0.043041 seconds and 4 git commands to generate.