From aa8cbfddbec8df7338a629fd96e6cfce0bb64ed7 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Mon, 1 Jun 2009 15:22:46 -0500
Subject: LinHES-config:  lineup debugging output

---
 abs/core-testing/LinHES-config/hostype.py        |   4 +-
 abs/core-testing/LinHES-config/mv_common.py      | 101 +++++++++++++++++------
 abs/core-testing/LinHES-config/mv_ir.py          |   4 +-
 abs/core-testing/LinHES-config/mv_network.py     |  27 +++---
 abs/core-testing/LinHES-config/mv_screensaver.py |   2 +-
 abs/core-testing/LinHES-config/mv_software.py    |   2 +-
 abs/core-testing/LinHES-config/mv_webuser.py     |   6 +-
 7 files changed, 99 insertions(+), 47 deletions(-)

diff --git a/abs/core-testing/LinHES-config/hostype.py b/abs/core-testing/LinHES-config/hostype.py
index 4dde3dc..0bbd16e 100644
--- a/abs/core-testing/LinHES-config/hostype.py
+++ b/abs/core-testing/LinHES-config/hostype.py
@@ -60,7 +60,7 @@ def setup_syslog(dbhost):
     return
 
 def hostypeprint(systemconfig):
-    logging.debug("______Start of hostype config_____")
+    logging.info("______Start of hostype config_____")
     mv_common.services(systemconfig)
     install_list=''
     remove_list=''
@@ -144,4 +144,4 @@ def hostypeprint(systemconfig):
         setup_func_minion(dbhost)
         setup_func_key()
         setup_syslog(systemconfig["dbhost"])
-    logging.debug("__End of hostype config")
+    logging.info("__End of hostype config\n")
diff --git a/abs/core-testing/LinHES-config/mv_common.py b/abs/core-testing/LinHES-config/mv_common.py
index 3ae7edb..64ff2d6 100644
--- a/abs/core-testing/LinHES-config/mv_common.py
+++ b/abs/core-testing/LinHES-config/mv_common.py
@@ -10,10 +10,9 @@ def runcmd(cmd):
     else:
         cmd = "echo "+cmd
     logging.debug("    %s",cmd)
-    cmdout = commands.getoutput(cmd)
+    cmdout = commands.getstatusoutput(cmd)
     logging.debug("    %s",cmdout)
-    return cmdout
-
+    return cmdout[0]
 
 def services(systemconfig):
     logging.debug("______Start of services______")
@@ -30,12 +29,34 @@ def cp_and_log(srcfile,destfile):
 
 def add_service(daemon):
     logging.info("    Adding service %s",daemon)
+    cmd = "add_service.sh %s" %daemon
+    runcmd(cmd)
 
 def remove_service(daemon):
     logging.info("    Removing service %s",daemon)
+    cmd = "remove_service.sh %s" %daemon
+    runcmd(cmd)
+
+def pkg_blacklist_check(pkg):
+    cmd = '''grep -q %s /etc/blacklist.package''' %pkg
+    rc = runcmd(cmd)
+    if rc == 0:
+        return True
+    else:
+        return False
+
+def pkg_installed_check(pkg):
+    logging.debug("    Checking if %sis installed",pkg)
+    cmd = "pacman -Q %s " %pkg
+    rc = runcmd(cmd)
+    if rc == 0:
+        return True
+    else:
+        return False
+
 
 def pacinstall(pkg):
-    logging.info("    Installing %s",pkg)
+    logging.info("    Checking %s for install",pkg)
     #extra pkg check
     if pkg == "xine":
         pacinstall("xine-ui")
@@ -44,8 +65,18 @@ def pacinstall(pkg):
     elif pkg == "webmin":
         add_service("webmin")
 
+    if  not pkg_blacklist_check(pkg):
+        if pkg_installed_check(pkg):
+            logging.info("    %s is already installed, will not install",pkg)
+        else:
+            logging.info("    Installing %s",pkg)
+            cmd ='''pacman --noconfirm -Sf %s ''' %pkg
+            runcmd(cmd)
+    else:
+        logging.info("    %s is blacklisted, will not install",pkg)
+
 def pacremove(pkg):
-    logging.info("    Removing %s",pkg)
+    logging.info("    Checking %s for removal",pkg)
     if pkg == "xine":
         pacremove("xine-ui")
     elif pkg == "dvdcss":
@@ -53,32 +84,52 @@ def pacremove(pkg):
     elif pkg == "webmin":
         remove_service("webmin")
 
