From 0c54282a13c12309a0cdfe52669ddd81c7d9dbf2 Mon Sep 17 00:00:00 2001 From: bpmcdevitt Date: Fri, 19 Aug 2022 01:44:56 -0500 Subject: [PATCH] added method to parse metadata file from changelog release --- .../source_ubuntu_packages.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tools/ubuntu_package_puller/source_ubuntu_packages.py diff --git a/tools/ubuntu_package_puller/source_ubuntu_packages.py b/tools/ubuntu_package_puller/source_ubuntu_packages.py new file mode 100644 index 0000000..f94f31b --- /dev/null +++ b/tools/ubuntu_package_puller/source_ubuntu_packages.py @@ -0,0 +1,83 @@ +from urllib import request +from io import TextIOWrapper +from itertools import groupby +import re + +META_RELEASE_WORD_MATCHER = '^w\:' + +class SourceUbuntuPackages: + + def __init__(self, distro_series): + self.distro_series = distro_series + 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 + 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 + """ + with request.urlopen(self.meta_release_url) as response: + index_counter = 0 + lines = TextIOWrapper(response, encoding='utf-8') + stripped_lines = [ + 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 = [] + + for group in grouped_lines: + d = {} + # list of each group + for arr in group: + l_str = arr[0] + parts = re.split(r"(^\w+\:)", l_str.strip()) + split_parts = parts[1::] + + # this signifies the end of the current group + if split_parts == []: + break + 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) + + 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) + +if __name__ == '__main__': + s = SourceUbuntuPackages('dapper') + print((s.meta_release_parse())) +