• R/O
  • HTTP
  • SSH
  • HTTPS

serene-cleaner: Commit


Commit MetaInfo

Revisiond71013f92c3f1ee1eccb15aa6e02f8179300a790 (tree)
Zeit2019-07-26 13:04:23
Autorksmt4699 <ksmt4699@gmai...>
Commiterksmt4699

Log Message

testingブランチよりマージ

Ändern Zusammenfassung

Diff

--- a/main/serene-cleaner.py
+++ b/main/serene-cleaner.py
@@ -1,50 +1,56 @@
11 #!/usr/bin/env python3
22 import subprocess
3+<<<<<<< HEAD
4+=======
5+import argparse
6+import re
7+
8+task_dict = {"clean APT cache": "cleanaptcache", "remove old kernels": "removekernel"}
9+
10+>>>>>>> testing
311 # Remove APT cache
4-def removeaptcache(self):
5- print("APTcache size is {}. Are you remove it? Y/n")
12+def cleanaptcache():
13+ print("APT-cache size is {}MiB.\nAre you clean it?".format(get_aptcachesize()))
14+ anser = yesno(input("Y/n "))
15+ if anser == True:
16+ cleanit()
17+ else:
18+ return 0
619
7-def get_aptcachesize(self):
8- return subprocess.check_output(["echo", "${$(du", "-s", "/var/cache/apt)%%/var/cache/apt}"])
20+def get_aptcachesize():
21+ output = subprocess.run(["sudo", "du", "-sm", "/var/cache/apt"], stdout=subprocess.PIPE)
22+ rawout = output.stdout.decode("UTF-8")
23+ size = [int(s) for s in rawout.split() if s.isdigit()][0]
24+ return size
925
10-def removeit(self):
11- return subprocess.check_output(["apt-get", "clean"])
26+def cleanit():
27+ return subprocess.check_output(["sudo", "apt-get", "clean"])
1228
1329
1430 # Remove old kernels
1531 def removekernel():
32+ olders = []
33+ removed = []
1634 def get_oldkernels():
35+ global olders
36+ global removed
1737 output = subprocess.run(r'dpkg -l | grep -Eo "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+[0-9]" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -nr', shell=True, stdout=subprocess.PIPE)
18- version = output.stdout.decode("UTF-8")
19- installing = version.splitlines()
38+ rawout = output.stdout.decode("UTF-8")
39+ installing = rawout.splitlines()
2040 del installing[0]
41+ olders = installing
2142 if not installing:
2243 print("Do not have to remove old kernel.")
2344 exit(0)
24- olders = tuple(installing)
25- return olders
26-
27- def formating(*args):# args type = string ! Do not number
28- olders = []
29- for i in range(len(args)):
30- olders.append(args[i][i])
31-
3245 terget = ("linux-headers-", "linux-image-")
33- removed = []
34- for version in olders:
35- for tgt in terget:
36- removed.append(tgt + version)
37- #removed = [tgt + version for version in olders for tgt in terget ]
46+ removed = [tgt + version for version in olders for tgt in terget ]
3847 return removed
3948
40- def removethem(*args):
41- removed_l = []
42- for i in range(len(args)):
43- for n in range(len(args[i])):
44- removed_l.append(args[i][n])
49+ def removethem():
50+ global removed
4551 cmd = "sudo apt-get --purge -y autoremove"
4652 command_l = cmd.split()
47- command_l.extend(removed_l)
53+ command_l.extend(removed)
4854 subprocess.call(command_l)
4955
5056 #Main
@@ -52,7 +58,7 @@ def removekernel():
5258 print("Are you remove them? Y/n")
5359 anser = yesno(input())
5460 if anser == True:
55- removethem(formating(get_oldkernels()))
61+ removethem()
5662 else:
5763 return 0
5864
@@ -71,4 +77,15 @@ def yesno(choice):
7177 else:
7278 return "Error"
7379
74-removekernel()
80+def swich(choice):
81+ if choice == "":
82+ return "Error"
83+ try:
84+ choice = int(choice[0])
85+ except ValueError:
86+ return "Please enter as an integer."
87+ try:
88+ task = list[choice - 1]
89+ except IndexError:
90+ return "The task is not find."
91+ return task
\ No newline at end of file
Show on old repository browser