]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/install.py
Make sure filter and map results are always lists (not true in py3 :/)
[projects/pld-builder.new.git] / PLD_Builder / install.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
508a95ef 3import re, os
deda9a51 4import string
308677c3
JR
5if sys.version_info[0] == 2:
6 import StringIO
7else:
8 from io import StringIO
deda9a51
MM
9
10import chroot
816ecd49 11import util
73bdb36b
AM
12import log
13
14hold = [
15 'dev',
16 'poldek',
17 'rpm-build',
98dc090c 18 'mksh',
15933860
AM
19 'coreutils',
20 'util-linux'
73bdb36b
AM
21]
22
23def close_killset(killset):
24 k = killset.keys()
feb26777
AM
25 if len(k) == 0:
26 return True
44e63f67 27 rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
73bdb36b
AM
28 errors = ""
29 for p in k:
30 if p in hold:
31 del killset[p]
32 errors += "cannot remove %s because it's crucial\n" % p
33 else:
64dbb5be 34 f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
73bdb36b
AM
35 crucial = 0
36 e = []
8b63d7eb 37 for l in f:
73bdb36b
AM
38 m = rx.search(l)
39 if m:
44e63f67 40 pkg = m.group('name')
73bdb36b
AM
41 if pkg in hold:
42 errors += "cannot remove %s because it's required " \
43 "by %s, that is crucial\n" % (p, pkg)
44 crucial = 1
45 e.append(pkg)
46 f.close()
47 if crucial:
48 del killset[p]
49 else:
50 for p in e:
51 killset[p] = 2
52 return errors
53
54def upgrade_from_batch(r, b):
55 f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
56 killset = {}
44e63f67 57 rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
8b63d7eb 58 for l in f:
73bdb36b 59 m = rx.search(l)
44e63f67 60 if m: killset[m.group('name')] = 1
73bdb36b
AM
61 f.close()
62 if len(killset) != 0:
63 err = close_killset(killset)
64 if err != "":
65 util.append_to(b.logfile, err)
66 log.notice("cannot upgrade rpms")
67 return False
68 k = string.join(killset.keys())
69 if True:
70 b.log_line("upgrade requires removal of %s" % k)
71 res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root")
72 if res != 0:
73 b.log_line("package removal failed")
7280b307 74 return False
73bdb36b
AM
75 else:
76 b.log_line("packages removed sucessfuly")
77 else:
78 b.log_line("upgrade would need removal of %s" % k)
79 return False
80 b.log_line("upgrading packages")
81 logbuf = StringIO.StringIO()
82 res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile)
83 if res != 0:
84 b.log_line("package upgrade failed")
85 logbuf.close()
86 return False
87 logbuf.close()
88 return True
deda9a51 89
301f3b7f
AM
90def uninstall(conflicting, b):
91 b.log_line("uninstalling conflicting packages")
92 err = close_killset(conflicting)
93 if err != "":
94 util.append_to(b.logfile, err)
95 b.log_line("error: conflicting packages uninstallation failed")
96 return False
97 else:
7280b307
AM
98 for k in conflicting.keys():
99 b.log_line("removing %s" % k)
100 res = chroot.run("poldek --noask --erase %s" % k, logfile = b.logfile, user = "root")
101 if res != 0:
102 b.log_line("package %s removal failed" % k)
301f3b7f
AM
103 return True
104
105def uninstall_self_conflict(b):
106 b.log_line("checking BuildConflict-ing packages")
266325ca
ER
107 f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
108 "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
109 'tmpdir': b.tmpdir(),
4e14a9bc 110 'rpmdefs' : b.rpmbuild_opts(),
839f8b9f 111 'topdir' : b.get_topdir(),
4e14a9bc
ER
112 'spec': b.spec,
113 })
84c554a0
AM
114 # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
115 # java-sun conflicts with soprano-2.1.67-1.src
44e63f67 116 rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
301f3b7f 117 conflicting = {}
8b63d7eb 118 for l in f:
301f3b7f 119 m = rx.search(l)
acc796cd
AM
120 if m:
121 b.log_line("rpmbuild: %s" % l.rstrip())
44e63f67 122 conflicting[m.group('name')] = 1
301f3b7f 123 f.close()
7fe3e937 124 if len(conflicting) and not uninstall(conflicting, b):
feb26777
AM
125 return False
126 b.log_line("no BuildConflicts found")
301f3b7f
AM
127 return True
128
deda9a51 129def install_br(r, b):
638f3c7d
AM
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)\(.*')
133
266325ca 134 tmpdir = b.tmpdir()
266325ca 135 cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
4e14a9bc 136 'tmpdir': tmpdir,
839f8b9f 137 'topdir' : b.get_topdir(),
4e14a9bc 138 'rpmdefs' : b.rpmbuild_opts(),
4e14a9bc
ER
139 'spec': b.spec,
140 }
638f3c7d
AM
141 f = chroot.popen(cmd)
142 rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by")
143 needed = {}
144 b.log_line("checking BR")
8b63d7eb 145 for l in f:
638f3c7d
AM
146 b.log_line("rpm: %s" % l.rstrip())
147 m = rx.search(l)
148 if m and not ignore_br.match(l):
149 needed[m.group('name')] = 1
150 f.close()
638f3c7d
AM
151 return needed
152
153 needed = get_missing_br(r, b);
83e50e5b 154
dfff8bd5
MM
155 if len(needed) == 0:
156 b.log_line("no BR needed")
feb26777 157 return True
638f3c7d 158
dfff8bd5
MM
159 nbr = ""
160 for bre in needed.keys():
161 nbr = nbr + " " + re.escape(bre)
162 br = string.strip(nbr)
caaac412 163 b.log_line("updating poldek cache...")
371eb1b9 164 chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
caaac412
AM
165 # check conflicts in BRed packages
166 b.log_line("checking conflicting packages in BRed packages")
bcc78cbf 167 f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root")
cc7a77b7 168 # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
e81b20ed 169 # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
3e45c3b6 170 # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
51deed6d 171 rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
caaac412 172 conflicting = {}
8b63d7eb 173 for l in f:
05f294ad 174 b.log_line("poldek: %s" % l.rstrip())
caaac412 175 m = rx.search(l)
34226c1a 176 if m: conflicting[m.group('name')] = 1
caaac412
AM
177 f.close()
178 if len(conflicting) == 0:
179 b.log_line("no conflicts found")
180 else:
67a9d800 181 if not uninstall(conflicting, b):
301f3b7f 182 return False
638f3c7d
AM
183
184 # recheck BuildRequires since above uninstallation could remove some required deps
185 needed = get_missing_br(r, b);
186
187 if len(needed) == 0:
188 b.log_line("no BR needed")
189 return True
e6376553 190
638f3c7d
AM
191 nbr = ""
192 for bre in needed.keys():
193 nbr = nbr + " " + re.escape(bre)
194 br = string.strip(nbr)
195
dfff8bd5 196 b.log_line("installing BR: %s" % br)
b95ea8fe 197 res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br),
caaac412
AM
198 user = "root",
199 logfile = b.logfile)
dfff8bd5
MM
200 if res != 0:
201 b.log_line("error: BR installation failed")
feb26777
AM
202 return False
203 return True
This page took 1.584021 seconds and 4 git commands to generate.