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

def __virtual__(): def __virtual__():
return 'linux_hosts' 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): def fqdn_sort_filter(iterable):
if iterable is None or isinstance(iterable, Undefined): if iterable is None or isinstance(iterable, Undefined):
return iterable return iterable
# Do effective custom sorting of iterable here # 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

{%- if user.gid is defined and user.gid %} {%- if user.gid is defined and user.gid %}
- gid: {{ user.gid }} - gid: {{ user.gid }}
{%- else %} {%- else %}
- gid_from_name: true
- gid: {{ name }}
{%- endif %} {%- endif %}
{%- if user.groups is defined %} {%- if user.groups is defined %}
- groups: {{ user.groups }} - groups: {{ user.groups }}

Loading…
Cancel
Save