launch.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # shutil.which supported from Python 3.3+
  2. from shutil import which
  3. from json import loads
  4. import subprocess
  5. class Launch:
  6. # Check if a shell command is available on the system.
  7. @staticmethod
  8. def check_shell_tool(name):
  9. return which(name) is not None
  10. @staticmethod
  11. def check_py_gtk():
  12. try:
  13. import gi
  14. gi.require_version('Gtk', '3.0')
  15. from gi.repository import Gtk, Gdk, GdkPixbuf
  16. return True
  17. except ModuleNotFoundError:
  18. return False
  19. @staticmethod
  20. def check_py_toml():
  21. try:
  22. import toml
  23. return True
  24. except ModuleNotFoundError:
  25. return False
  26. @staticmethod
  27. def check_sox():
  28. return Launch.check_shell_tool("sox")
  29. @staticmethod
  30. def check_sox_pulse():
  31. sox_help = subprocess.run(["sox", "--help"], capture_output=True, encoding="utf8")
  32. stdout = sox_help.stdout
  33. sox_drivers_prefix = "AUDIO DEVICE DRIVERS: "
  34. for line in stdout.split("\n"):
  35. if line.startswith(sox_drivers_prefix):
  36. drivers = line[len(sox_drivers_prefix):].split(" ")
  37. return "pulseaudio" in drivers
  38. return False
  39. @staticmethod
  40. def check_pactl():
  41. return Launch.check_shell_tool("pactl")
  42. @staticmethod
  43. def determine_audio_server():
  44. pactl_info = subprocess.run(["pactl", "--format=json", "info"], capture_output=True, encoding="utf8")
  45. server_info = loads(pactl_info.stdout)
  46. if "server_name" in server_info:
  47. return server_info["server_name"]
  48. return None