qubes.GetDate 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  20. #
  21. import qubesadmin
  22. import datetime
  23. import subprocess
  24. def main():
  25. app = qubesadmin.Qubes()
  26. clockvm = app.clockvm
  27. if clockvm is None:
  28. return
  29. if not clockvm.is_running():
  30. # print dom0 time if clockvm is not running
  31. print(datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S+00:00'))
  32. else:
  33. # passthrough request to the clockvm
  34. p = clockvm.run_service('qubes.GetDate', stdout=None, stdin=subprocess.DEVNULL)
  35. p.wait()
  36. if __name__ == '__main__':
  37. main()