Skip to content
Permalink
Browse files

Update py23 functions: cmp() and cmp=

Change-Id: I9ab6dddbe62aa1f89cfd6f41fdf66cb9313e3499
  • Loading branch information...
loocars committed Aug 5, 2019
1 parent c3c6ecf commit 9721ded153eefaf170fdc94e8b3c2e4e43b82aaf
Showing with 17 additions and 13 deletions.
  1. +2 −3 checks/apache_status
  2. +5 −3 cmk/gui/availability.py
  3. +1 −1 cmk/gui/config.py
  4. +2 −1 cmk_base/config.py
  5. +7 −5 cmk_base/snmp.py
@@ -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():
@@ -26,6 +26,7 @@

import time
import os
import functools

import cmk.utils.defines as defines
import cmk.utils.paths
@@ -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 = []
@@ -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:
@@ -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"])

@@ -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):
@@ -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
@@ -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)
@@ -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
@@ -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):
@@ -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):
@@ -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
@@ -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 = []

0 comments on commit 9721ded

Please sign in to comment.
You can’t perform that action at this time.