summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-system/myth_mtc.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2008-10-10 03:28:50 (GMT)
committerJames Meyer <james.meyer@operamail.com>2008-10-10 03:28:50 (GMT)
commit3981e3bd46861efbe9cebe4a0cb106faa9033daa (patch)
treeef6d32ca5a3e99cb88f8c54720b9b6528904b006 /abs/core-testing/LinHES-system/myth_mtc.py
parentbd5bf3ecdb7757918a4d12add60ae295c837a2b7 (diff)
downloadlinhes_pkgbuild-3981e3bd46861efbe9cebe4a0cb106faa9033daa.zip
linhes_pkgbuild-3981e3bd46861efbe9cebe4a0cb106faa9033daa.tar.gz
linhes_pkgbuild-3981e3bd46861efbe9cebe4a0cb106faa9033daa.tar.bz2
Scripts to make LinHES all that it will be.
sudo rules are installed via LinHES.install. Currently this allows mythtv to do anything. This will need to change in the future, but for now its ok. -myth_mtc.py is a script that will check to make sure myth is idle before running optimize_mythdb.py along with performing a nightly backup. Currently the backup is not functional, as it's waiting on the knoppmyth scripts. LinHES-start and LinHES-session start X and control whats run. Instead of using a .xinitrc for mythtv LinHES-start is systemwide. LinHES-profile.sh set's up the PATH for LinHES tools & scripts.
Diffstat (limited to 'abs/core-testing/LinHES-system/myth_mtc.py')
-rwxr-xr-xabs/core-testing/LinHES-system/myth_mtc.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/abs/core-testing/LinHES-system/myth_mtc.py b/abs/core-testing/LinHES-system/myth_mtc.py
new file mode 100755
index 0000000..faeee84
--- /dev/null
+++ b/abs/core-testing/LinHES-system/myth_mtc.py
@@ -0,0 +1,139 @@
+#!/usr/bin/python
+
+
+import sys,popen2
+import optparse
+import re
+import socket
+import os
+import datetime,time
+
+
+
+try:
+ from MythTV import MythTV
+ mythtv = MythTV()
+except:
+ mythtv = None
+
+#print mythtv.db.getSetting( 'Theme', socket.gethostname())
+
+def optimize():
+ cursor = mythtv.db.cursor()
+ cursor.execute("SHOW tables")
+ result = cursor.fetchall()
+ ops=["REPAIR","OPTIMIZE","ANALYZE"]
+ for row in result:
+ ctable=row[0]
+ for op in ops:
+ print op,ctable
+ cmd= "%s table %s" %(op,ctable)
+ cursor.execute(cmd)
+
+
+def upcoming_check():
+ upcoming = mythtv.getUpcomingRecordings()
+ try:
+ show=str(upcoming[0])
+ show=show.strip()
+ showtime=show.partition("(")[2].strip(")")
+ now=time.time()
+ rec_time=time.strptime( showtime ,"%Y-%m-%d %H:%M:%S" )
+ r=time.mktime(rec_time)
+ time_diff= ( r - now ) / 60
+ except:
+ time_diff=100
+ show="No show"
+ if ( time_diff > 30) :
+ return True
+ else:
+ print show , "is upcoming in " , time_diff
+ return False
+
+
+def schemalock_check():
+ c = mythtv.db.cursor()
+ c.execute("select count(*) from schemalock")
+ results=c.fetchone()
+ schemalock=results[0]
+ if schemalock == 0:
+ return True
+ else:
+ print "schema is locked"
+ return False
+
+def job_check():
+ c = mythtv.db.cursor()
+ c.execute("select count(*) from jobqueue where status = 4")
+ results=c.fetchone()
+ jobs= results[0]
+ if jobs == 0 :
+ return True
+ else:
+ print " jobs are running"
+ return False
+
+
+def in_use():
+ c = mythtv.db.cursor()
+ c.execute("select count(*) from inuseprograms")
+ results=c.fetchone()
+ prginuse=results[0]
+ if prginuse == 0 :
+ return True
+ else:
+ print "programs in use"
+ return False
+
+def mfd_check():
+ ismfd=popen2.Popen3('/bin/ps cax|/bin/grep -v grep |/bin/grep mythfilldatabase')
+ ismfd.wait()
+ mfdIdle=ismfd.poll()
+ if mfdIdle == 0:
+ print "mythfilldatabase is running"
+ return False
+ else:
+ return True
+
+
+
+def idle_check():
+ if ( upcoming_check() and schemalock_check() and job_check() and in_use() and mfd_check() ):
+ idle=True
+ print "Myth is idle"
+ else:
+ idle=False
+ print "Myth is NOT idle"
+ return idle
+
+def run_stuff():
+ if idle_check():
+ print "Running optimize"
+ optimize()
+
+ print "Running backup"
+ os.system('/usr/MythVantage/bin/backup_job')
+
+ print "Running system_update"
+ os.system('/usr/MythVantage/bin/update_system')
+ continue_loop=False
+ else:
+ continue_loop=True
+ return continue_loop
+
+#---------------------------------
+starttime=time.time()
+ctin=True
+while ctin:
+ ctin=run_stuff()
+ if ctin:
+ time.sleep(600)
+ current_time=time.time()
+ if (current_time - starttime) > 10800 :
+ ctin = False
+ print "time exceeded (3 hours)"
+ exit(1)
+
+
+
+