diff options
| author | Britney Fransen <brfransen@gmail.com> | 2014-10-27 20:28:27 (GMT) |
|---|---|---|
| committer | Britney Fransen <brfransen@gmail.com> | 2014-10-27 20:28:27 (GMT) |
| commit | f7b823f55a80b1498c30e9f3a47692a2329c4f09 (patch) | |
| tree | 6de557714e6336282fbc0ab16c6578386dfc6654 /abs/core/LinHES-system/myth_mtc.py | |
| parent | 4c2a2e3504f472628285a989c7c9a76be6855f54 (diff) | |
| parent | 01c1a60f3b7f93b3ed7404196c2cf798c4d8c674 (diff) | |
| download | linhes_pkgbuild-f7b823f55a80b1498c30e9f3a47692a2329c4f09.zip linhes_pkgbuild-f7b823f55a80b1498c30e9f3a47692a2329c4f09.tar.gz linhes_pkgbuild-f7b823f55a80b1498c30e9f3a47692a2329c4f09.tar.bz2 | |
Merge branch 'testing'
Diffstat (limited to 'abs/core/LinHES-system/myth_mtc.py')
| -rwxr-xr-x | abs/core/LinHES-system/myth_mtc.py | 114 |
1 files changed, 12 insertions, 102 deletions
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py index 7847313..b1ec75d 100755 --- a/abs/core/LinHES-system/myth_mtc.py +++ b/abs/core/LinHES-system/myth_mtc.py @@ -6,6 +6,8 @@ import socket import os import datetime,time import shlex +sys.dont_write_bytecode = True +import idle try: from MythTV import MythBE @@ -21,15 +23,13 @@ def get_timestamp(): date = (now.strftime('%Y-%m-%d %H:%M')) return date - def optimize(): - try: cursor = mythtv.db.cursor() cursor.execute("SHOW tables") result = cursor.fetchall() except: - print " Problem getting tables from database" + print "\n%s Problem getting tables from the database" %(get_timestamp()) return ops=["REPAIR","OPTIMIZE","ANALYZE"] for row in result: @@ -39,95 +39,15 @@ def optimize(): cmd= "%s table %s" %(op,ctable) cursor.execute(cmd) - -def upcoming_check(): - print " Checking for upcoming shows" - try: - upcoming = mythtv.getUpcomingRecordings() - except: - return True - 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 " %s is upcoming in %s" %(show,time_diff) - return False - - -def schemalock_check(): - print " Checking if schema is locked" - try: - c = mythtv.db.cursor() - c.execute("select count(*) from schemalock") - results=c.fetchone() - schemalock=results[0] - except: - return True - - if schemalock == 0: - return True - else: - print " schema is locked" - return False - -def job_check(): - print " Checking jobqueue" +def cleanup_inuseprograms(): + fourHoursAgo=datetime.datetime.today() - datetime.timedelta(hours=4) + cmd="DELETE FROM inuseprograms WHERE lastupdatetime < '%s';" %fourHoursAgo try: - c = mythtv.db.cursor() - c.execute("select count(*) from jobqueue where status = 4") - results=c.fetchone() + cursor = mythtv.db.cursor() + cursor.execute(cmd) except: - return True - jobs= results[0] - if jobs == 0 : - return True - else: - print " jobs are running" - return False - + print "\n%s Problem cleaning inuseprograms in database" %(get_timestamp()) -def in_use(): - print " Checking if programs are in use" - try: - c = mythtv.db.cursor() - c.execute("select count(*) from inuseprograms") - results=c.fetchone() - except: - return True - prginuse=results[0] - if prginuse == 0 : - return True - else: - print " Programs in use" - return False - -def mfd_check(): - print " Checking is mythfilldatabase is running" - ps = subprocess.Popen("ps ax -o pid= -o args= ", shell=True, stdout=subprocess.PIPE) - ps_pid = ps.pid - output = ps.stdout.read() - ps.stdout.close() - ps.wait() - proc_name="mythfilldatabase" - for line in output.split("\n"): - res = re.findall("(\d+) (.*)", line) - if res: - pid = int(res[0][0]) - if proc_name in res[0][1] and pid != os.getpid() and pid != ps_pid: - print " mythfilldatabase is running" - return False - - return True def bail_if_another_is_running(): cmd = shlex.split("pgrep -u {} -f {}".format(os.getuid(), __file__)) @@ -138,19 +58,9 @@ def bail_if_another_is_running(): __file__, " ".join(pids)) raise SystemExit(1) - -def idle_check(): - print "\n%s Checking Idle" %(get_timestamp()) - if ( upcoming_check() and schemalock_check() and job_check() and in_use() and mfd_check() ): - idle=True - print "\n%s Myth is idle" %(get_timestamp()) - else: - idle=False - print "\n%s Myth is NOT idle" %(get_timestamp()) - return idle - def run_stuff(): - if idle_check(): + print "\n%s" %get_timestamp() + if idle.main(): print "\n#######################################" print "\n%s Running Optimize" %(get_timestamp()) optimize() @@ -174,6 +84,7 @@ bail_if_another_is_running() starttime=time.time() ctin=True while ctin: + cleanup_inuseprograms() ctin=run_stuff() if ctin: print "\n%s Waiting 10 minutes before trying again." %(get_timestamp()) @@ -184,4 +95,3 @@ while ctin: ctin = False print "\n%s Time Exceeded 50 minutes. Quitting.)" %(get_timestamp()) exit(1) - |
