# -*- coding: utf-8 -*-
import logging, mv_common
import os, re

config_file = "mv_config"

def windowmanager(systemconfig):
    logging.info("____Start of windowmanager setup____")
    try:
        windowmanager = systemconfig.get("windowmanager")
    except:
        windowmanager = "default"
        return

    if windowmanager == ""  or windowmanager == None:
        windowmanager = "default"
    try:
        style = systemconfig.get("EnhancedWMStyle")
    except:
        style = ""

    if style == "1" and windowmanager != "default" :
        style = "enhanced"
    else:
        style = ""

    if windowmanager != "fluxbox":
        mv_common.pacinstall("e16_theme_settings")
        mv_common.pacinstall("wmaker_settings")
    else:
        mv_common.pacinstall("alt_wm")

    cmd = '''/usr/LH/bin/set_windowmanager.sh %s %s ''' %(windowmanager,style)
    print cmd
    mv_common.runcmd(cmd)
    logging.info("__End of windowmanager \n")


def supplemental(systemconfig,this_is_install = False):
    logging.info("____Start of supplemental config ____")
    try:
        supplemental=systemconfig.get("supplemental")
    except:
        supplemental = "0"
    if supplemental == "1":
        logging.info("     Installing supplemental system\n")
        if this_is_install == True:
            if os.path.exists('/home/xymon/server'):
                cmd='''pacman --noconfirm --dbonly -Sdd xymonserver'''
                mv_common.runcmd(cmd)

        cmd='''/usr/LH/bin/install_supplemental_service.sh'''
        mv_common.runcmd(cmd)
    logging.info("__End of supplemental\n")
