]> TLD Linux GIT Repositories - tld-builder.git/blob - TLD_Builder/install.py
- adjusted options for rpm.org RPM
[tld-builder.git] / TLD_Builder / install.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import re, os
4 import string
5 import StringIO
6
7 import chroot
8 import util
9 import log
10
11 hold = [
12     'dev',
13     'poldek',
14     'rpm-build',
15     'pdksh',
16     'mksh',
17     'coreutils'
18 ]
19
20 def close_killset(killset):
21     k = killset.keys()
22     if len(k) == 0:
23         return True
24     rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
25     errors = ""
26     for p in k:
27         if p in hold:
28             del killset[p]
29             errors += "cannot remove %s because it's crucial\n" % p
30         else:
31             f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
32             crucial = 0
33             e = []
34             for l in f.xreadlines():
35                 m = rx.search(l)
36                 if m:
37                     pkg = m.group('name')
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):
52     f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
53     killset = {}
54     rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
55     for l in f.xreadlines():
56         m = rx.search(l)
57         if m: killset[m.group('name')] = 1
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
65         k = string.join(killset.keys())
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")
71                 return False
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")
78     logbuf = StringIO.StringIO()
79     res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile)
80     if res != 0:
81         b.log_line("package upgrade failed")
82         logbuf.close()
83         return False
84     logbuf.close()
85     return True
86
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:
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)
100     return True
101
102 def uninstall_self_conflict(b):
103     b.log_line("checking BuildConflict-ing packages")
104     f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
105         "rpmbuild -br --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
106         'tmpdir': b.tmpdir(),
107         'rpmdefs' : b.rpmbuild_opts(),
108         'topdir' : b.get_topdir(),
109         'spec': b.spec,
110     })
111     # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
112     # java-sun conflicts with soprano-2.1.67-1.src
113     rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
114     conflicting = {}
115     for l in f.xreadlines():
116         m = rx.search(l)
117         if m:
118             b.log_line("rpmbuild: %s" % l.rstrip())
119             conflicting[m.group('name')] = 1
120     f.close()
121     if len(conflicting) and not uninstall(conflicting, b):
122         return False
123     b.log_line("no BuildConflicts found")
124     return True
125
126 def install_br(r, b):
127     def get_missing_br(r, b):
128         # ignore internal rpm dependencies, see lib/rpmns.c for list
129         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)\(.*')
130
131         tmpdir = b.tmpdir()
132         cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild -br --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
133             'tmpdir': tmpdir,
134             'topdir' : b.get_topdir(),
135             'rpmdefs' : b.rpmbuild_opts(),
136             'spec': b.spec,
137         }
138         f = chroot.popen(cmd)
139         rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by")
140         needed = {}
141         b.log_line("checking BR")
142         for l in f.xreadlines():
143             b.log_line("rpm: %s" % l.rstrip())
144             m = rx.search(l)
145             if m and not ignore_br.match(l):
146                 needed[m.group('name')] = 1
147         f.close()
148         return needed
149
150     needed = get_missing_br(r, b);
151
152     if len(needed) == 0:
153         b.log_line("no BR needed")
154         return True
155
156     nbr = ""
157     for bre in needed.keys():
158         nbr = nbr + " " + re.escape(bre)
159     br = string.strip(nbr)
160     b.log_line("updating poldek cache...")
161     chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
162     # check conflicts in BRed packages
163     b.log_line("checking conflicting packages in BRed packages")
164     f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root")
165     # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
166     # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
167     # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
168     rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
169     conflicting = {}
170     for l in f.xreadlines():
171         b.log_line("poldek: %s" % l.rstrip())
172         m = rx.search(l)
173         if m: conflicting[m.group('name')] = 1
174     f.close()
175     if len(conflicting) == 0:
176         b.log_line("no conflicts found")
177     else:
178         if not uninstall(conflicting, b):
179             return False
180
181     # recheck BuildRequires since above uninstallation could remove some required deps
182     needed = get_missing_br(r, b);
183
184     if len(needed) == 0:
185         b.log_line("no BR needed")
186         return True
187
188     nbr = ""
189     for bre in needed.keys():
190         nbr = nbr + " " + re.escape(bre)
191     br = string.strip(nbr)
192
193     b.log_line("installing BR: %s" % br)
194     res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br),
195             user = "root",
196             logfile = b.logfile)
197     if res != 0:
198         b.log_line("error: BR installation failed")
199         return False
200     return True