From d2558b37e5c93dff5ee88519d416686b9df1a40b Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Thu, 7 May 2009 12:49:08 -0500
Subject: mv_install: add support for reading timezone on km upgrades.  Fix
 backupsql check path

---
 abs/core-testing/LinHES-config/PKGBUILD         |  2 +-
 abs/core-testing/LinHES-config/install_proxy.sh |  6 +++-
 abs/core-testing/LinHES-config/mv_install.py    | 46 ++++++++++++++++++++-----
 3 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/abs/core-testing/LinHES-config/PKGBUILD b/abs/core-testing/LinHES-config/PKGBUILD
index b20af81..a85f158 100755
--- a/abs/core-testing/LinHES-config/PKGBUILD
+++ b/abs/core-testing/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=1.0
-pkgrel=410
+pkgrel=418
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev )
 pkgdesc="Install and configure your system"
 depends=(bc libstatgrab  mysql-python expect curl dnsutils parted sg3_utils nmbscan system-templates rsync python-parted )
diff --git a/abs/core-testing/LinHES-config/install_proxy.sh b/abs/core-testing/LinHES-config/install_proxy.sh
index cb387b9..b9d6b67 100755
--- a/abs/core-testing/LinHES-config/install_proxy.sh
+++ b/abs/core-testing/LinHES-config/install_proxy.sh
@@ -201,7 +201,11 @@ case $1 in
             cond2=$(echo "$percent > 98" |bc  )
             if [ $cond2 -eq 1  ]
             then
-            percent=98
+                percent=98
+            fi
+            if  [  x"${state}" =  "xDone" ]
+            then
+                percent=100
             fi
             cond3=$(echo "$percent < 3" |bc )
             if [ $cond3 -eq 0   ]
diff --git a/abs/core-testing/LinHES-config/mv_install.py b/abs/core-testing/LinHES-config/mv_install.py
index a945e34..678cf3e 100755
--- a/abs/core-testing/LinHES-config/mv_install.py
+++ b/abs/core-testing/LinHES-config/mv_install.py
@@ -15,8 +15,19 @@ def usage():
 def clean_upgrade():
     return False
 
+def update_db(value,data):
+    db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg")
+    try:
+        cursor = db.cursor()
+        cursor.execute("DELETE FROM settings where value=%s and hostname=%s;",(value,data_config.MVHOSTNAME))
+        cursor.execute("REPLACE INTO  settings set value=%s,data=%s,hostname=%s;" ,(value,data,data_config.MVHOSTNAME))
+        logging.debug("Updated database  with %s,%s",data,value)
+    except  MySQLdb.Error, e:
+        logging.debug("Unable to update database with %s,%s",data,value)
+
+
 def progress(pgnum):
-    progressline = str(pgnum) + " complete"
+    progressline = str(pgnum) + "% complete"
     logging.debug("Progress: %s" , pgnum)
     f = open('/tmp/.install_percent', 'w')
     f.write(progressline)
@@ -64,11 +75,11 @@ def backup_sql_check():
     except:
         logging.debug("Backup file var is empty")
         return False
-    if os.path.exists(hostoptions["backupfile"]):
-        logging.debug("Backup file %s is present",hostoptions["backupfile"])
+    if os.path.exists(data_config.MOUNTPOINT+hostoptions["backupfile"]):
+        logging.debug("Backup file %s is present",data_config.MOUNTPOINT+hostoptions["backupfile"])
         return True
     else:
-        logging.debug("Backup file %s is NOT present",hostoptions["backupfile"])
+        logging.debug("Backup file %s is NOT present",data_config.MOUNTPOINT+hostoptions["backupfile"])
         return False
 
 def mdadm_find(PREFIX):
@@ -90,7 +101,7 @@ def mdadm_assemble_all():
     mdadm_contents = ''
     try:
         f = open(mdadmconf_file, 'r')
-        mdadm_contents = f.readlines
+        mdadm_contents = f.readlines()
         f.close()
     except:
         logging.debug("     Couldn't open mdadmconf file")
@@ -115,7 +126,23 @@ def copy_updates():
     cp_and_log2(MVROOT+"/bin/",data_config.MOUNTPOINT+MVROOT+"/bin","*.py")
 
 def timezone_to_db(timefile):
-    logging.info("LOOK TIMEZONE TO DB needs to be completed")
+    logging.info("importing timezone needs")
+    try:
+        f = open(timefile)
+        timezonecontents = f.readline().strip()
+        f.close
+    except:
+        logging.debug("Couldn't open /tmp/etc/timezone, will not set the timezone")
+        return
+    tzsplit = timezonecontents.partition('/')
+    print tzsplit
+    if tzsplit[2]  == '' :
+        update_db("HostTimeZoneRegion", tzsplit[0])
+    else:
+        update_db("HostTimeZoneRegion", tzsplit[0])
+        tztemp="HostTimeZoneRegion_%s" % tzsplit[0]
+        update_db(tztemp,tzsplit[2])
+
 
 
 def cp_and_log(srcfile,destfile):
@@ -1008,6 +1035,7 @@ def upgrade_mount_search():
         newbackupfile = "/tmp/"+data_config.BACKUPFILE
         if os.path.exists(newbackupfile):
             logging.debug("Setting backup file to %s",newbackupfile)
+            cp_and_log(newbackupfile,data_config.MOUNTPOINT+newbackupfile)
             hostoptions["backupfile"] = newbackupfile
         else:
             logging.info("Couldn't find any database to restore, upgrade will continue with a new database")
@@ -1036,7 +1064,7 @@ def upgrade(hostoptions):
     update_status(statusmsg)
     progress(3)
     mount_it()
-    hostoptions["backupfile"] = data_config.MOUNTPOINT+data_config.BACKUPPATH+data_config.BACKUPFILE
+    hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE
     statgrab( hostoptions["rootdisk"])
     msg = "Upgrading %s" %(systemconfig["hostname"])
     update_status(msg)
@@ -1201,7 +1229,7 @@ logging.basicConfig(level=logging.DEBUG,
                     format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                     datefmt='%m-%d %H:%M',
                     filename=DEBUGLOG,
-                    filemode='w')
+                    filemode='a')
 # define a Handler which writes INFO messages or higher to the sys.stderr
 console = logging.StreamHandler()
 console.setLevel(logging.INFO)
@@ -1241,7 +1269,7 @@ for line in config_file:
 if __name__ == "__main__":
     config_file = "mv_config"
     data_config = __import__(config_file, globals(), locals(), [])
-
+    logging.debug("___________START OF DEBUG_________________________")
     cmdoptions = main(sys.argv[1:])
     logging.debug("______cmd line options______")
     for i in cmdoptions.items():
-- 
cgit v0.12