diff --git a/daklib/dakapt.py b/daklib/dakapt.py
new file mode 100644
index 0000000000000000000000000000000000000000..676215eef78f610e94d55997921c723bf139111b
--- /dev/null
+++ b/daklib/dakapt.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+"""
+interfaces around python-apt
+
+@copyright: 2020 😸 <😸@43-1.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+import apt_pkg
+
+"""
+wrapper around `apt_pkg.Hashes`
+"""
+class DakHashes(object):
+ def __init__(self, *args, **kwargs):
+ self._apt_hashes = apt_pkg.Hashes(*args, **kwargs)
+
+ # python-apt in Debian 10 (buster) uses
+ # `apt_pkg.Hashes(...).md5`
+ # but in Debian bullseye it switched to
+ # `apt_pkg.Hashes(...).find('md5sum').hashvalue`
+ def _hashvalue(self, attr, name):
+ if hasattr(self._apt_hashes, attr):
+ return getattr(self._apt_hashes, attr)
+ else:
+ return self._apt_hashes.hashes.find(name).hashvalue
+
+ @property
+ def md5(self):
+ return self._hashvalue('md5', 'md5sum')
+
+ @property
+ def sha1(self):
+ return self._hashvalue('sha1', 'sha1')
+
+ @property
+ def sha256(self):
+ return self._hashvalue('sha256', 'sha256')
diff --git a/daklib/import_repository.py b/daklib/import_repository.py
index 08b64461ddcd1034c4d647880af8c25be9ec5ba6..fa2050be87699264e8b7e144461dcfefcf7bb9a9 100644
--- a/daklib/import_repository.py
+++ b/daklib/import_repository.py
@@ -16,6 +16,7 @@
import daklib.compress
import daklib.config
+import daklib.dakapt
import daklib.dbconn
import daklib.gpg
import daklib.upload
@@ -79,7 +80,7 @@ class File(object):
return self._tmp
def hashes(self):
- return apt_pkg.Hashes(self.fh())
+ return daklib.dakapt.DakHashes(self.fh())
def obtain_file(base, path):
diff --git a/daklib/upload.py b/daklib/upload.py
index 374dabf3343f2d36e72f1872db46f01ece3bc624..f114f18b26fee8c6ef1102f3cf70abc93ce12fb8 100644
--- a/daklib/upload.py
+++ b/daklib/upload.py
@@ -31,6 +31,7 @@ import six
from daklib.aptversion import AptVersion
from daklib.gpg import SignedFile
from daklib.regexes import *
+import daklib.dakapt
import daklib.packagelist
@@ -156,7 +157,7 @@ class HashedFile(object):
path = os.path.join(directory, filename)
with open(path, 'r') as fh:
size = os.fstat(fh.fileno()).st_size
- hashes = apt_pkg.Hashes(fh)
+ hashes = daklib.dakapt.DakHashes(fh)
return cls(filename, size, hashes.md5, hashes.sha1, hashes.sha256, section, priority)
def check(self, directory):
@@ -181,7 +182,7 @@ class HashedFile(object):
def check_fh(self, fh):
size = os.fstat(fh.fileno()).st_size
fh.seek(0)
- hashes = apt_pkg.Hashes(fh)
+ hashes = daklib.dakapt.DakHashes(fh)
if size != self.size:
raise InvalidHashException(self.filename, 'size', self.size, size)
diff --git a/tests/test_daklib_dakapt.py b/tests/test_daklib_dakapt.py
new file mode 100644
index 0000000000000000000000000000000000000000..4d76dbf0d561cbac50aed530b445d34ff1fd5dcb
--- /dev/null
+++ b/tests/test_daklib_dakapt.py
@@ -0,0 +1,31 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# © 2020, 😸 <😸@43-1.org>
+#
+# License: GPL-2+
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+from base_test import DakTestCase
+
+import daklib.dakapt
+
+class TestDakHashes(DakTestCase):
+ def testDakHashes(self):
+ hashes = daklib.dakapt.DakHashes("/dev/null")
+ self.assertEqual(hashes.md5, "d41d8cd98f00b204e9800998ecf8427e")
+ self.assertEqual(hashes.sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709")
+ self.assertEqual(hashes.sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")