+    if  not pkg_blacklist_check(pkg):
+        if not pkg_installed_check(pkg):
+            logging.info("    %s is not installed, will not remove",pkg)
+        else:
+            logging.info("    Removing %s",pkg)
+            cmd ='''pacman --noconfirm -R  %s ''' %pkg
+    else:
+        logging.info("    %s is blacklisted, will not remove",pkg)
+
+def getpid(process):
+    return commands.getoutput('pidof %s' % process)
+
+
+def restartLCD(RESTART_LCD):
+    if  RESTART_LCD :
+        logging.info("    Restarting lcd server")
+        cmd = "killall -9 mythlcdserver"
+        runcmd(cmd)
+    else:
+        logging.debug("    Not restarting MYTHLCD server")
+
 
-def reloadfe():
-    logging.info("    Reloading frontend")
-    logging.info("    LOOK Reloading frontend")
-    #function reloadfe(){
-    #PID=`ps -ef |grep mythfrontend|grep -v grep |awk  '{print $2 }'`
-    #/usr/bin/backend_control.sh  clearcache  behost $dbhost
-    #if [ x$RESTART_LCD = xtrue ]
-    #then
-        #killall -9 mythlcdserver
-    #fi
-    #if [  x = x$PID ]
-    #then
-        #echo "Mythfrontend not running, will not reload"
-    #else
-            #kill -s USR1 $PID
-    #fi
-    return
-
-def restartfe():
+def reloadfe(dbhost,RESTART_LCD):
+    logging.debug("____Start of reloadfe____")
+    logging.info("    Clearing Backend cache")
+    cmd = '''/usr/bin/backend_control.sh  clearcache  behost %s''' %dbhost
+    runcmd(cmd)
+    restartLCD(RESTART_LCD)
+    for pid in getpid("mythfrontend"):
+        cmd = ''' kill -s USR1 %s ''' %pid
+        #runcmd(cmd)
+        logging.info("    Reloading frontend with pid of %s",pid)
+
+    logging.debug("__End of reloadfe\n")
+
+
+def restartfe(RESTART_LCD):
+    logging.debug("____Start of restartfe____")
     logging.info("    Restarting frontend")
+    restartLCD(RESTART_LCD)
     cmd="killall -9 mythfrontend"
     runcmd(cmd)
     cmd="killall -9 welcome"
     runcmd(cmd)
-    return
+    logging.debug("__End of restartfe\n")
+
 
 def udev_trigger():
     logging.info("    Triggering udev")
diff --git a/abs/core-testing/LinHES-config/mv_ir.py b/abs/core-testing/LinHES-config/mv_ir.py
index cbc18a2..b3552c5 100644
--- a/abs/core-testing/LinHES-config/mv_ir.py
+++ b/abs/core-testing/LinHES-config/mv_ir.py
@@ -277,12 +277,12 @@ def setup_ir(systemconfig, data_config):
         mv_common.udev_trigger()
         cmd="sv start lircd"
         mv_common.runcmd(cmd)
-        rc = True
+        rc = [ True , True ]
     if systemconfig["LCDtype"]:
         setup_lcd(systemconfig["LCDtype"],
                   systemconfig["TEMPLATES"],
                   systemconfig["Remotetype"])
     else:
         logging.debug("    LCD not defined")
-    logging.info("__End IR ")
+    logging.info("__End IR\n")
     return rc
\ No newline at end of file
diff --git a/abs/core-testing/LinHES-config/mv_network.py b/abs/core-testing/LinHES-config/mv_network.py
index 71bc442..77ee2d8 100644
--- a/abs/core-testing/LinHES-config/mv_network.py
+++ b/abs/core-testing/LinHES-config/mv_network.py
@@ -13,7 +13,7 @@ def setup_MYTH_IP(systemconfig):
     except:
         logging.debug("    Error occured finding the defaultip")
         defaultip = "127.0.0.1"
-    logging.info("    Using %s as default ip", defaultip)
+    logging.debug("    Using %s as default ip", defaultip)
     return defaultip
 
 def setup_MYTH_DHCP(systemconfig):
@@ -23,7 +23,7 @@ def setup_MYTH_DHCP(systemconfig):
     except:
         logging.debug("    Error occured finding default dhcp")
         defaultdhcp = "0"
-    logging.info("    Using %s as dhcp value for %s", default_interface, defaultdhcp)
+    logging.debug("    Using %s as dhcp value for %s", default_interface, defaultdhcp)
     return defaultdhcp
 
 def flush(netdev):
@@ -51,13 +51,12 @@ def kill_dhcp(basedir):
 
 def setup_nameserver(dns):
     logging.info("    Adding %s for DNS", dns)
-    logging.info("-----------NEED TO SETUP setup_nameserver")
-    #grep -q $1 ${BASE}/etc/resolv.conf
-    #status=$?
-    #if [ ! $status = 0 ]
-    #then
-        #echo "nameserver $1" >> ${BASE}/etc/resolv.conf
-    #fi
+    cmd = '''grep -q %s /etc/resolv.conf''' %dns
+    status = mv_common.runcmd(cmd)
+    if  not status == 0 :
+        cmd =  ''' echo "nameserver %s" >> /etc/resolv.conf ''' %dns
+        mv_common.runcmd(cmd)
+
 
 
 def setup_hostname(systemconfig):
