From 726420975dde811460e030a9ff7dc64454e3243d Mon Sep 17 00:00:00 2001 From: MANQUAT G Date: Sat, 13 Oct 2018 04:25:12 +0200 Subject: [PATCH] Resolve the issue on Alpine This resolve the issue #208 : This remove the "/" in the regex and order the server by only mean ping if the mean deviation is not present. --- openpyn/openpyn.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openpyn/openpyn.py b/openpyn/openpyn.py index 44e537e..cc5045a 100755 --- a/openpyn/openpyn.py +++ b/openpyn/openpyn.py @@ -530,7 +530,7 @@ def ping_servers(better_servers_list: List, pings: str, stats: bool) -> List: stdout=subprocess.PIPE) # pipe the output of ping to grep. ping_output = subprocess.check_output( - ["grep", "-B", "1", "min/avg/max/"], stdin=ping_proc.stdout) + ["grep", "-B", "1", "min/avg/max"], stdin=ping_proc.stdout) ping_string = str(ping_output) # logger.debug(ping_string) @@ -557,8 +557,12 @@ def ping_servers(better_servers_list: List, pings: str, stats: bool) -> List: ping_result.append(ping_list) # logger.debug(ping_result) pinged_servers_list.append(ping_result) - # sort by Ping Avg and Median Deviation - pinged_servers_list = sorted(pinged_servers_list, key=lambda item: (item[1][1], item[1][3])) + if len(pinged_servers_list[0][1]) >= 4: + # sort by Ping Avg and Median Deviation + pinged_servers_list = sorted(pinged_servers_list, key=lambda item: (item[1][1], item[1][3])) + else: + # sort by Ping Avg + pinged_servers_list = sorted(pinged_servers_list, key=lambda item: item[1][1]) return pinged_servers_list