service_manager.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # systemctl-mqtt - MQTT client triggering & reporting shutdown on systemd-based systems
  2. #
  3. # Copyright (C) 2024 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import jeepney
  18. import systemctl_mqtt._dbus
  19. class ServiceManager(jeepney.MessageGenerator):
  20. """
  21. https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html
  22. """
  23. # pylint: disable=too-few-public-methods
  24. interface = "org.freedesktop.systemd1.Manager"
  25. def __init__(self):
  26. super().__init__(
  27. object_path="/org/freedesktop/systemd1", bus_name="org.freedesktop.systemd1"
  28. )
  29. # pylint: disable=invalid-name
  30. def GetUnit(self, name: str) -> jeepney.low_level.Message:
  31. return jeepney.new_method_call(
  32. remote_obj=self, method="GetUnit", signature="s", body=(name,)
  33. )
  34. class Unit(systemctl_mqtt._dbus.Properties): # pylint: disable=protected-access
  35. """
  36. https://www.freedesktop.org/software/systemd/man/latest/org.freedesktop.systemd1.html#Unit%20Objects
  37. """
  38. # pylint: disable=too-few-public-methods
  39. interface = "org.freedesktop.systemd1.Unit"
  40. def __init__(self, *, object_path: str):
  41. super().__init__(object_path=object_path, bus_name="org.freedesktop.systemd1")
  42. # pylint: disable=invalid-name