示例#1
0
def get_free_space(path=KOLIBRI_HOME):
    if sys.platform.startswith("win"):
        import ctypes

        free = ctypes.c_ulonglong(0)
        check = ctypes.windll.kernel32.GetDiskFreeSpaceExW(
            ctypes.c_wchar_p(path), None, None, ctypes.pointer(free))
        if check == 0:
            raise ctypes.winError()
        result = free.value
    elif on_android():
        # This is meant for android, which needs to interact with android API to understand free
        # space. If we're somehow getting here on non-android, we've got a problem.
        try:
            from jnius import autoclass

            StatFs = autoclass("android.os.StatFs")

            st = StatFs(KOLIBRI_HOME)

            try:
                # for api version 18+
                result = st.getFreeBlocksLong() * st.getBlockSizeLong()
            except Exception:
                # for api versions < 18
                result = st.getFreeBlocks() * st.getBlockSize()

        except Exception as e:
            raise e
    else:
        st = os.statvfs(os.path.realpath(path))
        result = st.f_bavail * st.f_frsize

    return result
示例#2
0
def get_free_space(path=KOLIBRI_HOME):
    if sys.platform.startswith('win'):
        import ctypes

        free = ctypes.c_ulonglong(0)
        check = ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(path), None, None, ctypes.pointer(free))
        if check == 0:
            raise ctypes.winError()
        result = free.value
    else:
        st = os.statvfs(path)
        result = st.f_bavail * st.f_frsize

    return result
示例#3
0
def get_free_space(path=settings.KOLIBRI_HOME):
    if sys.platform.startswith('win'):
        import ctypes

        free = ctypes.c_ulonglong(0)
        check = ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(path), None, None, ctypes.pointer(free))
        if check == 0:
            raise ctypes.winError()
        result = free.value
    else:
        st = os.statvfs(path)
        result = st.f_bavail * st.f_frsize

    return result