hacking on sanitizing the lines now in the release file

This commit is contained in:
Brendan McDevitt 2022-08-21 07:12:21 -05:00
parent 5f00b4e581
commit f6b42a71ce

View file

@ -6,7 +6,7 @@ import json
from meta_release import SourceMetaRelease, MetaRelease
RELEASE_WORD_MATCHER = r'(^\Origin\:\s|Label:\s|Suite:\s|Version:\s|Codename:\s|Date:\s|Architecture:\s|Components:\s|Description\:\s|MD5Sum:\s)'
RELEASE_WORD_MATCHER = r'(^\Origin\:\s|Label:\s|Suite:\s|Version:\s|Codename:\s|Date:\s|Architecture:\s|Components:\s|Description:\s|MD5Sum:\s|SHA256:\s|Aquire\-By\-Hash:\s)'
class Release:
def __init__(self, distro_codename):
@ -24,19 +24,52 @@ class Release:
for d in self.meta_release:
meta_release_obj = MetaRelease(d)
dist_and_release_file_url = { meta_release_obj.dist, meta_release_obj.release_file }
print(type(dist_and_release_file_url))
dist_and_release_file_url = { meta_release_obj.dist: meta_release_obj.release_file }
meta_release_objects.append(dist_and_release_file_url)
return meta_release_objects
def line_format(self, line):
""" Use this method for cleaning the line, especially the one with the md5
and shasums in them. """
try:
#cleaned_line = re.split(RELEASE_WORD_MATCHER, line)
cleaned_line = line
return cleaned_line
except Exception as e:
print('failed to clean')
print(e.message)
def validate_parse(self):
""" Use this method for validating the entire returned dictionary. make
sure it has the expected keys we want/expect. """
return
def md5_from_line(line):
return
def sha256_from_line(line):
return
def release_file_parse(self, release_file_url):
""" Returns the meta_release_file parsed as a list of dicts """
""" Returns the parsed_release_file parsed as a list of dicts """
with request.urlopen(f'{release_file_url}') as response:
index_counter = 0
lines = TextIOWrapper(response, encoding='utf-8')
cleaned_lines = []
for l in lines:
cleaned_line = self.line_format(l)
cleaned_lines.append(cleaned_line)
print(cleaned_line)
return cleaned_lines
#return parsed_release_file
"""
stripped_lines = [
re.split(RELEASE_WORD_MATCHER, l.strip()) for l in
re.split(RELEASE_WORD_MATCHER, l.strip()[::1]) for l in
lines ]
print(stripped_lines)
grouped_lines = [list(group) for key, group in
@ -57,6 +90,7 @@ class Release:
list_of_dicts.append(d) if arr_per_group == len(d.keys()) else None
return list_of_dicts
"""
if __name__ == '__main__':
# testing
@ -64,10 +98,13 @@ if __name__ == '__main__':
r = Release('focal')
release_file_urls = r.distro_release_file_urls()
for meta_release in release_file_urls:
print(meta_release)
#keys = meta_release.keys()
#for distro in keys:
# url = meta_release[distro]
# print(url)
for meta_release_dict in release_file_urls:
keys = meta_release_dict.keys()
for distro in keys:
url = meta_release_dict[distro]
try:
results = r.release_file_parse(url)
except Exception as e:
print(e.__doc__)
print(e.message)