scripts/utils/chambre-on-off.py
Antoine Durand-Gasselin 4a68475e34 [wiki-lenny] suppression de static/
darcs-hash:20090314092631-bd074-b01256aeaf71e935851b3ecdbd623eaae8c9e8a1.gz
2009-03-14 10:26:31 +01:00

58 lines
1.5 KiB
Python

#! /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 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/")
import hptools
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 : %s" % chambre
print "switch : %s" % chbre_sw.switch
print "prise : %s" % chbre_sw.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)