diff options
| author | Britney Fransen <brfransen@gmail.com> | 2016-05-16 16:24:28 (GMT) |
|---|---|---|
| committer | Britney Fransen <brfransen@gmail.com> | 2016-05-16 16:24:28 (GMT) |
| commit | fff4c50d3a1d94c807604d6c21355993dfb95c85 (patch) | |
| tree | 390f0eb0781b2599449edbdafbeb6aaba34200dc /abs/core/LinHES-system/myth_mtc.py | |
| parent | 8de064f6e96f960cdbfe6868d9957a4613f704df (diff) | |
| parent | 6f7a84649ef75069cc4fa06fabeb63e762e049d1 (diff) | |
| download | linhes_pkgbuild-fff4c50d3a1d94c807604d6c21355993dfb95c85.zip linhes_pkgbuild-fff4c50d3a1d94c807604d6c21355993dfb95c85.tar.gz linhes_pkgbuild-fff4c50d3a1d94c807604d6c21355993dfb95c85.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 | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py index 8a08c05..e62592f 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() @@ -59,8 +84,28 @@ 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 ("--optimize" in sys.argv) or (len(sys.argv) == 1): + + if (len(sys.argv) == 1) or ("--noidlecheck" in sys.argv) and (len(sys.argv) == 2): + runall = True + else: + runall = False + + if ("--noidlecheck" in sys.argv): + print "No system idle check will be done." + idle = 0 + else: + idle = subprocess.call(["/usr/bin/python2", "/usr/LH/bin/idle.py"]) + + if not idle: + if ("--check_home" in sys.argv) or runall: + 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 runall: print "\n#######################################" print "\n%s Running Optimize" %(get_timestamp()) if not optimize(): @@ -68,13 +113,13 @@ def run_stuff(): else: return True - if ("--backup" in sys.argv) or (len(sys.argv) == 1): + if ("--backup" in sys.argv) or runall: print "\n#######################################" print "\n%s Running Backup" %(get_timestamp()) if not os.system('/usr/LH/bin/lh_system_backup_job'): print "\nFinished Backup" - if ("--update" in sys.argv) or (len(sys.argv) == 1): + if ("--update" in sys.argv) or runall: print "\n#######################################" print "\n%s Running System Update" %(get_timestamp()) if not os.system('/usr/LH/bin/lh_system_host_update'): @@ -96,7 +141,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 |
