#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#########################################################################
# pyeole.service - manage EOLE services
# Copyright © 2014 Pôle de Compétence EOLE <eole@ac-dijon.fr>
#
# License CeCILL:
#  * in french: http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
#  * in english http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
#########################################################################
from creole.client import CreoleClient
from pyeole.diagnose import test_containers, OK, NOK
from subprocess import getstatusoutput


if __name__ == "__main__":
    client = CreoleClient()
    if client.get_creole('mode_conteneur_actif') == 'oui':
        cmd = [". /usr/lib/eole/diagnose.sh"]
        cmd.append('EchoGras "*** Conteneurs"')
        for container, status in test_containers().items():
            cmd.append('printf ".  %${len_pf}s => " "' + container + '"')
            if status:
                cmd.append('EchoVert "Ok"')
            else:
                cmd.append('EchoRouge "Erreur"')
        cmd_string = "\n".join(cmd)
        err, ret = getstatusoutput(cmd_string)
        print(ret)
