Android Python module to check disk space?
#1
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?

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'
Reply
#2
Yeah

Dont steal my code

"File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.service.rawmaintenance/service.py", line 39, in <module>"

Im the dev behind rawmaintenance.
Reply
#3
I just checked our python code on android and statvfs is there. (not runtime tested though)

did you try a simple:
Code:
from os import statvfs
statvfs("/tmp")
Reply
#4
(2015-11-12, 01:01)Gombeek Wrote: Yeah

Dont steal my code

"File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.service.rawmaintenance/service.py", line 39, in <module>"

Im the dev behind rawmaintenance.

I looked up rawmaintenance. Is this it? https://github.com/rawmedia/raw_maintenance/

If so, kodaxx hasn't stolen anything (yet) since your code is GPLv3 licensed.
Reply
#5
Hi, nice to hear someone is doing this.
I made a batch script for this case on windows
Reply
#6
(2015-11-12, 18:26)Pline Wrote:
(2015-11-12, 01:01)Gombeek Wrote: Yeah

Dont steal my code

"File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.service.rawmaintenance/service.py", line 39, in <module>"

Im the dev behind rawmaintenance.

I looked up rawmaintenance. Is this it? https://github.com/rawmedia/raw_maintenance/

If so, kodaxx hasn't stolen anything (yet) since your code is GPLv3 licensed.

Technically it is all open source and he is free to use it, its just rather dirty to post on here pretending he coded it and is looking to make a ground breaking add-on that already exists as he simply copy and pasted my code.
But feel free to download it, heres a tutorial video showing how to install it
https://www.youtube.com/watch?v=aHDlXYV9EG4
Reply
#7
Sorry guys, wasn't trying to mislead anyone. I am improving upon this code (which is why I ask about the Android Python modules?), such is the basis of open source. I have taken my download offline until Gombeek and I have discussed it further. I want to point out that I have posted long ago that it was an edited version of Raw Maintenance here: http://forum.kodi.tv/showthread.php?tid=...pid2012762

I originally needed to tweak it for myself, like we all have done with certain addons and I have since added features to this plugin that were requested by users of this forum and intend to go another direction with this addon by adding things that were never considered in Gombeeks addon.

I apologize for any confusion

I also want to point out that I have shared information regarding this code on the no-issue forums and did not ever hear back - thats when I decided to do things on my own.
Reply
#8
(2015-11-13, 00:03)Gombeek Wrote:
(2015-11-12, 18:26)Pline Wrote:
(2015-11-12, 01:01)Gombeek Wrote: Yeah

Dont steal my code

"File "/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/plugin.service.rawmaintenance/service.py", line 39, in <module>"

Im the dev behind rawmaintenance.

I looked up rawmaintenance. Is this it? https://github.com/rawmedia/raw_maintenance/

If so, kodaxx hasn't stolen anything (yet) since your code is GPLv3 licensed.

Technically it is all open source and he is free to use it, its just rather dirty to post on here pretending he coded it and is looking to make a ground breaking add-on that already exists as he simply copy and pasted my code.
But feel free to download it, heres a tutorial video showing how to install it
https://www.youtube.com/watch?v=aHDlXYV9EG4

Copy and pasted yes, I have also added things to your code which is what I thought the point of open sourcing things is for? To share what you have done and let others build upon them. This is a similar situation as Media Player and Kodi or Boxee and Kodi is it not? I did not mean to offend.
Reply
#9
(2015-11-12, 16:11)wsnipex Wrote: I just checked our python code on android and statvfs is there. (not runtime tested though)

did you try a simple:
Code:
from os import statvfs
statvfs("/tmp")
I will try when I get the time! Thank you. With my luck it would be something simple Smile
Reply
#10
If anyone's still interested in this, here's what I did:

Code:
if xbmc.getCondVisibility('system.platform.android'):
        import subprocess
        df = subprocess.Popen(['df', '/storage/emulated/legacy'], stdout=subprocess.PIPE)
        output = df.communicate()[0]
        info = output.split('\n')[1].split()
        size = float(info[1].replace('G', '').replace('M', '')) * 1000000000.0
        size = size - (size % float(info[-1]))
        available = float(info[3].replace('G', '').replace('M', '')) * 1000000000.0
        available = available - (available % float(info[-1]))
        return int(round(available)), int(round(size))

the return values are in bytes
Reply

Logout Mark Read Team Forum Stats Members Help
Python module to check disk space?0