dnf-qubes-hooks.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 resolved(self):
  35. # in case of no action to do, transaction() hook won't be called;
  36. # report updates availability here - especially when everything is up
  37. # to date - to clear updates-available flag
  38. if not self.base.transaction:
  39. query = self.base.sack.query()
  40. query = query.upgrades()
  41. updates = set(query.run())
  42. subprocess.call([
  43. '/usr/lib/qubes/qrexec-client-vm',
  44. 'dom0',
  45. 'qubes.NotifyUpdates',
  46. '/bin/echo',
  47. str(len(updates))
  48. ])
  49. def transaction(self):
  50. if LooseVersion(dnf.const.VERSION) < '2.0.0':
  51. config = self.read_config(self.base.conf, PLUGIN_CONF)
  52. else:
  53. config = self.read_config(self.base.conf)
  54. if config.getboolean('main', 'notify-updates'):
  55. # Get all updates available _before_ this transaction
  56. query = self.base.sack.query()
  57. query = query.upgrades()
  58. updates = set(query.run())
  59. # Get packages installed in this transaction...
  60. just_installed = self.base.transaction
  61. # ...and filter them out of available updates
  62. for item in just_installed:
  63. updates.discard(item.pkg)
  64. subprocess.call([
  65. '/usr/lib/qubes/qrexec-client-vm',
  66. 'dom0',
  67. 'qubes.NotifyUpdates',
  68. '/bin/echo',
  69. str(len(updates))
  70. ])
  71. self.log.info("Notifying dom0 about installed applications")
  72. subprocess.call(['/etc/qubes-rpc/qubes.PostInstall'])