Last active
October 4, 2024 23:46
-
-
Save AllanRPereira/13c83aab80bb6bebc651fb570e6b9094 to your computer and use it in GitHub Desktop.
Cálcula espaço gasto por pacotes instalados utilizando o gerenciador apt
This file contains hidden or 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
| """ | |
| Software para listar o tamanho de todos os softwares instalados | |
| com o gerenciador de pacotes apt | |
| """ | |
| import subprocess | |
| from json import dump | |
| pacotes = subprocess.run(["dpkg", "-l"], capture_output=True) | |
| lista_pacotes = [] | |
| for pacote in pacotes.stdout.decode("utf-8").split("\n")[5:]: | |
| try: | |
| tmp = [] | |
| for elemento in pacote.split(" "): | |
| if (elemento != ""): | |
| tmp.append(elemento) | |
| if len(tmp) > 1: | |
| lista_pacotes.append(tmp[1]) | |
| except: | |
| pass | |
| tamanhos = {} | |
| for pacote in lista_pacotes: | |
| dpkg_process = subprocess.Popen(["dpkg", "-s", pacote], stdout=subprocess.PIPE, text=True) | |
| dados = subprocess.Popen(["grep", "Size"], stdin=dpkg_process.stdout, stdout=subprocess.PIPE, text=True) | |
| output, error = dados.communicate() | |
| output = output.split(" ")[1] | |
| tamanhos[pacote] = round(int(output) / 1024) | |
| with open("dados.json", "w") as file: | |
| dump(tamanhos, file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment