Passage de chbre_on_off à hptools2 (pour ra2.py)

This commit is contained in:
Gabriel Detraz 2015-08-22 01:19:49 +02:00
parent ae803ba2c3
commit 0b12a81e93

View file

@ -1,4 +1,4 @@
#! /usr/bin/env python #!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""chambre_on_off.py: Affiche le statut, active ou désactive une prise """chambre_on_off.py: Affiche le statut, active ou désactive une prise
@ -9,29 +9,39 @@
- off : désactiver la prise - off : désactiver la prise
- absent : affiche le statut de la prise - absent : affiche le statut de la prise
Script importé par ra2.py
""" """
import sys import sys
sys.path.append("/usr/scripts/gestion/") from gestion import annuaires_pg
from gestion import hptools2
import hptools
def chambre_on_off(chambre, cmd = None): def chambre_on_off(chambre, cmd = None):
"""Active ou désactive une prise """Active ou désactive une prise
chambre: numéro de chambre chambre: numéro de chambre
cmd: si fourni, "on" ou "off" pour activer ou désactiver la prise 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 si cmd n'est pas fourni, ne fait qu'afficher le statut de la prise
""" """
# On formatte
bat = chambre[0]
chbre = chambre[1:]
# On cherche
prise = annuaires_pg.chbre_prises(batiment=bat,chambre=chbre)
switch_name = 'bat'+bat.lower()+'-'+prise[0]+'.adm.crans.org'
# connexion au switch # connexion au switch
chbre_sw = hptools.sw_chbre(chambre) chbre_sw = hptools2.HPSwitch(switch_name)
# affichage des infos # affichage des infos
print "chbre : %s" % chambre print "chbre : %s" % chambre
print "switch : %s" % chbre_sw.switch print "switch : %s" % switch_name
print "prise : %s" % chbre_sw.prise print "prise : %s" % prise
print "statut : %s" % (chbre_sw.is_enable() and "on" or "off") print "statut : %s" % chbre_sw.is_enabled(int(prise[1:]))
if cmd: if cmd:
cmd = cmd.lower() cmd = cmd.lower()
@ -39,13 +49,13 @@ def chambre_on_off(chambre, cmd = None):
# modification du statut # modification du statut
if cmd == "off": if cmd == "off":
print "action : disable" print "action : disable"
chbre_sw.disable() chbre_sw.set_enabled(int(prise[1:]),enabled=False)
elif cmd == "on": elif cmd == "on":
print "action : enable" print "action : enable"
chbre_sw.enable() chbre_sw.set_enabled(int(prise[1:]),enabled=True)
# affichage du nouveau statut # affichage du nouveau statut
print "statut : %s" % (chbre_sw.is_enable() and "on" or "off") print "statut : %s" % chbre_sw.is_enabled(int(prise[1:]))
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2: if len(sys.argv) == 2: