diff --git a/utils/chambre-on-off.py b/utils/chambre-on-off.py index e9307bae..b0eddca4 100755 --- a/utils/chambre-on-off.py +++ b/utils/chambre-on-off.py @@ -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 + chbre de la forme A101d + 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"