]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/install.py
- python3 raises error when dictionary is changed during loop
[tld-builder.git] / TLD_Builder / install.py
index f08a6b40937cf133f57f0e5575e91bab6bcdd691..c8eb5438075383f7b53555882222a353c4078680 100644 (file)
@@ -2,8 +2,8 @@
 
 import re, os
 import string
-import StringIO
-
+import sys
+from io import StringIO
 import chroot
 import util
 import log
@@ -12,9 +12,9 @@ hold = [
     'dev',
     'poldek',
     'rpm-build',
-    'pdksh',
     'mksh',
-    'coreutils'
+    'coreutils',
+    'util-linux'
 ]
 
 def close_killset(killset):
@@ -23,15 +23,15 @@ def close_killset(killset):
         return True
     rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
     errors = ""
-    for p in k:
+    for p in list(k):
         if p in hold:
             del killset[p]
             errors += "cannot remove %s because it's crucial\n" % p
         else:
-            f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
+            f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root", encoding = "utf-8")
             crucial = 0
             e = []
-            for l in f.xreadlines():
+            for l in f:
                 m = rx.search(l)
                 if m:
                     pkg = m.group('name')
@@ -49,10 +49,10 @@ def close_killset(killset):
     return errors
 
 def upgrade_from_batch(r, b):
-    f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
+    f = chroot.popen("rpm --test -F %s 2>&1" % ' '.join(b.files), user = "root", encoding = "utf-8")
     killset = {}
     rx = re.compile(r' \(installed\) (?P<name>[^\s]+)-[^-]+-[^-]+$')
-    for l in f.xreadlines():
+    for l in f:
         m = rx.search(l)
         if m: killset[m.group('name')] = 1
     f.close()
@@ -62,7 +62,7 @@ def upgrade_from_batch(r, b):
             util.append_to(b.logfile, err)
             log.notice("cannot upgrade rpms")
             return False
-        k = string.join(killset.keys())
+        k = ' '.join(killset.keys())
         if True:
             b.log_line("upgrade requires removal of %s" % k)
             res = chroot.run("rpm -e %s" % k, logfile = b.logfile, user = "root")
@@ -75,8 +75,8 @@ def upgrade_from_batch(r, b):
             b.log_line("upgrade would need removal of %s" % k)
             return False
     b.log_line("upgrading packages")
-    logbuf = StringIO.StringIO()
-    res = chroot.run("rpm -Fvh %s" % string.join(b.files), user = "root", logfile = b.logfile)
+    logbuf = StringIO()
+    res = chroot.run("rpm -Fvh %s" % ' '.join(b.files), user = "root", logfile = b.logfile)
     if res != 0:
         b.log_line("package upgrade failed")
         logbuf.close()
@@ -99,20 +99,38 @@ def uninstall(conflicting, b):
                 b.log_line("package %s removal failed" % k)
     return True
 
+def is_rpmorg():
+    f = chroot.popen("rpm --version 2>&1", encoding = "utf-8")
+    v = re.compile(r'(RPM version|rpm \(RPM\)) (?P<major>\d)\.(?P<minor>\d+)(\.\d+)?')
+    for l in f:
+        m = v.search(l)
+        if m:
+            major = int(m.group('major'))
+            minor = int(m.group('minor'))
+            if major == 4 and minor > 5:
+                f.close()
+                return True
+    f.close()
+    return False
+
 def uninstall_self_conflict(b):
     b.log_line("checking BuildConflict-ing packages")
-    f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
-        "rpmbuild -br --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
+    if is_rpmorg():
+        rpmcommand = "rpmbuild --nobuild -br"
+    else:
+        rpmcommand = "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0'"
+    f = chroot.popen("set -e; TMPDIR=%(tmpdir)s %(rpmcommand)s %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
+        'rpmcommand': rpmcommand,
         'tmpdir': b.tmpdir(),
         'rpmdefs' : b.rpmbuild_opts(),
         'topdir' : b.get_topdir(),
         'spec': b.spec,
-    })
+    }, encoding = "utf-8")
     # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
     # java-sun conflicts with soprano-2.1.67-1.src
     rx = re.compile(r"\s+(?P<name>[\w-]+)\s+.*conflicts with [^\s]+-[^-]+-[^-]+\.src($| .*)")
     conflicting = {}
-    for l in f.xreadlines():
+    for l in f:
         m = rx.search(l)
         if m:
             b.log_line("rpmbuild: %s" % l.rstrip())
@@ -129,17 +147,22 @@ def install_br(r, b):
         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)\(.*')
 
         tmpdir = b.tmpdir()
-        cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild -br --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
+        if is_rpmorg():
+            rpmcommand = "rpmbuild --nobuild -br"
+        else:
+            rpmcommand = "rpmbuild --nobuild"
+        cmd = "set -e; TMPDIR=%(tmpdir)s %(rpmcommand)s %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
+            'rpmcommand': rpmcommand,
             'tmpdir': tmpdir,
             'topdir' : b.get_topdir(),
             'rpmdefs' : b.rpmbuild_opts(),
             'spec': b.spec,
         }
-        f = chroot.popen(cmd)
+        f = chroot.popen(cmd, encoding = "utf-8")
         rx = re.compile(r"^\s*(?P<name>[^\s]+) .*is needed by")
         needed = {}
         b.log_line("checking BR")
-        for l in f.xreadlines():
+        for l in f:
             b.log_line("rpm: %s" % l.rstrip())
             m = rx.search(l)
             if m and not ignore_br.match(l):
@@ -156,18 +179,18 @@ def install_br(r, b):
     nbr = ""
     for bre in needed.keys():
         nbr = nbr + " " + re.escape(bre)
-    br = string.strip(nbr)
+    br = nbr.strip()
     b.log_line("updating poldek cache...")
     chroot.run("poldek --up --upa", user = "root", logfile = b.logfile)
     # check conflicts in BRed packages
     b.log_line("checking conflicting packages in BRed packages")
-    f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root")
+    f = chroot.popen("poldek --test --test --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br), user = "root", encoding = "utf-8")
     # phonon-devel-4.3.1-1.i686 conflicts with qt4-phonon-devel-4.5.0-6.i686
     # jdbc-stdext >= 2.0 is required by installed java-struts-1.3.10-1.noarch
     # jmx is needed by (installed) java-commons-modeler-2.0-1.noarch
     rx = re.compile(r".*(conflicts with|is required by|is needed by)( installed| \(installed\)|) (?P<name>[^\s]+)-[^-]+-[^-]+($| .*)")
     conflicting = {}
-    for l in f.xreadlines():
+    for l in f:
         b.log_line("poldek: %s" % l.rstrip())
         m = rx.search(l)
         if m: conflicting[m.group('name')] = 1
@@ -188,7 +211,7 @@ def install_br(r, b):
     nbr = ""
     for bre in needed.keys():
         nbr = nbr + " " + re.escape(bre)
-    br = string.strip(nbr)
+    br = nbr.strip()
 
     b.log_line("installing BR: %s" % br)
     res = chroot.run("set -x; poldek --noask --caplookup -Q -v %s --upgrade %s" % (b.ignores(), br),