Browse Source

no regex

keep-around/e977c9e07f177e8bc2b51265de1bc93475397f61
parazyd 6 years ago
parent
commit
fe689ce0c3
Signed by untrusted user: parazyd GPG Key ID: F0CB28FCF78637DE
  1. 2
      lib/package.py
  2. 33
      lib/parse.py

2
lib/package.py

@ -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.

33
lib/parse.py

@ -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:

Loading…
Cancel
Save