dnf-qubes-hooks.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if LooseVersion(dnf.const.VERSION) > '4.0.0':
  41. # self.base.transaction empty at this point in dnf4
  42. # https://bugzilla.redhat.com/1650446
  43. # until fixed, load the repositories again and again check for
  44. # updates
  45. base = dnf.Base()
  46. base.read_all_repos()
  47. base.fill_sack()
  48. query = base.sack.query()
  49. query = query.upgrades()
  50. updates = set(query.run())
  51. else:
  52. # Get all updates available _before_ this transaction
  53. query = self.base.sack.query()
  54. query = query.upgrades()
  55. updates = set(query.run())
  56. # Get packages installed in this transaction...
  57. just_installed = self.base.transaction
  58. # ...and filter them out of available updates
  59. for item in just_installed:
  60. for pkg in item.installs():
  61. updates.discard(pkg)
  62. subprocess.call([
  63. '/usr/lib/qubes/qrexec-client-vm',
  64. 'dom0',
  65. 'qubes.NotifyUpdates',
  66. '/bin/echo',
  67. str(len(updates))
  68. ])
  69. self.log.info("Notifying dom0 about installed applications")
  70. subprocess.call(['/etc/qubes-rpc/qubes.PostInstall'])