Created
November 2, 2019 13:37
-
-
Save vifly/33d1a4f63b0b7319c6db9af9d3bdbdb0 to your computer and use it in GitHub Desktop.
删除 kde-applications 中属于教育或游戏分类的应用,需要 root 权限,使用需谨慎
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import glob | |
def is_need_remove(file_path): | |
with open(file_path, 'r') as f: | |
content = f.readlines() | |
for line in content: | |
if line.split("=")[0] == "Categories": | |
categories = line.split("=")[1] | |
# 如果分类字段里有 Education 或 Game,那么认为是需要删除的 | |
if "Education" in categories or "Game" in categories: | |
return True | |
else: | |
return False | |
for desktop_file in glob.glob("/usr/share/applications/*"): | |
if is_need_remove(desktop_file): | |
query_command = "pacman -Qoq " + desktop_file | |
# 查询该 desktop 文件属于哪个软件包 | |
package_name = subprocess.run(query_command, shell=True, stdout = subprocess.PIPE) | |
package_name = package_name.stdout.decode("utf-8").strip() | |
remove_command = "pacman -Rsc " + package_name + " --noconfirm" | |
print(remove_command) | |
# 移除软件包 | |
result = subprocess.run(remove_command, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment