qubes-set-updates 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/python2
  2. import os
  3. import sys
  4. from qubes.qubes import QubesVmCollection
  5. from qubes.qubesutils import updates_vms_toggle,updates_dom0_toggle,\
  6. updates_dom0_status
  7. def usage():
  8. print "Usage: qubes-set-updates enable|disable|status"
  9. print " Enable or disable globally checking for updates (both dom0 and VM)"
  10. print " Status option checks only dom0 updates status"
  11. def main():
  12. if len(sys.argv) < 2:
  13. usage()
  14. return 1
  15. action = sys.argv[1]
  16. if action not in ['enable', 'disable', 'status']:
  17. usage()
  18. return 1
  19. qvm_collection = QubesVmCollection()
  20. if action == 'status':
  21. qvm_collection.lock_db_for_reading()
  22. else:
  23. qvm_collection.lock_db_for_writing()
  24. qvm_collection.load()
  25. if action == 'enable':
  26. updates_dom0_toggle(qvm_collection, True)
  27. updates_vms_toggle(qvm_collection, True)
  28. elif action == 'disable':
  29. updates_dom0_toggle(qvm_collection, False)
  30. updates_vms_toggle(qvm_collection, False)
  31. else:
  32. if updates_dom0_status(qvm_collection):
  33. print "enabled"
  34. else:
  35. print "disabled"
  36. if action != 'status':
  37. qvm_collection.save()
  38. qvm_collection.unlock_db()
  39. if __name__ == "__main__":
  40. main()