dnf-qubes-hooks.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/python
  2. # coding=utf-8
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2015 Marek Marczykowski-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. from __future__ import absolute_import
  23. import logging
  24. import dnf
  25. import subprocess
  26. PLUGIN_CONF = 'qubes-hooks'
  27. class QubesHooks(dnf.Plugin):
  28. name = 'qubes-hooks'
  29. def __init__(self, base, cli):
  30. super(QubesHooks, self).__init__(base, cli)
  31. self.base = base
  32. self.log = logging.getLogger('dnf')
  33. def transaction(self):
  34. config = self.read_config(self.base.conf, PLUGIN_CONF)
  35. if config.getboolean('main', 'notify-updates'):
  36. # Get all updates available _before_ this transaction
  37. query = self.base.sack.query()
  38. query = query.upgrades()
  39. updates = set(query.run())
  40. # Get packages installed in this transaction...
  41. just_installed = self.base.transaction
  42. # ...and filter them out of available updates
  43. for item in just_installed:
  44. for pkg in item.installs():
  45. updates.discard(pkg)
  46. subprocess.call([
  47. '/usr/lib/qubes/qrexec-client-vm',
  48. 'dom0',
  49. 'qubes.NotifyUpdates',
  50. '/bin/echo',
  51. str(len(updates))
  52. ])
  53. if config.getboolean('main', 'sync-appmenus'):
  54. self.log.info("Sending application list and icons to dom0")
  55. subprocess.call(['/usr/lib/qubes/qubes-trigger-sync-appmenus.sh'])