show_updates.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Shows available updates for Arch and Debian Linux.
  4. import subprocess
  5. def show_updates_debian():
  6. """Show updates for Debian Linux."""
  7. updates = ""
  8. updates_list = []
  9. try:
  10. updates = subprocess.check_output(["apt-show-versions", "-u", "-b"], encoding="utf-8").strip()
  11. # updates = subprocess.check_output(["apt-show-versions", "-u", "-b"]).decode("utf-8").strip()
  12. updates_list = updates.splitlines()
  13. except subprocess.CalledProcessError:
  14. updates_output = ""
  15. else:
  16. updates_output = "\nAvailable: {}{}".format(len(updates_list), updates)
  17. subprocess.call(["notify-send", "-i", "software-update-available", "Updates: {}".format(updates_output)])
  18. # subprocess.call(["notify-send", "-i", "software-update-available", "Updates: {} \n\n{}".format(len(updates_list), updates)])
  19. def show_updates_arch():
  20. """Show updates for Arch Linux."""
  21. amount_updates = 0
  22. def check_community():
  23. """Check community repo."""
  24. updates_community = ""
  25. updates_community_list = []
  26. try:
  27. # updates_community = subprocess.check_output(["pacman", "-Q", "-u"]).decode("utf-8").strip()
  28. # updates_community = subprocess.check_output(["checkupdates"]).decode("utf-8").strip()
  29. updates_community = subprocess.check_output(["checkupdates"], encoding="utf-8").strip()
  30. updates_community_list = updates_community.splitlines()
  31. except subprocess.CalledProcessError:
  32. community_output = ""
  33. else:
  34. community_output = ("\n\nCommunity: {}\n{}".format(len(updates_community_list), updates_community)
  35. if updates_community_list else "")
  36. nonlocal amount_updates
  37. amount_updates += len(updates_community_list)
  38. return community_output
  39. def check_aur():
  40. """Check AUR repo."""
  41. updates_aur = ""
  42. updates_aur_list = []
  43. try:
  44. # updates_aur = subprocess.check_output(["paru", "-Q", "-u", "-a"]).decode("utf-8").strip()
  45. # updates_aur = subprocess.check_output(["checkupdates-aur"]).decode("utf-8").strip()
  46. updates_aur = subprocess.check_output(["yay", "-Q", "-u", "-a"]).decode("utf-8").strip()
  47. updates_aur_list = updates_aur.splitlines()
  48. except subprocess.CalledProcessError:
  49. aur_output = ""
  50. else:
  51. aur_output = ("\n\nAUR: {}\n{}".format(len(updates_aur_list), updates_aur)
  52. if updates_aur_list else "")
  53. nonlocal amount_updates
  54. amount_updates += len(updates_aur_list)
  55. return aur_output
  56. subprocess.call(["notify-send", "-i", "software-update-available", "Updates: {amount_updates}{}{}".format(check_community(), check_aur(), amount_updates=amount_updates)])