[utils/chambre-on-off] Petites améliorations
- le script peut être lancé sans commande pour juste voir le statut de la prise - la fonction peut être réutilisée ailleurs (pourquoi pas...) darcs-hash:20090212235502-ffbb2-8d3eb933a45550fdb4c2276a1402aa80fdd8c00e.gz
This commit is contained in:
parent
0027e245d2
commit
b8b1d48b44
1 changed files with 47 additions and 32 deletions
|
@ -1,43 +1,58 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
"""chambre_on_off.py: Affiche le statut, active ou désactive une prise
|
||||
|
||||
# syntaxe : chambre-on-off.py A101d on
|
||||
# chambre-on-off.py A101d off
|
||||
syntaxe : chambre-on-off.py chbre <cmd>
|
||||
chbre de la forme A101d
|
||||
<cmd> peut être :
|
||||
- on : activer la prise
|
||||
- off : désactiver la prise
|
||||
- absent : affiche le statut de la prise
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
sys.path.append("/usr/scripts/gestion/")
|
||||
|
||||
# recherche des coordonnées de la chambre
|
||||
from annuaires import chbre_prises
|
||||
chbre = sys.argv[1].lower()
|
||||
bat = chbre[0]
|
||||
prise = int(chbre_prises[bat][chbre[1:]][1:])
|
||||
switch = "bat" + bat + "-" + chbre_prises[bat][chbre[1:]][0]
|
||||
cmd = sys.argv[2].lower()
|
||||
import hptools
|
||||
|
||||
# connecion au switch
|
||||
from hptools import hpswitch
|
||||
sw = hpswitch(switch)
|
||||
def chambre_on_off(chambre, cmd = None):
|
||||
"""Active ou désactive une prise
|
||||
|
||||
chambre: numéro de chambre
|
||||
cmd: si fourni, "on" ou "off" pour activer ou désactiver la prise
|
||||
si cmd n'est pas fourni, ne fait qu'afficher le statut de la prise
|
||||
"""
|
||||
# connexion au switch
|
||||
chbre_sw = hptools.sw_chbre(chambre)
|
||||
|
||||
# affichage des infos
|
||||
print "chbre : " + chbre
|
||||
print "switch : " + switch
|
||||
print "prise : " + str(prise)
|
||||
if sw.is_enable(prise):
|
||||
print "old statut : on"
|
||||
else:
|
||||
print "old statut : off"
|
||||
# affichage des infos
|
||||
print "chbre : %s" % chambre
|
||||
print "switch : %s" % chbre_sw.switch
|
||||
print "prise : %s" % chbre_sw.prise
|
||||
|
||||
# modification du statut
|
||||
if cmd == "off":
|
||||
print "action : disable"
|
||||
sw.disable(prise)
|
||||
else:
|
||||
print "action : enable"
|
||||
sw.enable(prise)
|
||||
print "statut : %s" % (chbre_sw.is_enable() and "on" or "off")
|
||||
|
||||
if cmd:
|
||||
cmd = cmd.lower()
|
||||
|
||||
# modification du statut
|
||||
if cmd == "off":
|
||||
print "action : disable"
|
||||
chbre_sw.disable()
|
||||
elif cmd == "on":
|
||||
print "action : enable"
|
||||
chbre_sw.enable()
|
||||
|
||||
# affichage du nouveau statut
|
||||
print "statut : %s" % (chbre_sw.is_enable() and "on" or "off")
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2:
|
||||
chambre_on_off(sys.argv[1])
|
||||
elif len(sys.argv) == 3:
|
||||
chambre_on_off(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
print __doc__
|
||||
sys.exit(0)
|
||||
|
||||
# affichage du nouveau statut
|
||||
if sw.is_enable(prise):
|
||||
print "new statut : on"
|
||||
else:
|
||||
print "new statut : off"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue