Sfoglia il codice sorgente

Merge pull request #231 from prannonpendragas/master

Update Sorting Function for Python3 sorted()
pull/232/head
Filip Pytloun 2 anni fa
parent
commit
974c0d88d9
Nessun account collegato all'indirizzo email del committer
2 ha cambiato i file con 5 aggiunte e 15 eliminazioni
  1. +4
    -14
      _modules/linux_hosts.py
  2. +1
    -1
      linux/system/user.sls

+ 4
- 14
_modules/linux_hosts.py Vedi 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 Vedi 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…
Annulla
Salva