summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-04-15 09:02:23 +0200
committerChristian Poessinger <christian@poessinger.com>2021-04-17 21:19:15 +0200
commitebece7a4cdb942ea1ff7582ceda0f8765c329c9b (patch)
treea07bc9f0888c3dd79a1b1ed9477d6434a0be0143 /python
parent837929297855034e4bea339ae5081c68daa4d6cb (diff)
downloadvyos-1x-ebece7a4cdb942ea1ff7582ceda0f8765c329c9b.tar.gz
vyos-1x-ebece7a4cdb942ea1ff7582ceda0f8765c329c9b.zip
policy: T2425: re-implement "policy" tree from vyatta-cfg-quagga in XML/Python
Diffstat (limited to 'python')
-rw-r--r--python/vyos/template.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 7810f5edd..3fbb33acb 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -346,3 +346,18 @@ def get_dhcp_router(interface):
if 'option routers' in line:
(_, _, address) = line.split()
return address.rstrip(';')
+
+@register_filter('natural_sort')
+def natural_sort(iterable):
+ import re
+ from jinja2.runtime import Undefined
+
+ if isinstance(iterable, Undefined) or iterable is None:
+ return list()
+
+ def convert(text):
+ return int(text) if text.isdigit() else text.lower()
+ def alphanum_key(key):
+ return [convert(c) for c in re.split('([0-9]+)', str(key))]
+
+ return sorted(iterable, key=alphanum_key)