Skip to content

Commit

Permalink
Update py23 functions: cmp() and cmp=
Browse files Browse the repository at this point in the history
Change-Id: I9ab6dddbe62aa1f89cfd6f41fdf66cb9313e3499
  • Loading branch information
loocars committed Aug 12, 2019
1 parent c3c6ecf commit 9721ded
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
5 changes: 2 additions & 3 deletions checks/apache_status
Expand Up @@ -159,9 +159,8 @@ def check_apache_status(item, params, info):
perfdata = []

# Sort keys
data.sort(cmp=lambda x, y: cmp(
_apache_status_fields.get(x[0], (0, None))[0],
_apache_status_fields.get(y[0], (0, None))[0]))
data.sort(key=functools.cmp_to_key(lambda x, y: (_apache_status_fields.get(x[0], (0, None))[
0] - _apache_status_fields.get(y[0], (0, None))[0])))

for key, value in data:
if key not in _apache_status_fields.keys():
Expand Down
8 changes: 5 additions & 3 deletions cmk/gui/availability.py
Expand Up @@ -26,6 +26,7 @@

import time
import os
import functools

import cmk.utils.defines as defines
import cmk.utils.paths
Expand Down Expand Up @@ -919,7 +920,7 @@ def compute_availability(what, av_rawdata, avoptions):

availability_table.append(availability_entry)

availability_table.sort(cmp=cmp_av_entry)
availability_table.sort(key=functools.cmp_to_key(cmp_av_entry))

# Apply filters
filtered_table = []
Expand Down Expand Up @@ -1062,7 +1063,7 @@ def compute_availability_groups(what, av_data, avoptions):
else:
title = group_titles.get(group_id, group_id)
titled_groups.append((title, group_id)) ## ACHTUNG
titled_groups.sort(cmp=lambda a, b: cmp(a[1], b[1]))
titled_groups.sort(key=functools.cmp_to_key(lambda a, b: (a[1] - b[1])))

# 3. Loop over all groups and render them
for title, group_id in titled_groups:
Expand Down Expand Up @@ -2040,7 +2041,8 @@ def cmp_av_entry(a, b):
import cmk.gui.plugins.views # pylint: disable=redefined-outer-name
return utils.cmp_num_split(a["site"], b["site"]) or \
utils.cmp_num_split(a["host"], b["host"]) or \
cmp(cmk.gui.plugins.views.cmp_service_name_equiv(a["service"]),
(cmk.gui.plugins.views.cmp_service_name_equiv(a["service"]) >
cmk.gui.plugins.views.cmp_service_name_equiv(b["service"])) - (cmk.gui.plugins.views.cmp_service_name_equiv(a["service"]) <
cmk.gui.plugins.views.cmp_service_name_equiv(b["service"])) or \
utils.cmp_num_split(a["service"], b["service"])

Expand Down
2 changes: 1 addition & 1 deletion cmk/gui/config.py
Expand Up @@ -1010,7 +1010,7 @@ def sorted_sites():
sorted_choices = []
for site_id, s in user.authorized_sites():
sorted_choices.append((site_id, s['alias']))
return sorted(sorted_choices, key=lambda k: k[1], cmp=lambda a, b: cmp(a.lower(), b.lower()))
return sorted(sorted_choices, key=lambda k: k[1].lower())


def site(site_id):
Expand Down
3 changes: 2 additions & 1 deletion cmk_base/config.py
Expand Up @@ -35,6 +35,7 @@
import struct
import sys
import itertools
import functools
from typing import Pattern, Iterable, Set, Text, Any, Callable, Dict, List, Tuple, Union, Optional # pylint: disable=unused-import

from pathlib2 import Path
Expand Down Expand Up @@ -275,7 +276,7 @@ def _get_config_file_paths(with_conf_d):
list_of_files = [Path(cmk.utils.paths.main_config_file)]
if with_conf_d:
list_of_files += sorted(Path(cmk.utils.paths.check_mk_config_dir).glob("**/*.mk"),
cmp=cmk.utils.cmp_config_paths)
key=functools.cmp_to_key(cmk.utils.cmp_config_paths))
for path in [Path(cmk.utils.paths.final_config_file), Path(cmk.utils.paths.local_config_file)]:
if path.exists():
list_of_files.append(path)
Expand Down
12 changes: 7 additions & 5 deletions cmk_base/snmp.py
Expand Up @@ -26,6 +26,7 @@

import os
import subprocess
import functools
from typing import Tuple, Optional, Any, Dict, List # pylint: disable=unused-import

import cmk.utils.debug
Expand Down Expand Up @@ -401,7 +402,7 @@ def _compare_oids(self, a, b):
if len(aa) <= len(bb) and bb[:len(aa)] == aa:
result = 0
else:
result = cmp(aa, bb)
result = (aa > bb) - (aa < bb)
return result

def _to_bin_string(self, oid):
Expand Down Expand Up @@ -510,11 +511,12 @@ def _oid_to_intlist(oid):


def _cmp_oids(o1, o2):
return cmp(_oid_to_intlist(o1), _oid_to_intlist(o2))
return (_oid_to_intlist(o1) > _oid_to_intlist(o2)) - (_oid_to_intlist(o1) < _oid_to_intlist(o2))


def _cmp_oid_pairs(pair1, pair2):
return cmp(_oid_to_intlist(pair1[0].lstrip('.')), _oid_to_intlist(pair2[0].lstrip('.')))
return (_oid_to_intlist(pair1[0].lstrip('.')) > _oid_to_intlist(pair2[0].lstrip('.'))) - (
_oid_to_intlist(pair1[0].lstrip('.')) < _oid_to_intlist(pair2[0].lstrip('.')))


def _snmpv3_contexts_of(snmp_config, check_plugin_name):
Expand Down Expand Up @@ -635,7 +637,7 @@ def _sanitize_snmp_table_columns(columns):
# The list needs to be sorted to prevent problems when the first
# column has missing values in the middle of the tree.
if not _are_ascending_oids(endoids):
endoids.sort(cmp=_cmp_oids)
endoids.sort(key=functools.cmp_to_key(_cmp_oids))
need_sort = True
else:
need_sort = False
Expand All @@ -647,7 +649,7 @@ def _sanitize_snmp_table_columns(columns):
# it comparable to the already sorted endoids list. Otherwise we would get
# some mixups when filling gaps
if need_sort:
column.sort(cmp=_cmp_oid_pairs)
column.sort(key=functools.cmp_to_key(_cmp_oid_pairs))

i = 0
new_column = []
Expand Down

0 comments on commit 9721ded

Please sign in to comment.