* Champ position des bornes

* whos -h plus concis

darcs-hash:20060313215451-68412-33985b31e41aabeba4f38fad4426029b2d4bf8f8.gz
This commit is contained in:
glondu 2006-03-13 22:54:51 +01:00
parent 6604677322
commit 3fe5d7be00
2 changed files with 80 additions and 33 deletions

View file

@ -242,7 +242,8 @@ class crans_ldap:
'hostname': 'host',
'mac': 'macAddress',
'ip': 'ipHostNumber',
'telephone': 'tel'}
'telephone': 'tel',
'position': 'positionBorne'}
# Les différentes classes LDAP de machines
ldap_machines_classes = ['machineFixe', 'machineWifi', 'machineCrans', 'borneWifi']
@ -276,7 +277,8 @@ class crans_ldap:
'mailAlias', 'info', 'controle'], \
'machineFixe': non_auto_search_machines_champs,
'machineCrans': non_auto_search_machines_champs + ['prise'],
'borneWifi': non_auto_search_machines_champs + ['prise', 'puissance', 'canal'],
'borneWifi': non_auto_search_machines_champs + \
['prise', 'puissance', 'canal', 'hotspot', 'positionBorne'],
'machineWifi': non_auto_search_machines_champs + ['ipsec'] }
# Profondeur des différentes recherches (scope)
@ -2671,10 +2673,11 @@ class BorneWifi(Machine):
def __init__(self, parent_or_tuple, typ='borne', conn=None):
Machine.__init__(self, parent_or_tuple, typ, conn)
# Initialisaton par défaut spécifique
self._data['canal'] = ['2047']
self._data['puissance'] = ['60']
self._data['hotspot'] = ['FALSE']
if not isinstance(parent_or_tuple, tuple):
# Initialisaton par défaut spécifique
self._data['canal'] = ['2047']
self._data['puissance'] = ['60']
self._data['hotspot'] = ['FALSE']
def mac2(self):
""" Retourne l'adresse MAC + 2 """
@ -2767,6 +2770,29 @@ class BorneWifi(Machine):
self._set('puissance', [str(new)])
return new
def position(self, new=False):
"""
Attribution ou visualisation de la position d'une borne wifi.
Renvoie un couple de coordonnées si elles existent, None sinon.
new doit être un couple de coordonnées, None (pour enlever les
coordonnées) ou False (retourne les valeurs actuelles).
"""
if new == False:
valeur = (self._data.get('positionBorne') or [''])[0]
if valeur:
valeur = valeur.split(' ')
return (float(valeur[0]), float(valeur[1]))
else:
return None
elif new == None:
self._set('positionBorne', [])
return None
else:
self._set('positionBorne', ['%.6g %.6g' % (new[0], new[1])])
return new
class _fake_proprio(crans_ldap):
""" Définitions de base d'un propriétaire virtuel """

View file

@ -498,10 +498,14 @@ def machine_details(machine) :
# Borne wifi
if isinstance(machine, BorneWifi):
f += coul(u'Hotspot : ', 'gras')
if machine.hotspot():
f += 'oui\n'
f += machine.hotspot() and 'oui' or 'non'
position = machine.position()
if position:
f += coul(u'\t\t\tCoordonnées : ', 'gras')
f += '(%.6g, %.6g)\n' % (position[0], position[1])
else:
f += 'non\n'
f += '\n'
f += coul(u'Puissance : ','gras') + u"%4.d" % int(machine.puissance())
f += coul(u'\tCanaux : ', 'gras') + machine.canal()
f += coul(u'\tÉtat : ', 'gras')
@ -821,32 +825,49 @@ def __usage_brief(err='') :
def __usage() :
""" Comment ca marche ? """
list = ['']
for c in base.auto_search_champs.values() :
for champ in c :
coul_champ = coul(champ,'bleu')
if list[-1] == '' :
list[-1] = coul_champ
l = len(champ)
else :
l += len(champ) + 2
if l < 80 :
list[-1] += ', ' + coul_champ
else :
list.append(coul_champ)
l = len(champ)
liste = []
accu = ""
longueur = 0
for c in base.non_auto_search_champs.values() :
for champ in c :
l += len(champ) + 2
if l < 80 :
list[-1] += ', ' + champ
else :
list.append(champ)
l = len(champ)
# Champs automatiques
champs = []
for c in base.auto_search_champs.values():
for champ in c:
if champ not in champs:
champs.append(champ)
for champ in champs:
coul_champ = coul(champ, "bleu")
if accu == "":
accu = coul_champ
longueur = len(champ)
elif longueur + 2 + len(champ) < 80:
longueur += 2 + len(champ)
accu += ", " + coul_champ
else:
liste.append(accu)
accu = coul_champ
longueur = len(champ)
# Champs manuels
champs = []
for c in base.non_auto_search_champs.values():
for champ in c:
if champ not in champs:
champs.append(champ)
for champ in champs:
if longueur + 2 + len(champ) < 80:
longueur += 2 + len(champ)
accu += ", " + champ
else:
liste.append(accu)
accu = champ
longueur = len(champ)
# Dernière ligne
liste.append(accu)
print __doc__ % { 'prog' : sys.argv[0].split('/')[-1].split('.')[0] ,
'champs_rech' : '\n'.join(list) ,
'champs_rech' : '\n'.join(liste) ,
'limit_aff_details' : limit_aff_details ,
'limit_aff_historique' : limit_aff_historique }
sys.exit(0)