def disk_usage(path):
 try:
  st = os.statvfs(path)
 except UnicodeEncodeError:
  if ((not PY3) and isinstance(path, unicode)):
   try:
    path = path.encode(sys.getfilesystemencoding())
   except UnicodeEncodeError:
    pass
   st = os.statvfs(path)
  else:
   raise
 total = (st.f_blocks * st.f_frsize)
 avail_to_root = (st.f_bfree * st.f_frsize)
 avail_to_user = (st.f_bavail * st.f_frsize)
 used = (total - avail_to_root)
 total_user = (used + avail_to_user)
 usage_percent_user = usage_percent(used, total_user, _round=1)
 return sdiskusage(total=total, used=used, free=avail_to_user, percent=usage_percent_user)

def disk_usage ( path ) : try : st = os . statvfs ( path ) except UnicodeEncodeError : if ( ( not PY3 ) and isinstance ( path , unicode ) ) : try : path = path . encode ( sys . getfilesystemencoding ( ) ) except UnicodeEncodeError : pass st = os . statvfs ( path ) else : raise total = ( st . f_blocks * st . f_frsize ) avail_to_root = ( st . f_bfree * st . f_frsize ) avail_to_user = ( st . f_bavail * st . f_frsize ) used = ( total - avail_to_root ) total_user = ( used + avail_to_user ) usage_percent_user = usage_percent ( used , total_user , _round = 1 ) return sdiskusage ( total = total , used = used , free = avail_to_user , percent = usage_percent_user )
return disk usage associated with path .