From 61a264de46913269780852560f45316b36e7e6fb Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Mon, 18 Feb 2008 16:17:57 -0800 Subject: [PATCH] Use python-debian for parsing RFC 822 files (untested). --- TODO | 7 ------- apt_dht/AptPackages.py | 27 +++++---------------------- apt_dht/Hash.py | 2 +- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/TODO b/TODO index 9cef5c7..7875203 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,3 @@ -Use python-debian for parsing RFC 822 files. - -There are already routines for parsing these files, so there is no need -to write more. In the AptPackages, change the Release file parsing to -use the python-debian routines. - - Packages.diff files need to be considered. The Packages.diff/Index files contain hashes of Packages.diff/rred.gz diff --git a/apt_dht/AptPackages.py b/apt_dht/AptPackages.py index 11a1c78..1c38a00 100644 --- a/apt_dht/AptPackages.py +++ b/apt_dht/AptPackages.py @@ -15,6 +15,7 @@ from twisted.trial import unittest import apt_pkg, apt_inst from apt import OpProgress +from debian_bundle import deb822 from Hash import HashObject @@ -154,29 +155,11 @@ class AptPackages: read_packages = False f = file_path.open('r') - for line in f: - line = line.rstrip() - - if line[:1] != " ": - read_packages = False - try: - # Read the various headers from the file - h, v = line.split(":", 1) - if h == "MD5Sum" or h == "SHA1" or h == "SHA256": - read_packages = True - hash_type = h - except: - # Bad header line, just ignore it - log.msg("WARNING: Ignoring badly formatted Release line: %s" % line) - - # Skip to the next line - continue + rel = deb822.Release(f, fields = ['MD5Sum', 'SHA1', 'SHA256']) + for hash_type in rel: + for file in rel[hash_type]: + self.indexrecords[cache_path].setdefault(file['name'], {})[hash_type.upper()] = (file['hash_type'], file['size']) - # Read file names from the multiple hash sections of the file - if read_packages: - p = line.split() - self.indexrecords[cache_path].setdefault(p[2], {})[hash_type] = (p[0], p[1]) - f.close() def file_updated(self, cache_path, file_path): diff --git a/apt_dht/Hash.py b/apt_dht/Hash.py index 2223876..933fdb5 100644 --- a/apt_dht/Hash.py +++ b/apt_dht/Hash.py @@ -28,7 +28,7 @@ class HashObject: {'name': 'md5', 'AptPkgRecord': 'MD5Hash', 'AptSrcRecord': True, - 'AptIndexRecord': 'MD5Sum', + 'AptIndexRecord': 'MD5SUM', 'old_module': 'md5', 'hashlib_func': 'md5', }, -- 2.30.2