]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/install.py
add php 7.3
[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
73bdb36b 5import StringIO
deda9a51
MM
6
7import chroot
816ecd49 8import util
73bdb36b
AM
9import log
10
11hold = [
12 'dev',
13 'poldek',
14 'rpm-build',
ab9a0684 15 'pdksh',
98dc090c 16 'mksh',
73bdb36b
AM
17 'coreutils'
18]
19
20def close_killset(killset):
21 k = killset.keys()
feb26777
AM
22 if len(k) == 0:
23 return True
44e63f67 24 rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
73bdb36b
AM
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:
64dbb5be 31 f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
73bdb36b
AM
32 crucial = 0
33 e = []
34 for l in f.xreadlines():
35 m = rx.search(l)
36 if m:
44e63f67 37 pkg = m.group('name')
73bdb36b
AM
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
51def upgrade_from_batch(r, b):
52 f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
53 killset = {}
44e63f67 54 rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
73bdb36b
AM
55 for l in f.xreadlines():
56 m = rx.search(l)
44e63f67 57 if m: killset[m.group('name')] = 1
73bdb36b
AM
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")
7280b307 71 return False
73bdb36b
AM
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
deda9a51 86
301f3b7f
AM
87def 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:
7280b307
AM
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)
301f3b7f
AM
100 return True
101
102def uninstall_self_conflict(b):
103 b.log_line("checking BuildConflict-ing packages")
266325ca
ER
104 f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
105 "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
106 'tmpdir': b.tmpdir(),
4e14a9bc 107 'rpmdefs' : b.rpmbuild_opts(),
839f8b9f 108 'topdir' : b.get_topdir(),
4e14a9bc
ER
109 'spec': b.spec,
110 })
84c554a0
AM
111 # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
112 # java-sun conflicts with soprano-2.1.67-1.src
44e63f67 113 rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
301f3b7f
AM
114 conflicting = {}
115 for l in f.xreadlines():
301f3b7f 116 m = rx.search(l)
acc796cd
AM
117 if m:
118 b.log_line("rpmbuild: %s" % l.rstrip())
44e63f67 119 conflicting[m.group('name')] = 1
301f3b7f 120 f.close()
7fe3e937 121 if len(conflicting) and not uninstall(conflicting, b):
feb26777
AM
122 return False
123 b.log_line("no BuildConflicts found")
301f3b7f
AM
124 return True
125
deda9a51 126def install_br(r, b):
638f3c7d
AM
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
266325ca 131 tmpdir = b.tmpdir()
266325ca 132 cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
4e14a9bc 133 'tmpdir': tmpdir,
839f8b9f 134 'topdir' : b.get_topdir(),
4e14a9bc 135 'rpmdefs' : b.rpmbuild_opts(),
4e14a9bc
ER
136 'spec': b.spec,
137 }
638f3c7d
AM
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()
638f3c7d
AM
148 return needed
149
150 needed = get_missing_br(r, b);
83e50e5b 151
dfff8bd5
MM
152 if len(needed) == 0:
153 b.log_line("no BR needed")
feb26777 154 return True
638f3c7d 155
dfff8bd5
MM
156 nbr = ""
157 for bre in needed.keys():
158 nbr = nbr + " " + re.escape(bre)
159 br = string.strip(nbr)
caaac412 160 b.log_line("updating poldek cache...")
371eb1b9 161 chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
caaac412
AM
162 # check conflicts in BRed packages
163 b.log_line("checking conflicting packages in BRed packages")
bcc78cbf 164 f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root")
cc7a77b7 165 # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
e81b20ed 166 # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
3e45c3b6 167 # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
51deed6d 168 rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
caaac412
AM
169 conflicting = {}
170 for l in f.xreadlines():
05f294ad 171 b.log_line("poldek: %s" % l.rstrip())
caaac412 172 m = rx.search(l)
34226c1a 173 if m: conflicting[m.group('name')] = 1
caaac412
AM
174 f.close()
175 if len(conflicting) == 0:
176 b.log_line("no conflicts found")
177 else:
67a9d800 178 if not uninstall(conflicting, b):
301f3b7f 179 return False
638f3c7d
AM
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
e6376553 187
638f3c7d
AM
188 nbr = ""
189 for bre in needed.keys():
190 nbr = nbr + " " + re.escape(bre)
191 br = string.strip(nbr)
192
dfff8bd5 193 b.log_line("installing BR: %s" % br)
b95ea8fe 194 res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br),
caaac412
AM
195 user = "root",
196 logfile = b.logfile)
dfff8bd5
MM
197 if res != 0:
198 b.log_line("error: BR installation failed")
feb26777
AM
199 return False
200 return True
This page took 2.005295 seconds and 4 git commands to generate.