dakapt.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. interfaces around python-apt
  4. @copyright: 2020 😸 <😸@43-1.org>
  5. @license: GNU General Public License version 2 or later
  6. """
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. import apt_pkg
  20. class DakHashes(object):
  21. """
  22. wrapper around `apt_pkg.Hashes`
  23. """
  24. def __init__(self, *args, **kwargs):
  25. self._apt_hashes = apt_pkg.Hashes(*args, **kwargs)
  26. # python-apt in Debian 10 (buster) uses
  27. # `apt_pkg.Hashes(...).md5`
  28. # but in Debian bullseye it switched to
  29. # `apt_pkg.Hashes(...).find('md5sum').hashvalue`
  30. def _hashvalue(self, attr, name):
  31. if hasattr(self._apt_hashes, attr):
  32. return getattr(self._apt_hashes, attr)
  33. else:
  34. return self._apt_hashes.hashes.find(name).hashvalue
  35. @property
  36. def md5(self):
  37. return self._hashvalue('md5', 'md5sum')
  38. @property
  39. def sha1(self):
  40. return self._hashvalue('sha1', 'sha1')
  41. @property
  42. def sha256(self):
  43. return self._hashvalue('sha256', 'sha256')