#!/usr/bin/env python
# coding=UTF-8

__author__ = "Pierre-Yves Langlois"
__copyright__ = "https://github.com/pylanglois/uadm/blob/master/LICENCE"
__credits__ = ["Pierre-Yves Langlois","Francois Vaillancourt"]
__license__ = "BSD"
__version__ = "1.0"
__maintainer__ = "Pierre-Yves Langlois"
__status__ = "Production"

"""
This is an example script using the uadm scripting tools
"""

import sys

from uadm.uadmcore import *

#if __name__ == "__main__":
def run(args = []):
    #Config override example:
    mod_conf({
        #"UADM_TOOL_NAME" : unicode(sys.argv[0].split(".")[0]),
        #"UADM_LOG_PATH" : u"/var/log/uadm",
        #"UADM_SMTP_SERVER" : u"smtp.example.com",
        #"UADM_SRC_EMAIL" : u"tech@example.com",
        #"UADM_SUCCESS_SUBJECT" : u"Success",
        #"UADM_ERROR_SUBJECT" : u"Error",
        #"UADM_REPORT_ON_SUCCESS" : False,
        #"UADM_DISABLE_MAIL" : False,
    })

    #log to file example:
    #l.info("hello")
    #l.error("world")
    #l.debug("!!!!")

    #example:
    send_report(u"Running %s" % CONF_MAP["UADM_TOOL_NAME"])

    cmd_list = [
        "ls -la", #ok
        "ls -la /doesnotexists", #erreur
        cfb(str("""
            bash -c "
                [[ -f /var/lib/uadm/checkkernel_`uname -r` ]] 
                &&  
                    (echo no new kernel;) 
                ||  
                    (echo a new kernel was installed. New vmtools needed; 
                    touch /var/lib/uadm/checkkernel_`uname -r`; 
                    exit 1;) 
                
            "
        """)), #complex bash one lineer with if
    ]
    exec_cmd_list(cmd_list)

