tno regex - amprolla - devuan's apt repo merger (HTM) git clone git://parazyd.org/amprolla.git (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit fe689ce0c36c11c7f5c5e00b645a9ca82f3e4d07 (DIR) parent 4316ce594f8e9d5d35c174b5daae7f33a02672e6 (HTM) Author: parazyd <parazyd@dyne.org> Date: Fri, 26 May 2017 15:22:15 +0200 no regex Diffstat: M lib/package.py | 2 +- M lib/parse.py | 33 ++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) --- (DIR) diff --git a/lib/package.py b/lib/package.py t@@ -3,7 +3,7 @@ from gzip import open as gzip_open from lib.parse import (parse_packages, parse_dependencies) from lib.config import packages_keys -def write_packages(packages, filename, sort=False): +def write_packages(packages, filename, sort=True): """ Writes `packages` to a file (per debian Packages format) If sort=True, the packages are sorted by name. (DIR) diff --git a/lib/parse.py b/lib/parse.py t@@ -17,14 +17,37 @@ def get_time(date): def get_date(relfile): - match = re.search('Date: .+', relfile) - if match: - line = relfile[match.start():match.end()] - relfile = line.split(': ')[1] - return relfile + date = None + contents = relfile.split('\n') + for line in contents: + if line.startswith('Date: '): + date = line.split(': ')[1] + break + return date def parse_release(reltext): + """ + Parses a Release file and returns a dict of the files we need + key = filename, value = sha256 checksum + """ + hashes = {} + + contents = reltext.split('\n') + + sha256 = False + for line in contents: + if sha256 is True and line != '': + filename = line.split()[2] + checksum = line.split()[0] + hashes[filename] = checksum + elif line.startswith('SHA256:'): + sha256 = True + + return hashes + + +def parse_release_re(reltext): _hash = {} match = re.search('SHA256:+', reltext) if match: