summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/timezip.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2013-02-19 21:10:18 (GMT)
committerJames Meyer <james.meyer@operamail.com>2013-02-19 21:10:18 (GMT)
commit2648e999d277eac5c3d331a3609bcc73fafbea71 (patch)
tree40951fb8e7fdbe28a0baa324ae615055203f1e2e /abs/core/LinHES-config/timezip.py
parentc759b5e0c4aa6fc37412b4dee2cf9ad993fd376d (diff)
parent7e6f7ca174e1af67178dc5293a312a4a733eb095 (diff)
downloadlinhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.zip
linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.gz
linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.bz2
Merge branch 'testing'
# By James Meyer (1091) and others # Via James Meyer (5) and others * testing: (1148 commits) LinHES-config: during install don't kill off lirc. This keeps the remote active all the way to the finish Change version numbers to 8.0 to match the release number. LinHES-conifg LinHES-system mythdb-initial runit-scripts supplemental-web LinHES-conifig: mv_install.py for the last partition don't go all the way to the end. Gotta leave room for gpt tables. xf86-video-ati: xorg ati driver. LinHES-config: timezip.py add syncing up of parental lvl passwords and starting level with MBE. LinHES-system: correct the logic for breaking out of the wmctrl loop. As written it would break out of the inner loop..but not the 60 iteration loop. e16_theme_settings: remove slide-in prop for new windows. For whatever reason this was preventing mplayer from being positioned correctly for appletrailers. LinHES-config, mythinstall: change case of hd_pvr and serial to all lower refs #902 zilog-firmware: firmware for TX support of the hdpvr and pvr-150 In general I can't recommend anybody using these transmitters but including the firmware just in case someone really wants to linhes-udev-rules: added hdprv_lirc rule. All of these lirc rules are limited to exactly one device. If more then one device is present then only the last device in init will get the symlink runit-scripts: fix logging for igdeamon, add support to remote init script so that the blaster is always the first device in the chain. added support specificly for hd_pvr LinHES-system: add lh_system_restore and lh_system_backup. These scripts are called from the mythmenu. refs #900 iguanair: rebuild with python 2.7 LinHES-system: msg_daemon.py fix init and nasty bug related to timeout. In a nutshell timeout wouldn't work unless a msg without a timeout was called first. linhes-udev-rules: add rules for mce,streamzap,serial lirc devices. mythinstall: recompile for matching libs mythtv: latest .25-fixes and change mythbackup/restore call lh_system_$op to replace mythbackup/mythrestore. mythbackup no longer works correctly with the new windowmanager linhes-scripts: myth2mp3, myth2x264, myth2xvid: use mythutil to get cutlist LinHES-config, supplimental-web: Fix proxy numbering for Ceton infiniTV linhes-system: add additional stuff to the system backup and also introduced an exclude file. The exclude/include files are locate in /home/mythtv/backup_config/ ...
Diffstat (limited to 'abs/core/LinHES-config/timezip.py')
-rwxr-xr-xabs/core/LinHES-config/timezip.py416
1 files changed, 323 insertions, 93 deletions
diff --git a/abs/core/LinHES-config/timezip.py b/abs/core/LinHES-config/timezip.py
index 4e494be..eb373b4 100755
--- a/abs/core/LinHES-config/timezip.py
+++ b/abs/core/LinHES-config/timezip.py
@@ -6,6 +6,26 @@ import MySQLdb
import sys
import getopt
import socket
+import urllib2
+socket.setdefaulttimeout(10)
+
+try:
+ from json import loads as jsonparse
+ nojson = False
+except ImportError:
+ try:
+ from simplejson import loads as jsonparse
+ nojson = False
+ except ImportError:
+ def jsonparse(js):
+ if unsafe:
+ return eval(js)
+ raise RuntimeError("Neither the json or simplejson module is available.\nUse the --unsafe option to use python eval() as an ad-hoc json decoder")
+
+
+def no_update(data):
+ print "* not updating %s, because a value is already present" %data
+
def usage():
@@ -14,19 +34,75 @@ def usage():
print " -m --masterdb"
print " -n --hostname of current machine"
+def latlong2_olsen(lat,lng):
+ olsenttz = ''
+ geo_url = "http://api.geonames.org/timezoneJSON?lat=%s&lng=%s&username=linhes_timezone" %(lat,lng)
+ try:
+ json_stream = urllib2.urlopen(geo_url,timeout=10)
+ json_dict = jsonparse(json_stream.read().replace("\r\n",""))
+ olsenttz = json_dict['timezoneId']
+ except:
+ print "error with geonames"
+
+ return olsenttz
+
+def geo_locate():
+ print " Trying to geo locate in timezip.py"
+ gtz = ''
+ gtz_region = ''
+ gtz_subregion = ''
+ #get long/lat from ip
+ try:
+ geo_url = "http://www.geobytes.com/IpLocator.htm?GetLocation&template=json.txt"
+ json_stream = urllib2.urlopen(geo_url,timeout=10)
+ json_dict = jsonparse(json_stream.read().replace("\r\n",""))['geobytes']
+ latitude = json_dict['latitude']
+ longitude = json_dict['longitude']
+ except:
+ print "error with geobytes/geolocate"
+ latitude = ''
+ longitude = ''
+
+ if latitude != '':
+ try:
+ olsenttz = latlong2_olsen (latitude,longitude)
+ gtz = olsenttz
+ gtz_region , gtz_subregion = olsenttz.split("/")
+ except:
+ print "error with geolocate"
+
+
+
+ return gtz, gtz_region , gtz_subregion
+
+
def printvars():
print "masterdb: " + masterdb
print "installdb:" + installdb
print "hostname: " + thishostname
print "BEhostname:" + BEhostname
- print "zipcode:" + zipcode
+ #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
+ print "nfsshare:" + nfsshareall
+ #print "hobbitclient:" + hobbitclient
+ print "windowmanager:" + windowmanager
+ print "windowmanager style:" + wmstyle
+ print "Gallery Dir:" + gallerydir
+ print "Music dir:" + musicdir
+ print "Music template:" + filenametemplate
+
+ for key,value in video_dict.items():
+ print "%s: %s" %(key,value)
+
+ print "-----------------------------------"
+ print "\n\n\n"
+
+
# connect
def selectvars():
@@ -38,160 +114,308 @@ def selectvars():
global nfsip
global nfstoggle
global nfsmount
- global hobbitclient
+ global nfsshareall
+ #global hobbitclient
+ global windowmanager
+ global wmstyle
+ global musicdir
+ global gallerydir
+ global filenametemplate
+ #video parent level
+ global video_dict
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:
+ cursor.execute("select hostname from settings where value='BackendServerIP' and data=(%s)",(masterdb))
+ result = cursor.fetchone()
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:
+ cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
nfsip=result[0]
except TypeError:
nfsip=""
- cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname))
- result = cursor.fetchone()
try:
+ cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
nfstoggle=result[0]
except TypeError:
- nfstoggle=""
+ nfstoggle="no"
+
- cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname))
- result = cursor.fetchone()
try:
+ cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
nfsmount=result[0]
except TypeError:
nfsmount=""
- cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname))
- result = cursor.fetchone()
try:
+ cursor.execute("select data from settings where value='HostCentralNFSallhosts' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ nfsshareall=result[0]
+ except TypeError:
+ nfsshareall="0"
+
+
+
+ try:
+ #cursor.execute("select data from settings where value='HostTimeZonetemp' and hostname=(%s)",(BEhostname))
+ cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
tz=result[0]
except TypeError:
- tz=""
-##########
- cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname))
- result = cursor.fetchone()
+ tz = ""
+
+ if tz == "":
+ tz,tz_region, tz_subregion = geo_locate()
+ else:
+ try:
+ cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ tz_region=result[0]
+ except TypeError:
+ tz_region=""
+
+ tempsubregion="HostTimeZoneRegion_" + tz_region
+ try:
+ cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname))
+ result = cursor.fetchone()
+ 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:
+ #hobbitclient="1"
+ #else:
+ #hobbitclient="1"
+
+
+
try:
- tz_region=result[0]
+ cursor.execute("select data from settings where value='HostWindowManager' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ windowmanager=result[0]
except TypeError:
- tz_region=""
- tempsubregion="HostTimeZoneRegion_" + tz_region
+ windowmanager=""
+
- cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname))
- result = cursor.fetchone()
try:
- tz_subregion=result[0]
+ cursor.execute("select data from settings where value='HostEnhancedWMStyle' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ wmstyle=result[0]
except TypeError:
- tz_subregion=""
-###############
- if ( thishostname != BEhostname ):
- cursor.execute("select data from settings where value='GlobalServiceHobbitserver'")
+ wmstyle=""
+
+
+ try:
+ cursor.execute("select data from settings where value='MusicLocation' and hostname=(%s)",(BEhostname))
result = cursor.fetchone()
- try:
- hobbitclient=result[0]
- except:
- hobbitclient="1"
- else:
- hobbitclient="1"
+ musicdir=result[0]
+ except TypeError:
+ musicdir=""
+
+
+ try:
+ cursor.execute("select data from settings where value='FilenameTemplate' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ filenametemplate=result[0]
+ except TypeError:
+ filenametemplate=""
+
+ try:
+ cursor.execute("select data from settings where value='GalleryDir' and hostname=(%s)",(BEhostname))
+ result = cursor.fetchone()
+ gallerydir=result[0]
+ except TypeError:
+ gallerydir=""
+# video parental level
+ video_list=['VideoAdminPassword',
+ 'VideoAdminPasswordThree',
+ 'VideoAdminPasswordTwo',
+ 'VideoAggressivePC',
+ 'VideoDefaultParentalLevel',
+ 'mythvideo.ParentalLevelFromRating']
+
+ for i in video_list:
+ sql_query="select data from settings where value='%s' and hostname='%s'" %(i,BEhostname)
+ try:
+ cursor.execute(sql_query)
+ result = cursor.fetchone()
+ video_dict[i]=result[0]
+ except TypeError:
+ video_dict[i]=''
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 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("select * from settings where value='HostTimeZone' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZone',(%s),(%s))",(tz,thishostname))
print "inserting timezone"
- else:
+ 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("select * from settings where value='HostTimeZoneRegion' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZoneRegion',(%s),(%s))",(tz_region,thishostname))
print "inserting timezone region"
- else:
+ 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):
+ tempsubregion="HostTimeZoneRegion_" + tz_region
+
+ cursor.execute("select * from settings where value=%s and hostname=(%s)",(tempsubregion,thishostname))
+ result = cursor.fetchone()
+ 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))
+ else:
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value=(%s)",(tz_subregion,thishostname,tempsubregion))
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 != ""):
+##start of NFSIP
+ if nfstoggle == "yes" :
+ print "BE has a central storage"
+ #if nfsshareall == "0":
+ #print "BE is not sharing central, starting config"
+ if ( nfsip != ""):
+ cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname))
+ print "inserting nfsip"
+ else:
+ no_update("HostCentralNFSIP")
+ #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostCentralNFSIP'",(nfsip,thishostname))
+ #print "updating nfsip"
+ 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"
+ else:
+ no_update("nfsmount")
+ #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostNFSmountpoint'",(nfsmount,thishostname))
+ #print "updating nfsmount"
+ #else:
+ #print "BE is sharing, config sync skipped"
+ else:
+ print "BE has no central storage"
+
+ #windowmanager
+ if windowmanager != "":
+ cursor.execute("select * from settings where value='HostWindowManager' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostWindowManager',(%s),(%s))",(windowmanager,thishostname))
+ print "inserting windowmanager"
+ else:
+ no_update("windowmanager")
+ #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostWindowManager'",(windowmanager,thishostname))
+ #print "updating windowmanager"
+
+
+ if wmstyle != "" :
+ cursor.execute("select * from settings where value='HostEnhancedWMStyle' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
if (result == None):
- cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname))
- print "inserting nfsip"
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostEnhancedWMStyle',(%s),(%s))",(wmstyle,thishostname))
+ print "inserting windowmanager style"
+ else:
+ no_update("wm_style")
+ #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostEnhancedWMStyle'",(wmstyle,thishostname))
+ #print "updating windowmanager style"
- if (nfstoggle != ""):
- cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(thishostname))
+#music and gallery
+
+ if ( musicdir != "" ):
+ cursor.execute("select * from settings where value='MusicLocation' 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"
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('MusicLocation',(%s),(%s))",(musicdir,thishostname))
+ print "inserting musicdir"
+ else:
+ #no_update("musicdir")
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='MusicLocation'",(musicdir,thishostname))
+ print "updating musicdir"
- if ( nfsmount !="") :
- cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(thishostname))
+ if ( filenametemplate != "" ):
+ cursor.execute("select * from settings where value='FilenameTemplate' 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"
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('FilenameTemplate',(%s),(%s))",(filenametemplate,thishostname))
+ print "inserting filenametemplate"
+ else:
+ no_update("filenametemplate")
+ #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='FilenameTemplate'",(filenametemplate,thishostname))
+ #print "updating filenametemplate"
+
+ if ( gallerydir != "" ):
+ cursor.execute("select * from settings where value='GalleryDir' and hostname=(%s)",(thishostname))
+ result = cursor.fetchone()
+ if (result == None):
+ cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('GalleryDir',(%s),(%s))",(gallerydir,thishostname))
+ print "inserting gallerydir"
+ else:
+ #no_update("gallerydir")
+ cursor.execute("update settings set data=(%s) where hostname=(%s) and value='GalleryDir'",(gallerydir,thishostname))
+ print "updating gallerydir"
+
+# parental level
+ for key,value in video_dict.items():
+ if ( value != "" ):
+ sql_query = "select * from settings where value='%s' and hostname='%s'" %(key,thishostname)
+ cursor.execute(sql_query)
+ result = cursor.fetchone()
+ if (result == None):
+ insert_sql ="INSERT INTO settings (value,data,hostname) VALUES ('%s','%s','%s')" %(key,value,thishostname)
+ cursor.execute(insert_sql)
+ print "inserting %s" %(key)
+ else:
+ no_update(key)
+ #update_sql="update settings set data='%s' where hostname='%s' and value='%s'" %(value,thishostname,key)
+ #cursor.execute(update_sql)
+ #print "updating %s" %(key)
+
-#hobbitclient
- cursor.execute("select * from settings where value='HostServiceHobbitclient' and hostname=(%s)",(thishostname))
- result = cursor.fetchone()
- if ( hobbitclient != ""):
- 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):
@@ -204,9 +428,15 @@ def main(argv):
global tz
global tz_region
global tz_subregion
+ #global nfsip
+ #global hobbitclient
+ global musicdir
+ global gallerydir
+ global filenametemplate
+
+ global video_dict
+ video_dict = {}
- global nfsip
- global hobbitclient
try:
opts, args = getopt.getopt(argv, "hm:d:n:", ["help", "masterdb=", "installdb=" , "hostname=" ] )
except getopt.GetoptError: