Browse Source

Merge pull request #231 from prannonpendragas/master

Update Sorting Function for Python3 sorted()
pull/232/head
Filip Pytloun 2 years ago
parent
commit
974c0d88d9
No account linked to committer's email address
2 changed files with 5 additions and 15 deletions
  1. +4
    -14
      _modules/linux_hosts.py
  2. +1
    -1
      linux/system/user.sls

+ 4
- 14
_modules/linux_hosts.py View File

@@ -9,22 +9,12 @@ from jinja2 import Undefined
def __virtual__():
return 'linux_hosts'

def fqdn_sort_fn(n1, n2):
l1 = n1.split('.')
l2 = n2.split('.')
if len(l1) > len(l2):
return -1
if len(l1) < len(l2):
return 1
for i1, i2 in zip(l1, l2):
if i1 < i2:
return -1
if i1 > i2:
return 1
return 0
def fqdn_sort_fn(n1):
length = len(n1)
return length

def fqdn_sort_filter(iterable):
if iterable is None or isinstance(iterable, Undefined):
return iterable
# Do effective custom sorting of iterable here
return sorted(set(iterable), cmp=fqdn_sort_fn)
return sorted(set(iterable), key=fqdn_sort_fn)

+ 1
- 1
linux/system/user.sls View File

@@ -49,7 +49,7 @@ system_user_{{ name }}:
{%- if user.gid is defined and user.gid %}
- gid: {{ user.gid }}
{%- else %}
- gid_from_name: true
- gid: {{ name }}
{%- endif %}
{%- if user.groups is defined %}
- groups: {{ user.groups }}

Loading…
Cancel
Save