Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:17

0001 # Licensed under the Apache License, Version 2.0 (the "License");
0002 # you may not use this file except in compliance with the License.
0003 # You may obtain a copy of the License at
0004 # http://www.apache.org/licenses/LICENSE-2.0
0005 #
0006 # Authors:
0007 # - Giampaolo Rodola, g.rodola@gmail.com, 2017
0008 # - Daniel Drizhuk, d.drizhuk@gmail.com, 2017
0009 
0010 import os
0011 import collections
0012 
0013 _ntuple_diskusage = collections.namedtuple('usage', 'total used free')
0014 
0015 if hasattr(os, 'statvfs'):  # POSIX
0016     def disk_usage(path):
0017         st = os.statvfs(path)
0018         free = st.f_bavail * st.f_frsize
0019         total = st.f_blocks * st.f_frsize
0020         used = (st.f_blocks - st.f_bfree) * st.f_frsize
0021         return _ntuple_diskusage(total, used, free)
0022 
0023 else:
0024     def disk_usage(path):
0025         return _ntuple_diskusage(0, 0, 0)
0026 
0027 disk_usage.__doc__ = """
0028 Return disk usage statistics about the given path as a (total, used, free)
0029 namedtuple.  Values are expressed in bytes.
0030 """