whosthere: affichage plus conçu
This commit is contained in:
parent
ece940a52e
commit
f991a7c064
1 changed files with 36 additions and 5 deletions
|
@ -10,10 +10,11 @@ import collections
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
from gestion.ldap_crans import crans_ldap
|
from gestion.ldap_crans import crans_ldap, MachineWifi
|
||||||
from gestion.hptools import hpswitch, ConversationError
|
from gestion.hptools import hpswitch, ConversationError
|
||||||
from gestion.affich_tools import coul, cprint
|
from gestion.affich_tools import coul, cprint
|
||||||
from gestion.whos import aff
|
from gestion.whos import aff
|
||||||
|
import gestion.affichage as affichage
|
||||||
|
|
||||||
# Constantes pour munin.
|
# Constantes pour munin.
|
||||||
# L'ordre est important : il détermine comment sont empilées les valeurs
|
# L'ordre est important : il détermine comment sont empilées les valeurs
|
||||||
|
@ -29,6 +30,36 @@ STATE_DESCR = collections.OrderedDict([
|
||||||
CLUB_CRANS = 35
|
CLUB_CRANS = 35
|
||||||
CLUB_BDE = 1
|
CLUB_BDE = 1
|
||||||
|
|
||||||
|
def pretty_name(item):
|
||||||
|
v = ""
|
||||||
|
|
||||||
|
if hasattr(item, 'nom'):
|
||||||
|
v = item.nom()
|
||||||
|
if hasattr(item, 'prenom'):
|
||||||
|
v = item.prenom() + " " + v
|
||||||
|
v = v.replace('.wifi.crans.org', ' (WiFi)')
|
||||||
|
v = v.replace('.crans.org', '')
|
||||||
|
return v
|
||||||
|
|
||||||
|
def show_liste_by_prop(liste):
|
||||||
|
by_owner = dict()
|
||||||
|
|
||||||
|
for machine in liste:
|
||||||
|
# ldap_crans or lc_ldap
|
||||||
|
owner = (getattr(machine, 'proprietaire', None) or \
|
||||||
|
getattr(machine, 'proprio', None))()
|
||||||
|
if owner.dn not in by_owner:
|
||||||
|
by_owner[owner.dn] = [pretty_name(owner), []]
|
||||||
|
by_owner[owner.dn][1].append(pretty_name(machine))
|
||||||
|
|
||||||
|
for items in by_owner.itervalues():
|
||||||
|
items[1] = ", ".join(items[1])
|
||||||
|
print affichage.tableau(by_owner.values(), largeur=[None, '*'],
|
||||||
|
alignement=['g', 'g']).rstrip()
|
||||||
|
|
||||||
|
def show_liste(liste):
|
||||||
|
print ", ".join(pretty_name(m) for m in liste)
|
||||||
|
|
||||||
def _mucode(u):
|
def _mucode(u):
|
||||||
"""Sad but true: munin ne fait pas d'utf-8 …"""
|
"""Sad but true: munin ne fait pas d'utf-8 …"""
|
||||||
return u.encode('iso-8859-15', errors='ignore')
|
return u.encode('iso-8859-15', errors='ignore')
|
||||||
|
@ -120,7 +151,7 @@ class WhosThere(object):
|
||||||
current = self.query()
|
current = self.query()
|
||||||
if current['ma']:
|
if current['ma']:
|
||||||
cprint('---=== Machines des membres actifs ===---', 'bleu')
|
cprint('---=== Machines des membres actifs ===---', 'bleu')
|
||||||
aff(current['ma'])
|
show_liste_by_prop(current['ma'])
|
||||||
cprint("---=== Il y a du monde ===---", 'vert')
|
cprint("---=== Il y a du monde ===---", 'vert')
|
||||||
else:
|
else:
|
||||||
cprint("---=== Il semble n'y avoir personne ... ===---", 'rouge')
|
cprint("---=== Il semble n'y avoir personne ... ===---", 'rouge')
|
||||||
|
@ -128,13 +159,13 @@ class WhosThere(object):
|
||||||
cprint("Machine inconnue: %s" % mac, 'rouge')
|
cprint("Machine inconnue: %s" % mac, 'rouge')
|
||||||
if current['crans']:
|
if current['crans']:
|
||||||
cprint("---=== Machines Cr@ns ===---", 'bleu')
|
cprint("---=== Machines Cr@ns ===---", 'bleu')
|
||||||
aff(current['crans'])
|
show_liste(current['crans'])
|
||||||
if current['bde']:
|
if current['bde']:
|
||||||
cprint("---=== Machines du BDE ===---", 'bleu')
|
cprint("---=== Machines du BDE ===---", 'bleu')
|
||||||
aff(current['bde'])
|
show_liste(current['bde'])
|
||||||
if current['adh']:
|
if current['adh']:
|
||||||
cprint("---=== Machines d'adhérents ===---", 'bleu')
|
cprint("---=== Machines d'adhérents ===---", 'bleu')
|
||||||
aff(current['adh'])
|
show_liste_by_prop(current['adh'])
|
||||||
|
|
||||||
def munin_config(self):
|
def munin_config(self):
|
||||||
"""Donne la configuration du graphe munin"""
|
"""Donne la configuration du graphe munin"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue