• R/O
  • HTTP
  • SSH
  • HTTPS

serene-cleaner: Commit


Commit MetaInfo

Revision7ab47c4d2d91c79c3242d44a150229525c45d7df (tree)
Zeit2019-07-31 20:37:09
Autorksmt4699 <ksmt4699@gmai...>
Commiterksmt4699

Log Message

CUI版完成

Ändern Zusammenfassung

Diff

--- a/main/serene-cleaner.py
+++ b/main/serene-cleaner.py
@@ -1,11 +1,12 @@
11 #!/usr/bin/env python3
22 import subprocess
33 import os.path
4-class clearcache():
4+class Cleancache():
55 def __init__(self, path):
66 rpath = path + r"/*"
77 self.searchpath = path.split()
88 self.removepath = rpath
9+ self.checkpath = ""
910 def get_cachesize(self):
1011 cmd = ["du", "-sm",]
1112 cmd.extend(self.searchpath)
@@ -13,16 +14,52 @@ class clearcache():
1314 rawout = output.stdout.decode("UTF-8")
1415 size = [int(s) for s in rawout.split() if s.isdigit()][0]
1516 return size
16- def check_dir(self):
17- return os.path.isfile(r"/var/cache/apt/pkgcache.bin")
17+ def check_exists(self):
18+ return os.path.exists(self.checkpath)
1819
1920 def cleanit(self):
2021 cmd = "sudo rm -r " + self.removepath
2122 subprocess.run(cmd, shell=True)
22- return "Done"
23+ return "0"
2324
24-# Remove old kernels
25-class removekernel():
25+
26+class Cleanaptcache(Cleancache):
27+ def __init__(self):
28+ path = r"/var/cache/apt"
29+ super().__init__(path)
30+ self.checkpath = path + r"/package.bin"
31+ def main(self):
32+ if self.check_exists() == False:
33+ print("Do not have to clean APT cache.\n")
34+ return 0
35+ print("APT cache size is {} MiB.".format(self.get_cachesize()))
36+ print("Are you clean it?\nYes/no")
37+ anser = yesno(input(">"))
38+ if anser == True:
39+ self.cleanit()
40+ else:
41+ return 0
42+
43+class Cleanchromiumcache(Cleancache):
44+ def __init__(self):
45+ homedir = get_homedir()
46+ path = homedir + r"/.cache/chromium/Default/Cache"
47+ super().__init__(path)
48+ self.checkpath = path + r"/index"
49+ def main(self):
50+ if self.check_exists() == False:
51+ print("Do not have to clean Chromium cache or Chromium is not installed this computer.\n")
52+ return 0
53+ print("Chromium cache is {} MiB.".format(self.get_cachesize()))
54+ print("Are you clean it?\nYes/no")
55+ anser = yesno(input(">"))
56+ if anser == True:
57+ self.cleanit()
58+ else:
59+ return 0
60+
61+
62+class Removekernel():
2663 removed = []
2764 @classmethod
2865 def get_oldkernels(self):
@@ -33,7 +70,7 @@ class removekernel():
3370 olders = installing
3471 if not installing:
3572 print("Do not have to remove old kernel.")
36- exit(0)
73+ return 0
3774 terget = ("linux-headers-", "linux-image-")
3875 self.removed = [tgt + version for version in olders for tgt in terget ]
3976 return self.removed
@@ -43,8 +80,15 @@ class removekernel():
4380 command_l = cmd.split()
4481 command_l.extend(self.removed)
4582 subprocess.call(command_l)
46-
47-
83+
84+ def main(self):
85+ print("These package will be removed {}".format(self.get_oldkernels()))
86+ print("Are you remove them?\nYes/no")
87+ anser = yesno(input(">"))
88+ if anser == True:
89+ self.removethem()
90+ else:
91+ return 0
4892
4993 #Others
5094 def yesno(choice):
@@ -58,4 +102,50 @@ def yesno(choice):
58102 elif choice.upper() == 'N':
59103 return False
60104 else:
61- return "Error"
\ No newline at end of file
105+ return "Error"
106+
107+def get_homedir():
108+ output = subprocess.run(["whoami"], stdout=subprocess.PIPE)
109+ rawout = output.stdout.decode("UTF-8")
110+ homedir = rawout.rstrip()
111+ return r"/home/" + homedir
112+
113+def main():
114+ print("---------------------------")
115+ print("|Welcome to serene-cleaner|")
116+ print("---------------------------")
117+ while True:
118+
119+ print("Please choose a task")
120+ print("1. clean APT cache")
121+ print("2. clean Chromium cache")
122+ print("3. remove old kernels")
123+ print("0. exit")
124+ anser = input(">")
125+ if anser == "":
126+ print("Please type integer\n")
127+ continue
128+ choice = 0
129+ try:
130+ choice = int(anser[0])
131+ except ValueError:
132+ print("Please type integer\n")
133+ continue
134+
135+ if choice == 1:
136+ call = Cleanaptcache()
137+ call.main()
138+ elif choice == 2:
139+ call = Cleanchromiumcache()
140+ call.main()
141+ elif choice == 3:
142+ call = Removekernel()
143+ call.main()
144+ elif choice == 0:
145+ exit(0)
146+ else:
147+ print("Please choose from the option\n")
148+ continue
149+
150+if __name__ == "__main__":
151+ main()
\ No newline at end of file
Show on old repository browser