@@ -132,16 +131,16 @@ def setup_interface(netdev,systemconfig):
             cmd = '''echo "key %s" >>  %s/%s/iwconfig ''' %(netinfo["KEY"], etcnetdir, netdev)
             mv_common.runcmd(cmd)
     else:
-        logging.info("  Disabling wireless extensions")
+        logging.info("    Disabling wireless extensions")
         cmd = '''sed -i -e 's/^CONFIG_WIRLESS=.*$/CONFIG_WIRLESS=no/g' %s/%s/options''' %(etcnetdir, netdev)
         mv_common.runcmd(cmd)
 
     if netinfo["UseDHCP"] == "0" :
-        logging.info("   Enabling DHCP support")
+        logging.info("    Enabling DHCP support")
         cmd = ''' sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=dhcp/g' %s/%s/options''' %(etcnetdir, netdev)
         mv_common.runcmd(cmd)
     else:
-        logging.info("   Using static ip address of %s",netinfo["ip"])
+        logging.info("    Using static ip address of %s",netinfo["ip"])
         cmd = ''' sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=static/g' %s/%s/options''' %(etcnetdir, netdev)
         mv_common.runcmd(cmd)
         cmd = '''echo "default via %s" > %s/%s/ipv4route''' %(netinfo["GW"], etcnetdir, netdev)
@@ -259,7 +258,7 @@ def setup_network (systemconfig):
     logging.info("    Setting up the network")
     setup_hostname(systemconfig)
     find_active(systemconfig)
-    logging.info("__End of network")
+    logging.info("__End of network\n")
 
 
 
@@ -272,6 +271,6 @@ def install_network_setup(systemconfig):
     stop_network()
     find_active(systemconfig)
     start_network()
-    logging.info("__End of network")
+    logging.info("__End of network install \n")
 
 
diff --git a/abs/core-testing/LinHES-config/mv_screensaver.py b/abs/core-testing/LinHES-config/mv_screensaver.py
index eb81792..2da970c 100644
--- a/abs/core-testing/LinHES-config/mv_screensaver.py
+++ b/abs/core-testing/LinHES-config/mv_screensaver.py
@@ -193,7 +193,7 @@ def setup_screensaver (systemconfig,data_config):
         logging.debug("    screensaver tinker mode detected")
     else:
         logging.debug("   Unknown screensaver")
-    logging.info("__End of screensaver")
+    logging.info("__End of screensaver\n")
 
 
 
diff --git a/abs/core-testing/LinHES-config/mv_software.py b/abs/core-testing/LinHES-config/mv_software.py
index 83d7c86..047a235 100644
--- a/abs/core-testing/LinHES-config/mv_software.py
+++ b/abs/core-testing/LinHES-config/mv_software.py
@@ -38,4 +38,4 @@ def setup_software(systemconfig, data_config):
                 mv_common.pacremove(pkg)
         except:
             logging.debug("   ERROR-- %s is not defined", pkg)
-    logging.info("__End Software ")
\ No newline at end of file
+    logging.info("__End Software\n ")
\ No newline at end of file
diff --git a/abs/core-testing/LinHES-config/mv_webuser.py b/abs/core-testing/LinHES-config/mv_webuser.py
index 026121f..a8517a8 100644
--- a/abs/core-testing/LinHES-config/mv_webuser.py
+++ b/abs/core-testing/LinHES-config/mv_webuser.py
@@ -3,17 +3,19 @@ import logging, mv_common
 #import os
 
 def setup_web_auth(UseMythWEB_auth):
+    logging.info("____Start of setup_web_auth____")
     if UseMythWEB_auth == str(1):
         #enable auth
-        logging.info("Enabling authorization for mythweb")
+        logging.info("    Enabling authorization for mythweb")
         cmd='''sed -i "s/^.*include.*auth-inc.conf.*$/include \\"\/etc\/lighttpd\/auth-inc.conf\\"/g" /etc/lighttpd/lighttpd.conf'''
         mv_common.runcmd(cmd)
     else:
         #disable auth
-        logging.info("Disabling authorization for mythweb")
+        logging.info("    Disabling authorization for mythweb")
         cmd='''sed -i "s/^.*include.*auth-inc.conf.*$/#include \\"\/etc\/lighttpd\/auth-inc.conf\\"/g" /etc/lighttpd/lighttpd.conf'''
         mv_common.runcmd(cmd)
     logging.debug("Restarting lighttpd")
     cmd="sudo sv restart lighttpd"
     mv_common.runcmd(cmd)
+    logging.info("__End of webauth\n")
 
-- 
cgit v0.12