| Index: third_party/psutil/examples/disk_usage.py
|
| diff --git a/third_party/psutil/examples/disk_usage.py b/third_party/psutil/examples/disk_usage.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..23f2d0c3f17118fe0d3b97df39ba0f35060d3eb1
|
| --- /dev/null
|
| +++ b/third_party/psutil/examples/disk_usage.py
|
| @@ -0,0 +1,43 @@
|
| +#!/usr/bin/env python
|
| +#
|
| +# $Id: disk_usage.py 1143 2011-10-05 19:11:59Z g.rodola $
|
| +#
|
| +# Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""
|
| +List all mounted disk partitions a-la "df -h" command.
|
| +"""
|
| +
|
| +import sys
|
| +import psutil
|
| +
|
| +def convert_bytes(n):
|
| + if n == 0:
|
| + return "0B"
|
| + symbols = ('k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
| + prefix = {}
|
| + for i, s in enumerate(symbols):
|
| + prefix[s] = 1 << (i+1)*10
|
| + for s in reversed(symbols):
|
| + if n >= prefix[s]:
|
| + value = float(n) / prefix[s]
|
| + return '%.1f%s' % (value, s)
|
| +
|
| +
|
| +def main():
|
| + templ = "%-17s %8s %8s %8s %5s%% %9s %s"
|
| + print templ % ("Device", "Total", "Used", "Free", "Use ", "Type", "Mount")
|
| + for part in psutil.disk_partitions(all=False):
|
| + usage = psutil.disk_usage(part.mountpoint)
|
| + print templ % (part.device,
|
| + convert_bytes(usage.total),
|
| + convert_bytes(usage.used),
|
| + convert_bytes(usage.free),
|
| + int(usage.percent),
|
| + part.fstype,
|
| + part.mountpoint)
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(main())
|
|
|