]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/install.py
- merged PLD changes, now it works with python 3.x
[tld-builder.git] / TLD_Builder / install.py
index 0131e19403aac55f52815d8b348a1f6fb7259dfc..e57ad2a7fe41e1e6789729770d9add2760185f52 100644 (file)
@@ -2,7 +2,11 @@
 
 import re, os
 import string
-import StringIO
+import sys
+if sys.version_info[0] == 2:
+    import StringIO
+else:
+    from io import StringIO
 
 import chroot
 import util
@@ -12,9 +16,9 @@ hold = [
     'dev',
     'poldek',
     'rpm-build',
-    'pdksh',
     'mksh',
-    'coreutils'
+    'coreutils',
+    'util-linux'
 ]
 
 def close_killset(killset):
@@ -31,7 +35,7 @@ def close_killset(killset):
             f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root")
             crucial = 0
             e = []
-            for l in f.xreadlines():
+            for l in f:
                 m = rx.search(l)
                 if m:
                     pkg = m.group('name')
@@ -52,7 +56,7 @@ def upgrade_from_batch(r, b):
     f = chroot.popen("rpm --test -F %s 2>&1" % string.join(b.files), user = "root")
     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()
@@ -99,10 +103,28 @@ def uninstall(conflicting, b):
                 b.log_line("package %s removal failed" % k)
     return True
 
+def is_rpmorg():
+    f = chroot.popen("rpm --version 2>&1")
+    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 -bp --nobuild --short-circuit --define 'prep exit 0' %(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(),
@@ -112,7 +134,7 @@ def uninstall_self_conflict(b):
     # 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,7 +151,12 @@ 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 --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(),
@@ -139,7 +166,7 @@ def install_br(r, b):
         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):
@@ -167,7 +194,7 @@ def install_br(r, b):
     # 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