dnf-qubes-hooks.py 2.2 KB

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