1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

kcc: fix sort for py3

py2:

    list.sort(cmp=None, key=None, reverse=False)
    sorted(iterable[, cmp[, key[, reverse]]])

py3:

    list.sort(key=None, reverse=False)
    sorted(iterable, *, key=None, reverse=False)

The `cmp` arg was removed in py3, make use of `key` arg to work around.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Joe Guo 2018-04-10 14:51:37 +12:00 committed by Douglas Bagnall
parent 949109442f
commit c7f3c91b62
2 changed files with 4 additions and 19 deletions

View File

@ -46,18 +46,6 @@ from samba.kcc.debug import DEBUG, DEBUG_FN, logger
from samba.kcc import debug
def sort_replica_by_dsa_guid(rep1, rep2):
"""Helper to sort NCReplicas by their DSA guids
The guids need to be sorted in their NDR form.
:param rep1: An NC replica
:param rep2: Another replica
:return: -1, 0, or 1, indicating sort order.
"""
return cmp(ndr_pack(rep1.rep_dsa_guid), ndr_pack(rep2.rep_dsa_guid))
def sort_dsa_by_gc_and_guid(dsa1, dsa2):
"""Helper to sort DSAs by guid global catalog status
@ -2194,7 +2182,7 @@ class KCC(object):
# on the local DC
r_list.append(l_of_x)
r_list.sort(sort_replica_by_dsa_guid)
r_list.sort(key=lambda rep: ndr_pack(rep.rep_dsa_guid))
r_len = len(r_list)
max_node_edges = self.intrasite_max_node_edges(r_len)

View File

@ -1581,7 +1581,9 @@ class Site(object):
# Which is a fancy way of saying "sort all the nTDSDSA objects
# in the site by guid in ascending order". Place sorted list
# in D_sort[]
D_sort = sorted(self.rw_dsa_table.values(), cmp=sort_dsa_by_guid)
D_sort = sorted(
self.rw_dsa_table.values(),
key=lambda dsa: ndr_pack(dsa.dsa_guid))
# double word number of 100 nanosecond intervals since 1600s
@ -2221,11 +2223,6 @@ def get_dsa_config_rep(dsa):
dsa.dsa_dnstr)
def sort_dsa_by_guid(dsa1, dsa2):
"use ndr_pack for GUID comparison, as appears correct in some places"""
return cmp(ndr_pack(dsa1.dsa_guid), ndr_pack(dsa2.dsa_guid))
def new_connection_schedule():
"""Create a default schedule for an NTDSConnection or Sitelink. This
is packed differently from the repltimes schedule used elsewhere