[projects/pld-builder.new] - more python 3.x fixes

hawk hawk at pld-linux.org
Mon Mar 22 23:49:55 CET 2021


commit 9366870d49b1070aa69bdc484b252a15656d9717
Author: Marcin Krol <mk at furud.net>
Date:   Mon Mar 22 23:49:23 2021 +0100

    - more python 3.x fixes

 PLD_Builder/bqueue.py          |  2 +-
 PLD_Builder/chroot.py          |  2 +-
 PLD_Builder/file_sender.py     |  3 ++-
 PLD_Builder/install.py         |  2 +-
 PLD_Builder/load_balancer.py   |  3 ++-
 PLD_Builder/mailer.py          |  2 +-
 PLD_Builder/notify.py          |  4 ++--
 PLD_Builder/pipeutil.py        |  4 ++--
 PLD_Builder/request_fetcher.py |  2 +-
 PLD_Builder/rpm_builder.py     |  2 +-
 PLD_Builder/srpm_builder.py    |  2 +-
 PLD_Builder/util.py            | 19 +++++++++++++++++++
 PLD_Builder/wrap.py            |  2 +-
 13 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index 3ab19c3..aaa249c 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -128,7 +128,7 @@ class B_Queue:
         fcntl.flock(self.fd, fcntl.LOCK_UN)
 
     def write_signed(self, name):
-        sio = StringIO.StringIO()
+        sio = StringIO()
         self._write_to(sio)
         sio.seek(0)
         sio.write(gpg.sign(sio.read()))
diff --git a/PLD_Builder/chroot.py b/PLD_Builder/chroot.py
index a489ac3..f91e1c6 100644
--- a/PLD_Builder/chroot.py
+++ b/PLD_Builder/chroot.py
@@ -49,7 +49,7 @@ def run(cmd, user = "builder", logfile = None, logstdout = None):
 
 def cp(file, outfile, user="builder", rm=False):
     m = md5()
-    m.update(str(random.sample(range(100000), 500)))
+    m.update(str(random.sample(range(100000), 500)).encode('utf-8'))
     digest = m.hexdigest()
 
     marker_start = "--- FILE BEGIN DIGEST %s ---" % digest
diff --git a/PLD_Builder/file_sender.py b/PLD_Builder/file_sender.py
index 933eedf..c6cc459 100644
--- a/PLD_Builder/file_sender.py
+++ b/PLD_Builder/file_sender.py
@@ -17,6 +17,7 @@ import log
 import loop
 import status
 import lock
+import util
 
 retries_times = [5 * 60, 5 * 60, 10 * 60, 10 * 60, 30 * 60, 60 * 60]
 
@@ -168,7 +169,7 @@ def flush_queue(dir):
             return cmp(x['Type'], y['Type'])
         else:
             return rc
-    q.sort(mycmp)
+    q.sort(key=util.cmp_to_key(mycmp))
 
     error = None
     # copy of q
diff --git a/PLD_Builder/install.py b/PLD_Builder/install.py
index f6f0719..edb4ae9 100644
--- a/PLD_Builder/install.py
+++ b/PLD_Builder/install.py
@@ -79,7 +79,7 @@ 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()
+    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")
diff --git a/PLD_Builder/load_balancer.py b/PLD_Builder/load_balancer.py
index 019c184..43d85d5 100644
--- a/PLD_Builder/load_balancer.py
+++ b/PLD_Builder/load_balancer.py
@@ -10,6 +10,7 @@ import log
 import status
 import lock
 import loop
+import util
 
 import rpm_builder
 
@@ -40,7 +41,7 @@ def builders_order():
     def mycmp(b1, b2):
         return cmp(bs[b1], bs[b2])
 
-    bl.sort(mycmp)
+    bl.sort(key=util.cmp_to_key(mycmp))
 
     f.seek(0)
     f.truncate(0)
diff --git a/PLD_Builder/mailer.py b/PLD_Builder/mailer.py
index 56a9f14..0c6ea27 100644
--- a/PLD_Builder/mailer.py
+++ b/PLD_Builder/mailer.py
@@ -21,7 +21,7 @@ def recode(s):
 class Message:
     def __init__(self):
         self.headers = {}
