2015-08-09, 00:44
I'm working on a service add-on that will check the remaining disk space and remind a person, once space gets below 500MB, to use the maintenance tool that I've uploaded. I need a way to determine the remaining disk space using python on Android. I tried using statvfs() but it is apparently only compatible on Unix-like systems, including OS X. That means I can use statvfs for Linux and OSX. I can use wmi or ctypes for Windows but nothing for Android so far. I can create a separate wrapper to check the operating system and use the best method for each - but I can't find a python module for Android that can do this. Any suggestions?
So far this is what I have...but I get back:
Code:
import xbmc, xbmcgui, xbmcaddon
import os, sys, statvfs, time, datetime
from time import mktime
__addon__ = xbmcaddon.Addon(id='plugin.service.maintenancetool')
__addonname__ = __addon__.getAddonInfo('name')
__icon__ = __addon__.getAddonInfo('icon')
thumbnailPath = xbmc.translatePath('special://thumbnails');
cachePath = os.path.join(xbmc.translatePath('special://home'), 'cache')
tempPath = xbmc.translatePath('special://temp')
addonPath = os.path.join(os.path.join(xbmc.translatePath('special://home'), 'addons'),'plugin.service.maintenancetool')
mediaPath = os.path.join(addonPath, 'media')
databasePath = xbmc.translatePath('special://database')
if __name__ == '__main__':
#check HDD freespace
st = os.statvfs(xbmc.translatePath('special://home'))
if st.f_frsize:
freespace = st.f_frsize * st.f_bavail/1024/1024
else:
freespace = st.f_bsize * st.f_bavail/1024/1024
print "Free Space: %dMB"%(freespace)
if(freespace < 500):
text = "You have less than 500MB of free space"
text1 = "Please use the Maintenance tool"
text2 = "immediately to prevent system issues"
xbmcgui.Dialog().ok(__addonname__, text, text1, text2)
while not xbmc.abortRequested:
xbmc.sleep(500)
So far this is what I have...but I get back:
Code:
Error Type: <type 'exceptions.AttributeError'>
Error Contents: 'module' object has no attribute 'statvfs'
Traceback (most recent call last):
File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.service.rawmaintenance/service.py", line 39, in <module>
st = os.statvfs(xbmc.translatePath('special://home))
Attribute Error: 'module' object has no attribute 'statvfs'