You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import subprocess
  2. from i3pystatus import IntervalModule, formatp
  3. class ArchUpdates(IntervalModule):
  4. settings = (
  5. "format",
  6. "format_down",
  7. "color",
  8. )
  9. interval = 60
  10. format = "Update count: {count_pacman} {count_yaourt}"
  11. format_down = ""
  12. color = "#FFFFFF"
  13. # clicking on it after installing updates will dismiss the notification
  14. on_leftclick = "run"
  15. def run(self):
  16. # We updates the db
  17. command = ["sudo", "yaourt", "-Sya"]
  18. subprocess.Popen(command, stdout=subprocess.PIPE,
  19. stderr=subprocess.DEVNULL)
  20. count_pacman = self.get_count(["yaourt", "-Qu"])
  21. count_yaourt = self.get_count(["yaourt", "-Qua"])
  22. format = self.format if count_yaourt else self.format_down
  23. count_yaourt -= count_pacman
  24. fdict = {
  25. "count_pacman": count_pacman,
  26. "count_yaourt": count_yaourt,
  27. }
  28. self.output = {
  29. "full_text": formatp(format, **fdict).strip(),
  30. "color": self.color,
  31. }
  32. return
  33. def get_count(self, command):
  34. check_pacman = subprocess.Popen(command, stdout=subprocess.PIPE,
  35. stderr=subprocess.DEVNULL)
  36. output = check_pacman.communicate()[0].decode("UTF-8").strip()
  37. return len(output.split("\n")) if len(output) > 0 else 0