From 3f2091a7684d02688c0ad8e9d4daa1a44ba6fe2b Mon Sep 17 00:00:00 2001 From: bpmcdevitt Date: Fri, 19 Aug 2022 02:01:17 -0500 Subject: [PATCH] more adjustments --- .../source_ubuntu_packages.py | 50 +++++-------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/tools/ubuntu_package_puller/source_ubuntu_packages.py b/tools/ubuntu_package_puller/source_ubuntu_packages.py index f94f31b..583985b 100644 --- a/tools/ubuntu_package_puller/source_ubuntu_packages.py +++ b/tools/ubuntu_package_puller/source_ubuntu_packages.py @@ -4,6 +4,7 @@ from itertools import groupby import re META_RELEASE_WORD_MATCHER = '^w\:' +META_SPACE_MATCHER = r'^\s' class SourceUbuntuPackages: @@ -12,28 +13,11 @@ class SourceUbuntuPackages: self.meta_release_url = 'http://changelogs.ubuntu.com/meta-release' # http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/update-manager/wily/view/head:/UpdateManager/Core/MetaRelease.py#L100-#L105 + # TODO: there is still a bug its ommitting the last keys/value pairs that we need that + # contain urls. because of the re.split with regex i think. def meta_release_parse(self): """ - Returns the meta_release_file parsed as a dict - Example text data: - Dist: breezy - Name: Breezy Badger - Version: 05.10 - Date: Thu, 13 Oct 2005 19:34:42 UTC - Supported: 0 - Description: This is the Breezy Badger release - Release-File: http://old-releases.ubuntu.com/ubuntu/dists/breezy/Release - - Dist: dapper - Name: Dapper Drake - Version: 6.06 LTS - Date: Thu, 01 Jun 2006 9:00:00 UTC - Supported: 0 - Description: This is the Dapper Drake release - Release-File: http://old-releases.ubuntu.com/ubuntu/dists/dapper/Release - ReleaseNotes: http://changelogs.ubuntu.com/EOLReleaseAnnouncement - UpgradeTool: http://old-releases.ubuntu.com/ubuntu/dists/dapper/main/dist-upgrader-all/current/dapper.tar.gz - UpgradeToolSignature: http://old-releases.ubuntu.com/ubuntu/dists/dapper/main/dist-upgrader-all/current/dapper.tar.gz.gpg + Returns the meta_release_file parsed as a list of dicts """ with request.urlopen(self.meta_release_url) as response: index_counter = 0 @@ -42,13 +26,15 @@ class SourceUbuntuPackages: re.split(META_RELEASE_WORD_MATCHER, l.strip()) for l in lines ] grouped_lines = [list(group) for key, group in groupby(stripped_lines, lambda x: x == ['']) if not key] - group_of_dicts = [] + list_of_dicts = [] for group in grouped_lines: d = {} # list of each group for arr in group: l_str = arr[0] + # regex still needs work i think. use the same constant + # matcher after fixing it. parts = re.split(r"(^\w+\:)", l_str.strip()) split_parts = parts[1::] @@ -58,24 +44,12 @@ class SourceUbuntuPackages: else: k = split_parts[0] v = split_parts[1] - # remove some leading whitespace. - cleaned_v = re.sub(r"^\s", '', v) - d["{}".format(k)] = cleaned_v - group_of_dicts.append(d) + cleaned_k = k.lower() + cleaned_v = re.sub(META_SPACE_MATCHER, '', v) + d["{}".format(cleaned_k)] = cleaned_v + list_of_dicts.append(d) - return group_of_dicts - - - - #split_lines = [ l.split(":") for l in stripped_lines ] - #for l in split_lines: - # if 'Dist' in l or 'Version' in l: - # dist_and_versions.append(l[1].replace(' ', '')) - - #distro_and_versions = [ tuple(dist_and_versions[x:x+2]) for x in range(0, - # len(dist_and_versions), 2) ] - - #return dict(distro_and_versions) + return list_of_dicts if __name__ == '__main__': s = SourceUbuntuPackages('dapper')