diff options
Diffstat (limited to 'importpkg.py')
-rwxr-xr-x | importpkg.py | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/importpkg.py b/importpkg.py index 4f00407..160fe9e 100755 --- a/importpkg.py +++ b/importpkg.py @@ -8,32 +8,48 @@ And finally a document consisting of the string "commit" is emitted.""" import argparse import hashlib import sys +import tarfile import urllib.request import zlib +import debian.deb822 import yaml from dedup.debpkg import DebExtractor, get_tar_hashes -from dedup.hashing import DecompressedHash, SuppressingHash, HashedStream, \ - HashBlacklistContent +from dedup.hashing import ( + DecompressedHash, + HashBlacklistContent, + HashedStream, + HashlibLike, + SuppressingHash, +) from dedup.compression import GzipDecompressor from dedup.image import GIFHash, PNGHash boring_content = set((b"", b"\n")) -def sha512_nontrivial(): + +def sha512_nontrivial() -> HashlibLike: return HashBlacklistContent(hashlib.sha512(), boring_content) -def gziphash(): - hashobj = hashlib.sha512() - hashobj = DecompressedHash(GzipDecompressor(), hashobj, "gzip_sha512") - hashobj = SuppressingHash(hashobj, (ValueError, zlib.error)) - return HashBlacklistContent(hashobj, boring_content) -def pnghash(): +def gziphash() -> HashlibLike: + return HashBlacklistContent( + SuppressingHash( + DecompressedHash( + GzipDecompressor(), hashlib.sha512(), "gzip_sha512" + ), + (ValueError, zlib.error), + ), + boring_content, + ) + + +def pnghash() -> HashlibLike: return SuppressingHash(PNGHash(hashlib.sha512()), (ValueError,)) -def gifhash(): + +def gifhash() -> HashlibLike: return SuppressingHash(GIFHash(hashlib.sha512()), (ValueError,)) class ProcessingFinished(Exception): @@ -42,11 +58,11 @@ class ProcessingFinished(Exception): class ImportpkgExtractor(DebExtractor): hash_functions = [sha512_nontrivial, gziphash, pnghash, gifhash] - def __init__(self, callback): + def __init__(self, callback) -> None: DebExtractor.__init__(self) self.callback = callback - def handle_control_info(self, info): + def handle_control_info(self, info: debian.deb822.Packages) -> None: try: source = info["source"].split()[0] except KeyError: @@ -60,7 +76,7 @@ class ImportpkgExtractor(DebExtractor): version=info["version"], architecture=info["architecture"], depends=depends)) - def handle_data_tar(self, tarfileobj): + def handle_data_tar(self, tarfileobj: tarfile.TarFile) -> None: for name, size, hashes in get_tar_hashes(tarfileobj, self.hash_functions): try: @@ -71,7 +87,8 @@ class ImportpkgExtractor(DebExtractor): self.callback(dict(name=name, size=size, hashes=hashes)) raise ProcessingFinished() -def main(): + +def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("-H", "--hash", action="store", help="verify that stdin hash given sha256 hash") |