]> git.pld-linux.org Git - projects/pld-builder.new.git/blobdiff - PLD_Builder/rpm_builder.py
Try fully preventing network access for rpmbuild.
[projects/pld-builder.new.git] / PLD_Builder / rpm_builder.py
index 2f70951312e6e98157bf7b7f94d8ce1fecac5071..7565c699c556cefc00be3c88ff0a9b914ebb42bb 100644 (file)
@@ -8,13 +8,15 @@ import atexit
 import time
 import datetime
 import string
-import urllib
-import urllib2
+import urllib.request
+import urllib.parse
+import urllib.error
 
 from config import config, init_conf
 from bqueue import B_Queue
 import lock
 import util
+import shutil
 import loop
 import path
 import status
@@ -46,12 +48,12 @@ def pick_request(q):
     def mycmp(r1, r2):
         if r1.kind != 'group' or r2.kind != 'group':
             raise Exception("non-group requests")
-        pri_diff = cmp(r1.priority, r2.priority)
+        pri_diff = util.cmp(r1.priority, r2.priority)
         if pri_diff == 0:
-            return cmp(r1.time, r2.time)
+            return util.cmp(r1.time, r2.time)
         else:
             return pri_diff
-    q.requests.sort(mycmp)
+    q.requests.sort(key=util.cmp_to_key(mycmp))
     ret = q.requests[0]
     return ret
 
@@ -62,12 +64,12 @@ def check_skip_build(r, b):
     while not good:
         try:
             headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-            req = urllib2.Request(url=src_url, headers=headers)
-            f = urllib2.urlopen(req)
+            req = urllib.request.Request(url=src_url, headers=headers)
+            f = urllib.request.urlopen(req)
             good = True
-        except urllib2.HTTPError as error:
+        except urllib.error.HTTPError as error:
             return False
-        except urllib2.URLError as error:
+        except urllib.error.URLError as error:
             # see errno.h
             try:
                 errno = error.errno
@@ -85,17 +87,17 @@ def check_skip_build(r, b):
     return False
 
 def fetch_src(r, b):
-    src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.quote(b.src_rpm)
+    src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.parse.quote(b.src_rpm)
     b.log_line("fetching %s" % src_url)
     start = time.time()
     good = False
     while not good:
         try:
             headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-            req = urllib2.Request(url=src_url, headers=headers)
-            f = urllib2.urlopen(req)
+            req = urllib.request.Request(url=src_url, headers=headers)
+            f = urllib.request.urlopen(req)
             good = True
-        except urllib2.HTTPError as error:
+        except urllib.error.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)
@@ -107,7 +109,7 @@ def fetch_src(r, b):
                 msg = "in queue for more than 6 hours, download failing"
                 b.log_line(msg)
                 return False
-        except urllib2.URLError as error:
+        except urllib.error.URLError as error:
             errno = 0
             if isinstance(error.args[0], IOError):
                 errno = error.args[0].errno
@@ -129,11 +131,12 @@ def fetch_src(r, b):
     o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
 
     try:
-        bytes = util.sendfile(f, o)
+        shutil.copyfileobj(f, o)
     except IOError as e:
         b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e))
         raise
 
+    bytes = float(f.headers['content-length'])
     f.close()
     o.close()
     t = time.time() - start
@@ -236,7 +239,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 '_make_opts -Otarget' --define '_pld_builder 1' %(rpmdefs)s %(topdir)s/%(spec)s" % {
+                    "unshare -n -c rpmbuild -bb --define '__jobs %(max_jobs)d' --define '_smp_mflags -j%(max_jobs)d' --define '_make_opts -Otarget' --define '_pld_builder 1' %(rpmdefs)s %(topdir)s/%(spec)s" % {
                     'r_id' : r.id,
                     'tmpdir': tmpdir,
                     'nice' : config.nice,
@@ -283,7 +286,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),
+                        (' '.join(b.files), rpm_cache_dir, rpm_cache_dir),
                      logfile = b.logfile, user = "root"
             )
         else:
This page took 0.133711 seconds and 4 git commands to generate.