-
Notifications
You must be signed in to change notification settings - Fork 9
/
cleaner.py
126 lines (84 loc) · 2.54 KB
/
cleaner.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /usr/bin/env python3
#program:cleaner
#@Author : 5hifaT
#github:https://github.com/jspw
#Date:12 June, 2020
#distro : Debian
import os
import sys
import subprocess as sp
def check_cache():
print("\nSHOWING CACHES .................\n\n")
# commands as variables
check_apt_cache = ["sudo" ,"du" ,"-sh", "/var/cache/apt"]
check_journal_logs =["sudo" ,"journalctl","--disk-usage"]
check_thumbnail_cache = ["sudo","du", "-sh", "~/.cache/thumbnails"]
# Executing
try :
sp.call(check_apt_cache)
except :
sp.call(["sudo","apt","install","du"])
sp.call(check_apt_cache)
try:
sp.call(check_journal_logs)
except:
sp.call(["sudo","apt","install","journalctl"])
sp.call(check_journal_logs)
try:
sp.call(check_thumbnail_cache)
except Exception as e :
print(e)
print("\n\n\n[-] please use -c to clean caches\n")
def clean():
# Variables
su = "sudo"
apt ="apt"
# Commands
autoremove = [su, apt, "autoremove"]
apt_cache1 = [su, apt, "autoclean"]
apt_cache2 = [su,apt ,"clean"]
journal_logs_clean = [su, "journalctl", "--vacuum-time=7d"]
thumbnail_cache = [su, "rm", "-rf", "~/.cache/thumbnails/*"]
# Execute
print("\n\n\nGeting rid of packages that are no longer required........\n\n\n")
sp.call(autoremove)
print("\n\n\nCleaning up APT cache..........\n\n\n")
sp.call(apt_cache1)
sp.call(apt_cache2)
print("\n\n\nClearing systemd journal logs 7 days out-dated......\n\n\n")
try:
sp.call(journal_logs_clean)
except:
sp.call(["sudo","apt","install","journalctl"])
sp.call(journal_logs_clean)
print("\n\n\nCleaning the thumbnail cache.......\n\n\n")
try:
sp.call(thumbnail_cache)
except :
print("Already Cleaned")
print("All Cleaned!")
def error_msg():
print("Help:")
print("\t[-] Please use -s to show caches")
print("\t[-] Please use -c to clean caches")
print("\t[-] Please use sudo command to execute properly!")
def main():
option = sys.argv
l = len(option)
if l == 2:
if option[1] == "-s":
try:
check_cache()
except:
print("Use sudo command to execute properly!")
elif option[1] == "-c":
try:
clean()
except:
print("Use sudo command to execute properly!")
else :
error_msg()
else :
error_msg()
if __name__ == "__main__":
main()