-        self.body = StringIO.StringIO()
+        self.body = StringIO()
         self.set_std_headers()
 
     def set_header(self, n, v):
diff --git a/PLD_Builder/notify.py b/PLD_Builder/notify.py
index ed5df8b..e13c052 100644
--- a/PLD_Builder/notify.py
+++ b/PLD_Builder/notify.py
@@ -14,12 +14,12 @@ from config import config
 
 class Notifier:
     def __init__(self, g):
-        self.xml = StringIO.StringIO()
+        self.xml = StringIO()
         self.xml.write("<notification group-id='%s' builder='%s'>\n" % \
                         (g.id, config.builder))
 
     def send(self, r):
-        sio = StringIO.StringIO()
+        sio = StringIO()
         self.xml.write("</notification>\n")
         self.xml.seek(0)
         sio.write(gpg.sign(self.xml.read()))
diff --git a/PLD_Builder/pipeutil.py b/PLD_Builder/pipeutil.py
index 9a3ca23..a3e78c9 100644
--- a/PLD_Builder/pipeutil.py
+++ b/PLD_Builder/pipeutil.py
@@ -9,9 +9,9 @@ else:
     from io import StringIO
 
 def rw_pipe(buf_, infd, outfd):
-    buf = StringIO.StringIO()
+    buf = StringIO()
     buf.write(buf_.read())
-    ret = StringIO.StringIO()
+    ret = StringIO()
     pos = 0
     rd_fin = 0
     wr_fin = 0
diff --git a/PLD_Builder/request_fetcher.py b/PLD_Builder/request_fetcher.py
index 609ec71..fc9f49d 100644
--- a/PLD_Builder/request_fetcher.py
+++ b/PLD_Builder/request_fetcher.py
@@ -73,7 +73,7 @@ def fetch_queue(control_url):
         signal.alarm(0)
         log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e))
         sys.exit(1)
-    sio = StringIO.StringIO()
+    sio = StringIO()
     util.sendfile(f, sio)
     f.close()
     sio.seek(0)
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index 59bd9ef..0126161 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -51,7 +51,7 @@ def pick_request(q):
             return 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
 
diff --git a/PLD_Builder/srpm_builder.py b/PLD_Builder/srpm_builder.py
index 2d75720..bee5f98 100644
--- a/PLD_Builder/srpm_builder.py
+++ b/PLD_Builder/srpm_builder.py
@@ -42,7 +42,7 @@ def pick_request(q):
             return 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]
     q.requests = q.requests[1:]
     return ret
diff --git a/PLD_Builder/util.py b/PLD_Builder/util.py
index 67bd9a1..05cf076 100644
--- a/PLD_Builder/util.py
+++ b/PLD_Builder/util.py
@@ -76,3 +76,22 @@ def find_last_section(log):
             last_section = m.group(1)
     f.close()
     return last_section
+
+def cmp_to_key(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K:
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) < 0
+        def __gt__(self, other):
+            return mycmp(self.obj, other.obj) > 0
+        def __eq__(self, other):
+            return mycmp(self.obj, other.obj) == 0
+        def __le__(self, other):
+            return mycmp(self.obj, other.obj) <= 0
+        def __ge__(self, other):
+            return mycmp(self.obj, other.obj) >= 0
+        def __ne__(self, other):
+            return mycmp(self.obj, other.obj) != 0
+    return K
diff --git a/PLD_Builder/wrap.py b/PLD_Builder/wrap.py
index 7391d4d..e343e16 100644
--- a/PLD_Builder/wrap.py
+++ b/PLD_Builder/wrap.py
@@ -48,7 +48,7 @@ def wrap(main):
         exctype, value = sys.exc_info()[:2]
         if exctype == SystemExit:
             sys.exit(value)
-        s = StringIO.StringIO()
+        s = StringIO()
         traceback.print_exc(file = s, limit = 20)
 
         log.alert("fatal python exception")
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/9366870d49b1070aa69bdc484b252a15656d9717



More information about the pld-cvs-commit mailing list