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