From 10ac93aacf7135ec0f5dda603790bcf51a7dde8d Mon Sep 17 00:00:00 2001 From: Andy Grover Date: Mon, 3 Dec 2012 15:02:47 -0800 Subject: Fix sort again We actually want to sort by non-ending-numeric part first, and *then* sort by ending number. Signed-off-by: Andy Grover --- configshell/node.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'configshell') diff --git a/configshell/node.py b/configshell/node.py index b3fed50..a6f1046 100644 --- a/configshell/node.py +++ b/configshell/node.py @@ -801,13 +801,15 @@ class ConfigNode(object): else: summary += self.shell.con.render_text(']', styles=['bold']) - def ending_number(s): - m = re.search(r'\d+$', str(s)) + def sorting_keys(s): + m = re.search(r'(.*?)(\d+$)', str(s)) if m: - return int(m.group()) + return (m.group(1), int(m.group(2))) + else: + return (str(s), None) # sort by ending number, then alpha - children = sorted(root.children, key=lambda c: (ending_number(c), str(c))) + children = sorted(root.children, key=lambda c: sorting_keys(c)) line = "" for pipe in margin[:-1]: -- cgit v1.2.1