2022-09-24 19:45:26 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-08-14 00:56:14 +00:00
|
|
|
|
2022-05-04 20:45:52 +00:00
|
|
|
import subprocess
|
|
|
|
from getpass import getpass
|
|
|
|
from sys import argv
|
|
|
|
|
|
|
|
|
|
|
|
def run(command, **kwargs):
|
|
|
|
return subprocess.run(command, shell=True, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def cap_live_lines(command, **kwargs):
|
|
|
|
lines = []
|
|
|
|
with subprocess.Popen(
|
|
|
|
command, shell=True, stdout=subprocess.PIPE, text=True, **kwargs
|
|
|
|
) as proc:
|
|
|
|
for line in proc.stdout:
|
|
|
|
print(line, end="")
|
|
|
|
lines.append(line.strip())
|
|
|
|
|
|
|
|
return lines
|
|
|
|
|
|
|
|
|
|
|
|
def press_to_exit():
|
2022-06-16 20:21:33 +00:00
|
|
|
getpass("\n<<-<>===EXIT===<>->>")
|
2022-05-04 20:45:52 +00:00
|
|
|
|
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
def update_rpm_ostree():
|
|
|
|
lines = cap_live_lines("rpm-ostree upgrade")
|
2022-05-04 20:45:52 +00:00
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
if "no upgrade" not in lines[-1].lower():
|
|
|
|
press_to_exit()
|
2022-05-04 20:45:52 +00:00
|
|
|
|
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
def update_flatpak():
|
|
|
|
lines = cap_live_lines("flatpak update -y")
|
|
|
|
done_updates = "nothing to do" not in lines[-1].lower()
|
2022-05-04 20:45:52 +00:00
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
run("flatpak remove --delete-data --unused")
|
2022-05-04 20:45:52 +00:00
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
if done_updates:
|
|
|
|
press_to_exit()
|
|
|
|
|
|
|
|
|
2022-06-16 20:21:33 +00:00
|
|
|
def update_cargo():
|
2022-10-16 15:21:26 +00:00
|
|
|
lines = cap_live_lines("rustup update && cargo install-update -a")
|
2022-06-16 20:21:33 +00:00
|
|
|
|
|
|
|
if "no packages need updating" not in lines[-2].lower():
|
|
|
|
press_to_exit()
|
|
|
|
|
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
def main(input):
|
2022-06-14 16:09:47 +00:00
|
|
|
if input == "rpm-ostree":
|
2022-05-14 00:15:17 +00:00
|
|
|
update_rpm_ostree()
|
|
|
|
elif input == "flatpak":
|
|
|
|
update_flatpak()
|
|
|
|
elif input == "cargo":
|
|
|
|
update_cargo()
|
2022-05-04 20:45:52 +00:00
|
|
|
else:
|
|
|
|
print(f"Input {input} not valid!")
|
|
|
|
|
|
|
|
|
2022-05-14 00:15:17 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main(argv[1])
|