whosthere: proprification (PEP8 et cie)
This commit is contained in:
parent
6b64af3314
commit
6b63e030a6
1 changed files with 58 additions and 26 deletions
|
@ -5,16 +5,15 @@
|
|||
à des fins de perms, et cie, filtre par membres actifs.'''
|
||||
|
||||
import sys
|
||||
from socket import gethostname
|
||||
import collections
|
||||
import os
|
||||
import xml.dom.minidom
|
||||
|
||||
from gestion.ldap_crans import crans_ldap, MachineWifi
|
||||
from gestion.ldap_crans import crans_ldap, AssociationCrans
|
||||
from gestion.hptools import hpswitch, ConversationError
|
||||
from gestion.affich_tools import coul, cprint
|
||||
from gestion.whos import aff
|
||||
from gestion.affich_tools import cprint
|
||||
import gestion.affichage as affichage
|
||||
import gestion.mail as mail_module
|
||||
|
||||
# Constantes pour munin.
|
||||
# L'ordre est important : il détermine comment sont empilées les valeurs
|
||||
|
@ -27,10 +26,13 @@ STATE_DESCR = collections.OrderedDict([
|
|||
('adh', ('autres machines appartenant aux autres adhérents', 0xe5ff00)),
|
||||
])
|
||||
|
||||
CLUB_CRANS = 35
|
||||
CLUB_BDE = 1
|
||||
DN_CLUB_CRANS = 'cid=35,'
|
||||
DN_CLUB_BDE = 'cid=1,'
|
||||
|
||||
WIFIMAP_DIR = os.getenv('DBG_WIFIMAP_DB', '/usr/scripts/var/wifi_xml')
|
||||
|
||||
def pretty_name(item):
|
||||
"""Affiche un joli nom pour un objet ldap (adh ou machine)"""
|
||||
v = ""
|
||||
|
||||
if hasattr(item, 'nom'):
|
||||
|
@ -38,10 +40,13 @@ def pretty_name(item):
|
|||
if hasattr(item, 'prenom'):
|
||||
v = item.prenom() + " " + v
|
||||
v = v.replace('.wifi.crans.org', ' (WiFi)')
|
||||
v = v.replace('.adm.crans.org', '')
|
||||
v = v.replace('.crans.org', '')
|
||||
return v
|
||||
|
||||
def show_liste_by_prop(liste):
|
||||
"""Récupère une liste de machines et affiche un tableau deux colonnes
|
||||
avec propriétaire d'un côté et ses machines de l'autre."""
|
||||
by_owner = dict()
|
||||
|
||||
for machine in liste:
|
||||
|
@ -58,10 +63,13 @@ def show_liste_by_prop(liste):
|
|||
alignement=['g', 'g']).rstrip()
|
||||
|
||||
def show_liste(liste):
|
||||
"""Affiche une liste d'objet ldap"""
|
||||
print ", ".join(pretty_name(m) for m in liste)
|
||||
|
||||
def _mucode(u):
|
||||
"""Sad but true: munin ne fait pas d'utf-8 …"""
|
||||
"""
|
||||
Renvoie le bytestr associé à un unicode, avec l'encodage de munin.
|
||||
Sad but true: munin ne fait pas d'utf-8 …"""
|
||||
return u.encode('iso-8859-15', errors='ignore')
|
||||
|
||||
class WhosThere(object):
|
||||
|
@ -91,11 +99,11 @@ class WhosThere(object):
|
|||
if m.nom() in self.expected:
|
||||
return
|
||||
proprio = m.proprietaire()
|
||||
if fm['machineCrans'] or fm["borneWifi"] or (proprio.idn == 'cid' and int(proprio.id()) == CLUB_CRANS):
|
||||
if isinstance(proprio, AssociationCrans) or proprio.dn.startswith(DN_CLUB_CRANS):
|
||||
key = 'crans'
|
||||
elif hasattr(proprio, 'droits') and proprio.droits():
|
||||
key = 'ma'
|
||||
elif proprio.idn == "cid" and int(proprio.id()) == CLUB_BDE:
|
||||
elif proprio.dn.startswith(DN_CLUB_BDE):
|
||||
key = 'bde'
|
||||
else:
|
||||
if self._ignore_inactive:
|
||||
|
@ -118,7 +126,8 @@ class WhosThere(object):
|
|||
|
||||
def populate_from_ap(self, host):
|
||||
"""Rempli les macs à partir de la prise d'un switch"""
|
||||
path = os.path.join('/usr/scripts/var/wifi_xml/alone/', host) + '.wifi.crans.org.xml'
|
||||
|
||||
path = os.path.join(WIFIMAP_DIR, 'alone', host + '.xml')
|
||||
with open(path, 'r') as f:
|
||||
doc = xml.dom.minidom.parse(f)
|
||||
|
||||
|
@ -177,7 +186,11 @@ graph_category environnement""" % _mucode(munin_title)
|
|||
for (name, (descr, color)) in STATE_DESCR.iteritems():
|
||||
print """%(name)s.label %(descr)s
|
||||
%(name)s.draw AREASTACK
|
||||
%(name)s.colour %(color)06X""" % {'name': name, 'descr': _mucode(descr), 'color': color}
|
||||
%(name)s.colour %(color)06X""" % {
|
||||
'name': name,
|
||||
'descr': _mucode(descr),
|
||||
'color': color,
|
||||
}
|
||||
# Dans le doute, n'affichons pas les adhérents
|
||||
print "adh.graph no"
|
||||
|
||||
|
@ -190,13 +203,32 @@ graph_category environnement""" % _mucode(munin_title)
|
|||
class WhoKfet(WhosThere):
|
||||
name = u"Kfet"
|
||||
|
||||
expected = [
|
||||
'kronos.wifi.crans.org',
|
||||
'oison.crans.org',
|
||||
'batk-0.crans.org',
|
||||
'camera1.crans.org',
|
||||
'camera2.crans.org',
|
||||
'camera3.crans.org',
|
||||
'camera4.crans.org',
|
||||
'kfet.crans.org',
|
||||
'impression-bureau.crans.org',
|
||||
]
|
||||
|
||||
def do_scan(self):
|
||||
self.populate_from_switch('backbone.adm.crans.org', 21)
|
||||
|
||||
class Who2B(WhosThere):
|
||||
name = u"2B"
|
||||
|
||||
expected = ['00:07:cb:b1:99:4e'] # Freebox
|
||||
expected = [
|
||||
'00:07:cb:b1:99:4e', # Freebox
|
||||
'terminal.crans.org',
|
||||
'minigiga.adm.crans.org',
|
||||
'belides.wifi.crans.org',
|
||||
'tinybrother.adm.crans.org',
|
||||
'vo.crans.org',
|
||||
]
|
||||
|
||||
def do_scan(self):
|
||||
# Tous les gens au 2B sont supposés actifs (local technique quoi)
|
||||
|
@ -210,7 +242,7 @@ class WhoDAlembert(WhosThere):
|
|||
expected = ['danae.wifi.crans.org']
|
||||
|
||||
def do_scan(self):
|
||||
self.populate_from_ap('danae')
|
||||
self.populate_from_ap('danae.wifi.crans.org')
|
||||
|
||||
class Who4J(WhosThere):
|
||||
name = u"4J"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue