diff options
Diffstat (limited to 'abs/core/LinHES-system/myth_mtc.py')
-rwxr-xr-x | abs/core/LinHES-system/myth_mtc.py | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py index 8a08c05..ee4fde2 100755 --- a/abs/core/LinHES-system/myth_mtc.py +++ b/abs/core/LinHES-system/myth_mtc.py @@ -17,10 +17,35 @@ except: def get_timestamp(): now = datetime.datetime.now() -#date = "%s-%s-%s" %(now.year, now.month, now.day) - date = (now.strftime('%Y-%m-%d %H:%M')) + date = (now.strftime('%Y-%m-%d %H:%M')) return date +def getFreePercentForDir(dir): + stats = os.statvfs(dir) + total = (stats.f_blocks) + avail = (stats.f_bavail) + return (total - avail) / float(total) + +def check_home(): + #get the mythtv home dir + sys.path.append('/usr/MythVantage/bin/') + config_file = "mv_config" + data_config = __import__(config_file, globals(), locals(), []) + + freePcent = getFreePercentForDir(data_config.MYTHHOME) + print " Home directory percent used: " + str(freePcent * 100) + "%" + if float(freePcent) > .9: + print " Home directory is greater than 90% used. Clearing MythTV caches..." + cmd = "/usr/bin/rm -rf " + data_config.MYTHHOME + "/.mythtv/{*cache,Cache-*}" + subprocess.call(["sh", "-c", cmd]) + print " Restarting mythfrontend..." + subprocess.call(["killall", "mythfrontend"]) + freePcent = getFreePercentForDir(data_config.MYTHHOME) + print " Home directory percent used: " + str(freePcent * 100) + "%" + else: + print " Home directory is less than 90% used. Not clearing MythTV caches." + return 0 + def optimize(): try: cursor = mythtv.db.cursor() @@ -60,6 +85,14 @@ def bail_if_another_is_running(): def run_stuff(): print "\n%s" %get_timestamp() if not subprocess.call(["/usr/bin/python2", "/usr/LH/bin/idle.py"]): + if ("--check_home" in sys.argv) or (len(sys.argv) == 1): + print "\n#######################################" + print "\n%s Checking size of MythTV home" %(get_timestamp()) + if not check_home(): + print "\nFinished checking size of MythTV home" + else: + return True + if ("--optimize" in sys.argv) or (len(sys.argv) == 1): print "\n#######################################" print "\n%s Running Optimize" %(get_timestamp()) @@ -96,7 +129,7 @@ while ctin: if ctin: print "\n%s Waiting 10 minutes before trying again." %(get_timestamp()) time.sleep(600) - + current_time=time.time() if (current_time - starttime) > 3000 : ctin = False |