From d398d662985299e8548fda37f75fc8b0ffe7a10f Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Mon, 22 Mar 2021 23:28:40 +0100 Subject: [PATCH] - more python 3.x fixes --- TLD_Builder/file_sender.py | 3 ++- TLD_Builder/load_balancer.py | 3 ++- TLD_Builder/rpm_builder.py | 2 +- TLD_Builder/srpm_builder.py | 2 +- TLD_Builder/util.py | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/TLD_Builder/file_sender.py b/TLD_Builder/file_sender.py index 2a0c120..18ee8d8 100644 --- a/TLD_Builder/file_sender.py +++ b/TLD_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(key=mycmp) + q.sort(key=util.cmp_to_key(mycmp)) error = None # copy of q diff --git a/TLD_Builder/load_balancer.py b/TLD_Builder/load_balancer.py index 9560ed6..43d85d5 100644 --- a/TLD_Builder/load_balancer.py +++ b/TLD_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(key=mycmp) + bl.sort(key=util.cmp_to_key(mycmp)) f.seek(0) f.truncate(0) diff --git a/TLD_Builder/rpm_builder.py b/TLD_Builder/rpm_builder.py index 80677d5..239f5a3 100644 --- a/TLD_Builder/rpm_builder.py +++ b/TLD_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(key=mycmp) + q.requests.sort(key=util.cmp_to_key(mycmp)) ret = q.requests[0] return ret diff --git a/TLD_Builder/srpm_builder.py b/TLD_Builder/srpm_builder.py index 6b8ea54..11f793b 100644 --- a/TLD_Builder/srpm_builder.py +++ b/TLD_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(key=mycmp) + q.requests.sort(key=util.cmp_to_key(mycmp)) ret = q.requests[0] q.requests = q.requests[1:] return ret diff --git a/TLD_Builder/util.py b/TLD_Builder/util.py index 67bd9a1..05cf076 100644 --- a/TLD_Builder/util.py +++ b/TLD_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 -- 2.46.0