]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/rpm_builder.py
- more python 3.x fixes
[tld-builder.git] / TLD_Builder / rpm_builder.py
index a2ec562045c3433bf7a113b1869277ddbdb883e5..4c4bf1f7271cf363cdc07618022f9aecd61ecb5b 100644 (file)
@@ -1,5 +1,7 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
+from __future__ import print_function
+
 import sys
 import os
 import atexit
@@ -43,7 +45,7 @@ socket.socket=mysocket
 def pick_request(q):
     def mycmp(r1, r2):
         if r1.kind != 'group' or r2.kind != 'group':
-            raise Exception, "non-group requests"
+            raise Exception("non-group requests")
         pri_diff = cmp(r1.priority, r2.priority)
         if pri_diff == 0:
             return cmp(r1.time, r2.time)
@@ -63,9 +65,9 @@ def check_skip_build(r, b):
             req = urllib2.Request(url=src_url, headers=headers)
             f = urllib2.urlopen(req)
             good = True
-        except urllib2.HTTPError, error:
+        except urllib2.HTTPError as error:
             return False
-        except urllib2.URLError, error:
+        except urllib2.URLError as error:
             # see errno.h
             try:
                 errno = error.errno
@@ -93,19 +95,19 @@ def fetch_src(r, b):
             req = urllib2.Request(url=src_url, headers=headers)
             f = urllib2.urlopen(req)
             good = True
-        except urllib2.HTTPError, error:
+        except urllib2.HTTPError as error:
             # fail in a way where cron job will retry
             msg = "unable to fetch url %s, http code: %d" % (src_url, error.code)
             b.log_line(msg)
             queue_time = time.time() - r.time
             # 6 hours
             if error.code != 404 or (queue_time >= 0 and queue_time < (6 * 60 * 60)):
-                raise IOError, msg
+                raise IOError(msg)
             else:
                 msg = "in queue for more than 6 hours, download failing"
                 b.log_line(msg)
                 return False
-        except urllib2.URLError, error:
+        except urllib2.URLError as error:
             errno = 0
             if isinstance(error.args[0], IOError):
                 errno = error.args[0].errno
@@ -115,20 +117,20 @@ def fetch_src(r, b):
                 continue
             else:
                 try:
-                    print "error.errno: %s" % str(error.errno)
-                except Exception, e:
-                    print "error.errno: exception %s" % e
+                    print("error.errno: %s" % str(error.errno))
+                except Exception as e:
+                    print("error.errno: exception %s" % e)
                 try:
-                    print "error.reason %s" % str(error.reason)
-                except Exception, e:
-                    print "error.reason exception %s" % e
+                    print("error.reason %s" % str(error.reason))
+                except Exception as e:
+                    print("error.reason exception %s" % e)
                 raise
 
     o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
 
     try:
         bytes = util.sendfile(f, o)
-    except IOError, e:
+    except IOError as e:
         b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e))
         raise
 
@@ -180,6 +182,13 @@ def build_rpm(r, b):
         return res
 
     b.log_line("started at: %s" % time.asctime())
+
+    b.log_line("killing old processes on a builder")
+    chroot.run("/bin/kill --verbose -9 -1", logfile = b.logfile)
+
+    b.log_line("cleaning up /tmp")
+    chroot.run("rm -rf /tmp/B.*", logfile = b.logfile)
+
     fetch_src(r, b)
     b.log_line("installing srpm: %s" % b.src_rpm)
     res = chroot.run("""
@@ -227,7 +236,7 @@ def build_rpm(r, b):
                 if r.max_jobs > 0:
                     max_jobs = max(min(config.max_jobs, r.max_jobs), 1)
                 cmd = "set -ex; : build-id: %(r_id)s; TMPDIR=%(tmpdir)s exec nice -n %(nice)s " \
-                    "rpmbuild -bb --define '_smp_mflags -j%(max_jobs)d' --define '_tld_builder 1' %(rpmdefs)s %(topdir)s/%(spec)s" % {
+                    "rpmbuild -bb --define '_smp_mflags -j%(max_jobs)d' --define '_make_opts -Otarget' --define '_tld_builder 1' %(rpmdefs)s %(topdir)s/%(spec)s" % {
                     'r_id' : r.id,
                     'tmpdir': tmpdir,
                     'nice' : config.nice,
@@ -274,7 +283,7 @@ def build_rpm(r, b):
             b.log_line("copy rpm files to cache_dir: %s" % rpm_cache_dir)
             chroot.run(
                     "cp -f %s %s && poldek --mo=nodiff --mkidxz -s %s/" % \
-                        (string.join(b.files), rpm_cache_dir, rpm_cache_dir),
+                        (b.files.join(), rpm_cache_dir, rpm_cache_dir),
                      logfile = b.logfile, user = "root"
             )
         else:
@@ -329,7 +338,7 @@ def check_load():
     do_exit = 0
     try:
         f = open("/proc/loadavg")
-        if float(string.split(f.readline())[2]) > config.max_load:
+        if float(f.readline().split()[2]) > config.max_load:
             do_exit = 1
     except:
         pass
@@ -402,14 +411,14 @@ def main_for(builder):
     q.lock(0)
     q.read()
     previouslen=len(q.requests)
-    q.requests=filter(otherreqs, q.requests)
+    q.requests=list(filter(otherreqs, q.requests))
     if len(q.requests)<previouslen:
         q.write()
     q.unlock()
 
 def main():
     if len(sys.argv) < 2:
-        raise Exception, "fatal: need to have builder name as first arg"
+        raise Exception("fatal: need to have builder name as first arg")
     return main_for(sys.argv[1])
 
 if __name__ == '__main__':