summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth_mtc.py
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2015-11-12 18:59:24 (GMT)
committerBritney Fransen <brfransen@gmail.com>2015-11-12 18:59:24 (GMT)
commita37f4c1263e867e049502aeb96a8a207424ae46c (patch)
tree0979974951f4675084c8721a6f2d9ea5bb1e8426 /abs/core/LinHES-system/myth_mtc.py
parentba2be7bcf3bd61642fb50ff779fbcea4d4df597c (diff)
downloadlinhes_pkgbuild-a37f4c1263e867e049502aeb96a8a207424ae46c.zip
linhes_pkgbuild-a37f4c1263e867e049502aeb96a8a207424ae46c.tar.gz
linhes_pkgbuild-a37f4c1263e867e049502aeb96a8a207424ae46c.tar.bz2
LinHES-system: myth_mtc.py & myth_mtc.cron: add new --check_home option.
The --check_home option checks how full home is and if it is over 90% it will remove caches in .mythtv and restart mythfrontend.
Diffstat (limited to 'abs/core/LinHES-system/myth_mtc.py')
-rwxr-xr-xabs/core/LinHES-system/myth_mtc.py39
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