more adjustments
This commit is contained in:
parent
0c54282a13
commit
3f2091a768
1 changed files with 12 additions and 38 deletions
|
@ -4,6 +4,7 @@ from itertools import groupby
|
||||||
import re
|
import re
|
||||||
|
|
||||||
META_RELEASE_WORD_MATCHER = '^w\:'
|
META_RELEASE_WORD_MATCHER = '^w\:'
|
||||||
|
META_SPACE_MATCHER = r'^\s'
|
||||||
|
|
||||||
class SourceUbuntuPackages:
|
class SourceUbuntuPackages:
|
||||||
|
|
||||||
|
@ -12,28 +13,11 @@ class SourceUbuntuPackages:
|
||||||
self.meta_release_url = 'http://changelogs.ubuntu.com/meta-release'
|
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
|
# 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):
|
def meta_release_parse(self):
|
||||||
"""
|
"""
|
||||||
Returns the meta_release_file parsed as a dict
|
Returns the meta_release_file parsed as a list of dicts
|
||||||
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:
|
with request.urlopen(self.meta_release_url) as response:
|
||||||
index_counter = 0
|
index_counter = 0
|
||||||
|
@ -42,13 +26,15 @@ class SourceUbuntuPackages:
|
||||||
re.split(META_RELEASE_WORD_MATCHER, l.strip()) for l in lines ]
|
re.split(META_RELEASE_WORD_MATCHER, l.strip()) for l in lines ]
|
||||||
grouped_lines = [list(group) for key, group in
|
grouped_lines = [list(group) for key, group in
|
||||||
groupby(stripped_lines, lambda x: x == ['']) if not key]
|
groupby(stripped_lines, lambda x: x == ['']) if not key]
|
||||||
group_of_dicts = []
|
list_of_dicts = []
|
||||||
|
|
||||||
for group in grouped_lines:
|
for group in grouped_lines:
|
||||||
d = {}
|
d = {}
|
||||||
# list of each group
|
# list of each group
|
||||||
for arr in group:
|
for arr in group:
|
||||||
l_str = arr[0]
|
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())
|
parts = re.split(r"(^\w+\:)", l_str.strip())
|
||||||
split_parts = parts[1::]
|
split_parts = parts[1::]
|
||||||
|
|
||||||
|
@ -58,24 +44,12 @@ class SourceUbuntuPackages:
|
||||||
else:
|
else:
|
||||||
k = split_parts[0]
|
k = split_parts[0]
|
||||||
v = split_parts[1]
|
v = split_parts[1]
|
||||||
# remove some leading whitespace.
|
cleaned_k = k.lower()
|
||||||
cleaned_v = re.sub(r"^\s", '', v)
|
cleaned_v = re.sub(META_SPACE_MATCHER, '', v)
|
||||||
d["{}".format(k)] = cleaned_v
|
d["{}".format(cleaned_k)] = cleaned_v
|
||||||
group_of_dicts.append(d)
|
list_of_dicts.append(d)
|
||||||
|
|
||||||
return group_of_dicts
|
return list_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__':
|
if __name__ == '__main__':
|
||||||
s = SourceUbuntuPackages('dapper')
|
s = SourceUbuntuPackages('dapper')
|
||||||
|
|
Loading…
Add table
Reference in a new issue