summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-config-22/timezip.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2009-11-13 07:22:22 (GMT)
committerJames Meyer <james.meyer@operamail.com>2009-11-13 07:22:22 (GMT)
commitf1e3c5f9132ab7fdf1e1d33f6020a82a9869096a (patch)
tree6b681fc663d7f8a07863185f4313d39cedba655a /abs/core-testing/LinHES-config-22/timezip.py
parent420f4c0c8157237d3b4b682a27db498b80c9e0f3 (diff)
downloadlinhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.zip
linhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.tar.gz
linhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.tar.bz2
LinHES-config-22: first check in of LinHES-config-22
Diffstat (limited to 'abs/core-testing/LinHES-config-22/timezip.py')
-rwxr-xr-xabs/core-testing/LinHES-config-22/timezip.py232
1 files changed, 232 insertions, 0 deletions
diff --git a/abs/core-testing/LinHES-config-22/timezip.py b/abs/core-testing/LinHES-config-22/timezip.py
new file mode 100755
index 0000000..bf6b389
--- /dev/null
+++ b/abs/core-testing/LinHES-config-22/timezip.py
@@ -0,0 +1,232 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# import MySQL module
+#used to import the zipcode/timezone/nfs info fromMBE
+import MySQLdb
+import sys
+import getopt
+import socket
+
+
+def usage():
+ print " -h --help"
+ print " -d --installdb"
+ print " -m --masterdb"
+ print " -n --hostname of current machine"
+
+def printvars():
+ print "masterdb: " + masterdb
+ print "installdb:" + installdb
+ print "hostname: " + thishostname
+ print "BEhostname:" + BEhostname
+ print "zipcode:" + zipcode
+ print "timezone:" + tz
+ print "timezone region:" + tz_region
+ print "timezone subregion:" + tz_subregion
+ print "nfsip:" + nfsip
+ print "nfstoggle:" + nfstoggle
+ print "nfsmount:" + nfsmount
+ print "hobbitclient:" + hobbitclient
+# connect
+def selectvars():
+
+ global BEhostname
+ global zipcode
+ global tz
+ global tz_region
+ global tz_subregion
+ global nfsip
+ global nfstoggle
+ global nfsmount
+ global hobbitclient
+
+ db = MySQLdb.connect(host=masterdb, user="mythtv", passwd="mythtv", db="mythconverg")
+ # create a cursor
+ cursor = db.cursor()
+ # execute SQL statement
+ cursor.execute("select hostname from settings where value='BackendServerIP' and data=(%s)",(masterdb))
+ result = cursor.fetchone()
+ try:
+ BEhostname=result[0]
+ except TypeError:
+ BEhostname=""
+
+ cursor.execute("select data from settings where value='HostZipcode' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ zipcode = result[0]
+ except TypeError:
+ zipcode=""
+
+ cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ nfsip=result[0]
+ except TypeError:
+ nfsip=""
+
+ cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ nfstoggle=result[0]
+ except TypeError:
+ nfstoggle=""
+
+ cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ nfsmount=result[0]
+ except TypeError:
+ nfsmount=""
+
+ cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ tz=result[0]
+ except TypeError:
+ tz=""
+##########
+ cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ try:
+ tz_region=result[0]
+ except TypeError:
+ tz_region=""
+ tempsubregion="HostTimeZoneRegion_" + tz_region
+
+ cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname))
+ result = cursor.fetchone()
+ try:
+ tz_subregion=result[0]
+ except TypeError:
+ tz_subregion=""
+###############
+ if ( thishostname != BEhostname ):
+ cursor.execute("select data from settings where value='GlobalServiceHobbitserver'")
+ result = cursor.fetchone()
+ try:
+ hobbitclient=result[0]
+ except TypeError:
+ hobbitclient="1"
+
+
+
+def insertvars():
+
+ db = MySQLdb.connect(host=installdb, user="mythtv", passwd="mythtv", db="mythconverg")
+ cursor = db.cursor()
+#inserting the zipcode
+ cursor.execute("select * from settings where value='HostZipcode' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if ( zipcode!="" ):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostZipcode',(%s),(%s))",(zipcode,thishostname))
+ print "inserting zipcode"
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostZipcode'",(zipcode,thishostname))
+ print "updating zipcode"
+
+#inserting the timezone
+ cursor.execute("select * from settings where value='HostTimeZone' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if ( tz != ""):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZone',(%s),(%s))",(tz,thishostname))
+ print "inserting timezone"
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostTimeZone'",(tz,thishostname))
+ print "updating timezone"
+
+ cursor.execute("select * from settings where value='HostTimeZoneRegion' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if ( tz != ""):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZoneRegion',(%s),(%s))",(tz_region,thishostname))
+ print "inserting timezone region"
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostTimeZoneRegion'",(tz_region,thishostname))
+ print "updating timezone region"
+
+ tempsubregion="HostTimeZoneRegion_" + tz_region
+ cursor.execute("select * from settings where value=%s and hostname=(%s)",(tempsubregion,thishostname))
+ result = cursor.fetchone()
+ if ( tz != ""):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ((%s),(%s),(%s))",(tempsubregion,tz_subregion,thishostname))
+ print "inserting timezone subregion"
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value=(%s)",(tempsubregion,tz_subregion,thishostname))
+ print "updating timezone subregion"
+
+
+#start of NFSIP
+ cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if ( nfsip != ""):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname))
+ print "inserting nfsip"
+
+ if (nfstoggle != ""):
+ cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostHaveCentralNFS',(%s),(%s))",(nfstoggle,thishostname))
+ print "inserting nfstoggle"
+
+ if ( nfsmount !="") :
+ cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostNFSmountpoint',(%s),(%s))",(nfsmount,thishostname))
+ print "inserting nfsmountpoint"
+
+#hobbitclient
+ cursor.execute("select * from settings where value='HostServiceHobbitclient' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if ( tz != ""):
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostServiceHobbitclient',(%s),(%s))",(hobbitclient,thishostname))
+ print "inserting hobbitcleint"
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostServiceHobbitclient'",(hobbitclient,thishostname))
+ print "updating hobbitclient"
+
+
+def main(argv):
+ global masterdb
+ global installdb
+ global thishostname
+ thishostname=""
+ global BEhostname
+ global zipcode
+ global tz
+ global tz_region
+ global tz_subregion
+
+ global nfsip
+ global hobbitclient
+ try:
+ opts, args = getopt.getopt(argv, "hm:d:n:", ["help", "masterdb=", "installdb=" , "hostname=" ] )
+ except getopt.GetoptError:
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ usage()
+ sys.exit()
+ elif opt in ( "-d" , "--installdb"):
+ installdb = arg
+ elif opt in ("-m", "--masterdb"):
+ masterdb = arg
+ elif opt in ("-n", "--hostname"):
+ thishostname = arg
+
+ if ( thishostname == "" ):
+ thishostname = socket.gethostname()
+
+ selectvars()
+ printvars()
+ insertvars()
+if __name__ == "__main__":
+ main(sys.argv[1:])
+