affichage plus joli d'un switch
This commit is contained in:
parent
d54b811ac9
commit
1edd471ecb
1 changed files with 12 additions and 9 deletions
|
@ -33,6 +33,7 @@ import gestion.annuaires_pg as annuaire
|
||||||
import gestion.config as config
|
import gestion.config as config
|
||||||
import lc_ldap.objets as ldap_classes
|
import lc_ldap.objets as ldap_classes
|
||||||
from gestion.hptools import snmp
|
from gestion.hptools import snmp
|
||||||
|
import gestion.config.encoding as enc
|
||||||
|
|
||||||
GIGABIT_MODELS = ['J9021A', 'J9145A']
|
GIGABIT_MODELS = ['J9021A', 'J9145A']
|
||||||
|
|
||||||
|
@ -40,9 +41,9 @@ MIB_PRISE_VLAN = 'SNMPv2-SMI::enterprises.11.2.14.11.5.1.7.1.15.3.1.1'
|
||||||
MIB_PRISE_MAC = 'SNMPv2-SMI::enterprises.11.2.14.11.5.1.9.4.2'
|
MIB_PRISE_MAC = 'SNMPv2-SMI::enterprises.11.2.14.11.5.1.9.4.2'
|
||||||
|
|
||||||
# Blocs verticaux pour ascii art des prises d'un switch
|
# Blocs verticaux pour ascii art des prises d'un switch
|
||||||
START_BLOCK = [u'', u'┌', u'│', u'│', u'├', u'│', u'│', u'└', u'']
|
START_BLOCK = [u' ', u'┌', u'│', u'│', u'├', u'│', u'│', u'└', u' ']
|
||||||
MIDDLE_BLOCK = [u'', u'┬', u'│', u'│', u'┼', u'│', u'│', u'┴', u'']
|
MIDDLE_BLOCK = [u' ', u'┬', u'│', u'│', u'┼', u'│', u'│', u'┴', u' ']
|
||||||
END_BLOCK = [u'', u'\u2510', u'│', u'│', u'\u2524', u'│', u'│', u'\u2518', u'']
|
END_BLOCK = [u' ', u'┐', u'│', u'│', u'┤', u'│', u'│', u'┘', u' ']
|
||||||
|
|
||||||
ldap = make_ldap_conn()
|
ldap = make_ldap_conn()
|
||||||
|
|
||||||
|
@ -393,10 +394,12 @@ def format_prises_group(data, first, last):
|
||||||
first = (first-1)/2*2+1
|
first = (first-1)/2*2+1
|
||||||
last = (-last/2)*-2
|
last = (-last/2)*-2
|
||||||
|
|
||||||
def align5(txt):
|
def align5(txt, right=False):
|
||||||
"""Aligne le texte en limitant à 5 char"""
|
"""Aligne le texte en limitant à 5 char"""
|
||||||
if len(txt) > 5:
|
if len(txt) > 5:
|
||||||
return txt[0:4] + u'*'
|
return txt[0:4] + u'*'
|
||||||
|
if right:
|
||||||
|
return (5-len(txt))*u' ' + txt
|
||||||
return txt + (5-len(txt))*u' '
|
return txt + (5-len(txt))*u' '
|
||||||
|
|
||||||
def align2x5(txt):
|
def align2x5(txt):
|
||||||
|
@ -413,7 +416,7 @@ def format_prises_group(data, first, last):
|
||||||
(txt1, txt2) = align2x5(txt)
|
(txt1, txt2) = align2x5(txt)
|
||||||
lines[i_info] += txt1
|
lines[i_info] += txt1
|
||||||
lines[i_info+1] += txt2
|
lines[i_info+1] += txt2
|
||||||
lines[i_prise] += u" " + align5(u"%d" % prise)
|
lines[i_prise] += align5(u"%d" % prise, right=(i_prise!=0))
|
||||||
|
|
||||||
sep = MIDDLE_BLOCK
|
sep = MIDDLE_BLOCK
|
||||||
for prise in xrange(first, last, 2):
|
for prise in xrange(first, last, 2):
|
||||||
|
@ -423,7 +426,7 @@ def format_prises_group(data, first, last):
|
||||||
fill_prise(prise+1, -4, -1)
|
fill_prise(prise+1, -4, -1)
|
||||||
if prise == last -1:
|
if prise == last -1:
|
||||||
sep = END_BLOCK
|
sep = END_BLOCK
|
||||||
for line_i in xrange(1, 8):
|
for line_i in xrange(0, 9):
|
||||||
lines[line_i] += sep[line_i]
|
lines[line_i] += sep[line_i]
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
@ -438,9 +441,9 @@ def pretty_print(hostname):
|
||||||
|
|
||||||
first = 1
|
first = 1
|
||||||
while first < total:
|
while first < total:
|
||||||
for line in format_prises_group(port_dict, first, min(first+11, total)):
|
for line in format_prises_group(port_dict, first, min(first+60, total)):
|
||||||
print(line)
|
print(line.encode(enc.out_encoding))
|
||||||
first += 12
|
first += 61
|
||||||
|
|
||||||
def get_bat_num(hostname):
|
def get_bat_num(hostname):
|
||||||
"""Renvoie un tuple (bat, num) où bat est la lettre du bâtiment et
|
"""Renvoie un tuple (bat, num) où bat est la lettre du bâtiment et
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue