diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2011-07-01 11:55:36 (GMT) |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2011-07-01 11:55:36 (GMT) |
commit | 210e7ca032d51b8368359c02ad505dbd5f633cc9 (patch) | |
tree | 6558f76ed9be7add62a771d5b09b52e94f058fa3 /Modules | |
parent | 59929d9877e2968c38e672f14cd92aa63bfe9c4b (diff) | |
download | cpython-210e7ca032d51b8368359c02ad505dbd5f633cc9.zip cpython-210e7ca032d51b8368359c02ad505dbd5f633cc9.tar.gz cpython-210e7ca032d51b8368359c02ad505dbd5f633cc9.tar.bz2 |
Issue #12442: add shutil.disk_usage()
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 60c374d..ba80f57 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7451,6 +7451,32 @@ posix_statvfs(PyObject *self, PyObject *args) } #endif /* HAVE_STATVFS */ +#ifdef MS_WINDOWS +PyDoc_STRVAR(win32__getdiskusage__doc__, +"_getdiskusage(path) -> (total, free)\n\n\ +Return disk usage statistics about the given path as (total, free) tuple."); + +static PyObject * +win32__getdiskusage(PyObject *self, PyObject *args) +{ + BOOL retval; + ULARGE_INTEGER _, total, free; + LPCTSTR path; + + if (! PyArg_ParseTuple(args, "s", &path)) + return NULL; + + Py_BEGIN_ALLOW_THREADS + retval = GetDiskFreeSpaceEx(path, &_, &total, &free); + Py_END_ALLOW_THREADS + if (retval == 0) + return PyErr_SetFromWindowsErr(0); + + return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart); +} +#endif + + /* This is used for fpathconf(), pathconf(), confstr() and sysconf(). * It maps strings representing configuration variable names to * integer values, allowing those functions to be called with the @@ -9716,6 +9742,7 @@ static PyMethodDef posix_methods[] = { {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, + {"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, |