forked from masasam/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm_garbage.py
executable file
·85 lines (71 loc) · 1.72 KB
/
rm_garbage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
"""Remove the garbage file."""
import os
import shutil
GARBAGE_FILES = [
'~/.recently-used',
'~/.local/share/recently-used.xbel',
'~/.thumbnails',
'~/.gconfd',
'~/.gconf',
'~/.local/share/gegl-0.2',
'~/.gstreamer-0.10',
'~/.pulse',
'~/.esd_auth',
'~/.config/enchant',
'~/.spicec',
'~/.dropbox-dist',
'~/.parallel',
'~/.dbus',
'~/.distlib/',
'~/.bazaar/',
'~/.bzr.log',
'~/.nv/',
'~/.viminfo',
'~/.npm/',
'~/.java/',
'~/.oracle_jre_usage/',
'~/.jssc/',
'~/.tox/',
'~/.pylint.d/',
'~/.qute_test/',
'~/.QtWebEngineProcess/',
'~/.qutebrowser/',
'~/.asy/',
'~/.cmake/',
'~/.gnome/',
'~/.texlive/',
'~/.w3m/',
]
def yes_or_no(question, default="n"):
"""Asks user for yes or no."""
prompt = "%s (y/[n]) " % question
answer = input(prompt).strip().lower()
if not answer:
answer = default
if answer == "y":
return True
return False
def rm_garbage():
"""Recursively remove"""
print("Found garbage files:")
found = []
for garbage_files in GARBAGE_FILES:
expandfile = os.path.expanduser(garbage_files)
if os.path.exists(expandfile):
found.append(expandfile)
print(" %s" % garbage_files)
if len(found) == 0:
print("No garbage files found")
return
if yes_or_no("Remove all?", default="n"):
for found_file in found:
if os.path.isfile(found_file):
os.remove(found_file)
else:
shutil.rmtree(found_file)
print("All cleaned")
else:
print("No file removed")
if __name__ == '__main__':
rm_garbage()