diff --git a/printing/templates.py b/printing/templates.py index f636071..e869e85 100644 --- a/printing/templates.py +++ b/printing/templates.py @@ -71,6 +71,21 @@ def telephone(l): tel.append(t) return tel +_ethercodes = None +def const_of_mac(mac): + global _ethercodes + if not _ethercodes: + _ethercodes = dict() + with open('/usr/scripts/gestion/ethercodes.dat', 'r') as f: + # Évite de mettre en RAM tout de suite, on utilise un itérateur + for line in iter(f.readline, ''): + line = line.split('\t\t') + _ethercodes[line[0][0:8].lower()] = line[-1].strip() + try: + return mac + u" (%s)" % _ethercodes[mac[0:8]] + except KeyError: + return mac + templateEnv=None def template(): global templateEnv @@ -87,6 +102,7 @@ def template(): templateEnv.filters['timeformat'] = timeformat templateEnv.filters['split'] = split templateEnv.filters['telephone'] = telephone + templateEnv.filters['const_of_mac'] = const_of_mac templateEnv.filters['tableau'] = tableau return templateEnv diff --git a/printing/templates/machine b/printing/templates/machine index 18e6855..eb35287 100644 --- a/printing/templates/machine +++ b/printing/templates/machine @@ -2,7 +2,7 @@ {% if o.hostAlias %} {{"Alias : "|coul('gras')}}{{o.hostAlias|join(', ')}} {% endif %} -{{"MAC : "|coul('gras')}}{{o.macAddress|join(', ')}} +{{"MAC : "|coul('gras')}}{{o.macAddress|join(', ')|const_of_mac}} {{"IPv4 : "|coul('gras')}}{{o.ipHostNumber|join(', ')}} {{"IPv6 : "|coul('gras')}}{{o.ip6HostNumber|join(', ')}} {{"DnsIpv6 : "|coul('gras')}}{% if not o.dnsIpv6 or o.dnsIpv6.0.value %}