dnf-qubes-hooks.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. from distutils.version import LooseVersion
  23. import logging
  24. import dnf
  25. import dnf.const
  26. import subprocess
  27. PLUGIN_CONF = 'qubes-hooks'
  28. class QubesHooks(dnf.Plugin):
  29. name = 'qubes-hooks'
  30. def __init__(self, base, cli):
  31. super(QubesHooks, self).__init__(base, cli)
  32. self.base = base
  33. self.log = logging.getLogger('dnf')
  34. def transaction(self):
  35. if LooseVersion(dnf.const.VERSION) < '2.0.0':
  36. config = self.read_config(self.base.conf, PLUGIN_CONF)
  37. else:
  38. config = self.read_config(self.base.conf)
  39. if config.getboolean('main', 'notify-updates'):
  40. # Get all updates available _before_ this transaction
  41. query = self.base.sack.query()
  42. query = query.upgrades()
  43. updates = set(query.run())
  44. # Get packages installed in this transaction...
  45. just_installed = self.base.transaction
  46. # ...and filter them out of available updates
  47. for item in just_installed:
  48. for pkg in item.installs():
  49. updates.discard(pkg)
  50. subprocess.call([
  51. '/usr/lib/qubes/qrexec-client-vm',
  52. 'dom0',
  53. 'qubes.NotifyUpdates',
  54. '/bin/echo',
  55. str(len(updates))
  56. ])
  57. self.log.info("Notifying dom0 about installed applications")
  58. subprocess.call(['/etc/qubes-rpc/qubes.PostInstall'])