Issue 12442: shutil.disk_usage() - Python tracker

Created on 2011-06-29 16:55 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (13) msg139439 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-06-29 16:55
Patch in attachment adds a new disk_usage() function to shutil module which retrieves total, used and free disk space given a certain path plus the percentage usage.

See original discussion on python-ideas ml:
http://mail.python.org/pipermail/python-ideas/2011-June/010480.htm
msg139440 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-06-29 17:02
Typo. It's:
http://mail.python.org/pipermail/python-ideas/2011-June/010480.html
msg139468 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-06-30 09:31
New patch includes:

- Py_BEGIN/END_ALLOW_THREADS around GetDiskFreeSpaceEx() call
- use of assertGreaterEqual / assertLessEqual when testing the percentage usage
- use of hasattr(shutil, 'disk_usage') for skipping the test
- extended url reference in the comments
msg139475 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-06-30 13:10
Why do you return a percentage? People can compute that themselves if they want to.
msg139476 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011-06-30 13:15
Agreed. I think we should pass on the raw data - how the user wants to format and present that is up to them.
msg139553 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-07-01 08:24
Agreed. 
New patch removes the percentage and fixes computations on posix as recommended by Charles-François:

free = st.f_bavail * st.f_bsize
total = st.f_blocks * st.f_frsize
used = (total - st.f_bfree * st.f_bsize)
msg139569 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-01 11:55
New changeset 2fc102ebaf73 by Giampaolo Rodola' in branch 'default':
Issue #12442: add shutil.disk_usage()
http://hg.python.org/cpython/rev/2fc102ebaf73
msg139645 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-02 13:21
Looks like my message on Rietveld was not received or not read:

http://bugs.python.org/review/12442/diff/2951/7664#newcode776
msg139651 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-07-02 13:57
I removed the percent usage from the returned namedtuple hence that comment is no longer necessary.
msg139655 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-02 14:30
Ah, excellent!  Thanks for the new function.  About using assertGreater and friends in tests, as Ezio and I suggested, I have done the change in my working copy and will commit it later.
msg139659 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-02 14:47
New changeset 479973c6aa03 by Éric Araujo in branch 'default':
Clean up NEWS entry and tests for shutil.disk_usage (#12442)
http://hg.python.org/cpython/rev/479973c6aa03
msg139660 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-07-02 14:53
Thanks for the further fixes.
msg147374 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-09 21:12
New changeset bdb3f0e7e268 by Victor Stinner in branch 'default':
Issue #12442: nt._getdiskusage() is now using the Windows Unicode API
http://hg.python.org/cpython/rev/bdb3f0e7e268