You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB
Plaintext

9 years ago
#!/usr/bin/env python
# Find junk in my home directory
from __future__ import division, print_function
from colorama import Fore
import os
import os.path
import sys
M = 1024 * 1024
9 years ago
def junk_dirs():
"""Return directories which potentially contain junk"""
static_junk_dirs = [
"~/tmp",
"~/.local/share/Trash",
"~/rpmbuild",
"~/RPM",
"~/.cache/tracker",
"~/.cache/tracker3",
"~/.cache",
"~/.local/share/apt-dater/history",
"~/.gradle/caches",
]
for d in static_junk_dirs:
9 years ago
d = os.path.expanduser(d)
if os.path.exists(d):
yield d
for d, _, _ in os.walk(os.path.expanduser("~")):
if d.endswith(".sync/Archive"):
9 years ago
yield d
def du(path):
"""Return disk usage of the given directory"""
def get_blocks(path):
stat = os.stat(path)
return (stat.st_ino, stat.st_blocks)
dd = {}
ino, blocks = get_blocks(path)
dd[ino] = blocks
for dirpath, dirnames, filenames in os.walk(path):
for filename in dirnames + filenames:
path = os.path.join(dirpath, filename)
if os.path.exists(path):
ino, blocks = get_blocks(path)
dd[ino] = blocks
return 512 * sum(dd.values())
def main():
for d in junk_dirs():
if os.path.isdir(d):
du_d = du(d)
if du_d < 5 * M:
9 years ago
continue
if du_d > 100 * M:
9 years ago
fore = Fore.RED
elif du_d > 50 * M:
9 years ago
fore = Fore.YELLOW
else:
fore = Fore.RESET
print(fore + str(du_d // M) + "M\t" + d + Fore.RESET)
9 years ago
main()