diff options
author | Andy Grover <agrover@redhat.com> | 2012-12-03 15:02:47 -0800 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2012-12-03 15:02:47 -0800 |
commit | 10ac93aacf7135ec0f5dda603790bcf51a7dde8d (patch) | |
tree | ccee8437bed883b67aa7535ab91d39c76726a1e7 /configshell | |
parent | f712d46ccaabcf7c9815da7a46dc0f5022222545 (diff) | |
download | configshell-fb-10ac93aacf7135ec0f5dda603790bcf51a7dde8d.tar.gz |
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 <agrover@redhat.com>
Diffstat (limited to 'configshell')
-rw-r--r-- | configshell/node.py | 10 |
1 files changed, 6 insertions, 4 deletions
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]: |