From a3a66d4d86181735a72f766fa24fbb5d7d8de625 Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Wed, 27 Jun 2018 15:26:19 +0200 Subject: [PATCH] Convert remaing compare functions --- dak/control_suite.py | 5 +++-- dak/cruft_report.py | 8 ++++---- dak/queue_report.py | 11 ++++++----- dak/rm.py | 2 +- daklib/rm.py | 3 ++- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/dak/control_suite.py b/dak/control_suite.py index 88d10b21..c4d877a6 100755 --- a/dak/control_suite.py +++ b/dak/control_suite.py @@ -45,6 +45,7 @@ from __future__ import print_function import sys import apt_pkg +import functools import os from daklib.archive import ArchiveTransaction @@ -246,7 +247,7 @@ def set_suite(file, suite, transaction, britney=False, force=False): desired.add(tuple(split_line)) # Check to see which packages need added and add them - for key in sorted(desired, cmp=cmp_package_version): + for key in sorted(desired, cmp=functools.cmp_to_key(cmp_package_version)): if key not in current: (package, version, architecture) = key version_checks(package, architecture, suite.suite_name, version, session, force) @@ -299,7 +300,7 @@ def process_file(file, suite, action, transaction, britney=False, force=False): continue request.append(split_line) - request.sort(cmp=cmp_package_version) + request.sort(key=functools.cmp_to_key(cmp_package_version)) for package, version, architecture in request: pkg = get_pkg(package, version, architecture, session) diff --git a/dak/cruft_report.py b/dak/cruft_report.py index f8afb26f..eb806fce 100755 --- a/dak/cruft_report.py +++ b/dak/cruft_report.py @@ -116,7 +116,7 @@ def do_anais(architecture, binaries_list, source, session): version = i[1] if arch in architectures: versions.append(version) - versions.sort(apt_pkg.version_compare) + versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare)) if versions: latest_version = versions.pop() else: @@ -133,7 +133,7 @@ def do_anais(architecture, binaries_list, source, session): if versions_d != {}: anais_output += "\n (*) %s_%s [%s]: %s\n" % (binary, latest_version, source, architecture) versions = versions_d.keys() - versions.sort(apt_pkg.version_compare) + versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare)) for version in versions: arches = versions_d[version] arches.sort() @@ -326,7 +326,7 @@ def do_dubious_nbs(dubious_nbs): source_binaries.get(source, "(source does not exist)"))) print(" won't admit to building:") versions = dubious_nbs[source].keys() - versions.sort(apt_pkg.version_compare) + versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare)) for version in versions: packages = dubious_nbs[source][version].keys() packages.sort() @@ -679,7 +679,7 @@ def main(): for source in nbs.keys(): for package in nbs[source].keys(): versions = nbs[source][package].keys() - versions.sort(apt_pkg.version_compare) + versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare)) latest_version = versions.pop() source_version = source_versions.get(source, "0") if apt_pkg.version_compare(latest_version, source_version) == 0: diff --git a/dak/queue_report.py b/dak/queue_report.py index 7dce4cfe..e072daab 100755 --- a/dak/queue_report.py +++ b/dak/queue_report.py @@ -41,6 +41,7 @@ import sys import time import apt_pkg import datetime +import functools try: import rrdtool @@ -143,7 +144,7 @@ def sg_compare(a, b): return 1 # Sort by time of oldest upload - return cmp(a["oldest"], b["oldest"]) + return a["oldest"] - b["oldest"] ############################################################ @@ -405,7 +406,7 @@ def process_queue(queue, log, rrd_dir): per_source[source]["processed"] = "PENDING %s" % handler.get_action() total_pending += 1 per_source[source]["list"].append(upload) - per_source[source]["list"].sort(lambda x, y: cmp(x.changes.created, y.changes.created), reverse=True) + per_source[source]["list"].sort(key=lambda x: x.changes.created, reverse=True) # Determine oldest time and have note status for each source group for source in per_source.keys(): source_list = per_source[source]["list"] @@ -429,7 +430,7 @@ def process_queue(queue, log, rrd_dir): else: per_source[source]["note_state"] = 2 # all per_source_items = per_source.items() - per_source_items.sort(sg_compare) + per_source_items.sort(key=functools.cmp_to_key(sg_compare)) update_graph_database(rrd_dir, type, len(per_source_items), len(queue.uploads)) @@ -547,7 +548,7 @@ def process_queue(queue, log, rrd_dir): elif i == "nf": # Notes first. direction.append([5, -1, 0]) - entries.sort(sortfunc) + entries.sort(key=functools.cmp_to_key(sortfunc)) # Yes, in theory you can add several sort options at the commandline with. But my mind is to small # at the moment to come up with a real good sorting function that considers all the sidesteps you # have with it. (If you combine options it will simply take the last one at the moment). @@ -594,7 +595,7 @@ def process_queue(queue, log, rrd_dir): if "Queue-Report::Options::New" in Cnf: direction.append([6, 1, "ao"]) - entries.sort(sortfunc) + entries.sort(key=functools.cmp_to_key(sortfunc)) # Output for a html file. First table header. then table_footer. # Any line between them is then a printed from subroutine table_row. if len(entries) > 0: diff --git a/dak/rm.py b/dak/rm.py index 84dccc79..7c42d484 100755 --- a/dak/rm.py +++ b/dak/rm.py @@ -345,7 +345,7 @@ def main(): removals.sort() for package in removals: versions = d[package].keys() - versions.sort(apt_pkg.version_compare) + versions.sort(key=functools.cmp_to_key(apt_pkg.version_compare)) for version in versions: d[package][version].sort(key=utils.ArchKey) summary += "%10s | %10s | %s\n" % (package, version, ", ".join(d[package][version])) diff --git a/daklib/rm.py b/daklib/rm.py index 6bf186c2..0a705a45 100644 --- a/daklib/rm.py +++ b/daklib/rm.py @@ -44,6 +44,7 @@ from __future__ import absolute_import, print_function import commands import apt_pkg import fcntl +import functools import sqlalchemy.sql as sql from re import sub from collections import defaultdict @@ -400,7 +401,7 @@ def remove(session, reason, suites, removals, d[package][version].append(architecture) for package in sorted(d): - versions = sorted(d[package], cmp=apt_pkg.version_compare) + versions = sorted(d[package], key=functools.cmp_to_key(apt_pkg.version_compare)) for version in versions: d[package][version].sort(key=utils.ArchKey) summary += "%10s | %10s | %s\n" % (package, version, ", ".join(d[package][version])) -- GitLab