Created
October 1, 2013 19:54
-
-
Save smoser/6784120 to your computer and use it in GitHub Desktop.
extract data from distro_info to a dict.
Quite possibly this should just read from /usr/share/distro-info/ubuntu.csv instead of using distro_info library. However, this seems functional for what I needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import distro_info | |
def get_ubuntu_info(date=None): | |
# this returns a sorted list of dicts | |
# each dict has information about an ubuntu release. | |
# Notably absent is any date information (release or eol) | |
# its harder than you'd like to get at data via the distro_info library | |
# | |
# The resultant dicts looks like this: | |
# {'codename': 'saucy', 'devel': True, | |
# 'full_codename': 'Saucy Salamander', | |
# 'fullname': 'Ubuntu 13.10 "Saucy Salamander"', | |
# 'lts': False, 'supported': True, 'version': '13.10'} | |
udi = distro_info.UbuntuDistroInfo() | |
# 'all' is a attribute, not a function. so we can't ask for it formated. | |
# s2all and us2all are lists, the value of each is the index | |
# where that release should fall in 'all'. | |
allcn = udi.all | |
s2all = [allcn.index(c) for c in | |
udi.supported(result="codename", date=date)] | |
us2all = [allcn.index(c) for c in | |
udi.unsupported(result="codename", date=date)] | |
def getall(result, date): | |
ret = [None for f in range(0, len(allcn))] | |
for i, r in enumerate(udi.supported(result=result, date=date)): | |
ret[s2all[i]] = r | |
for i, r in enumerate(udi.unsupported(result=result, date=date)): | |
ret[us2all[i]] = r | |
return [r for r in ret if r is not None] | |
codenames = getall(result="codename", date=date) | |
fullnames = getall(result="fullname", date=date) | |
lts = [bool('LTS' in f) for f in fullnames] | |
versions = [x.replace(" LTS", "") for x in | |
getall(result="release", date=date)] | |
full_codenames = [x.split('"')[1] for x in fullnames] | |
supported = udi.supported(date=date) | |
devel = udi.devel(date=date) | |
ret = [] | |
for i, codename in enumerate(codenames): print(i, codename) | |
for i, codename in enumerate(codenames): | |
ret.append({'lts': lts[i], 'version': versions[i], | |
'supported': codename in supported, | |
'fullname': fullnames[i], 'codename': codename, | |
'full_codename': full_codenames[i], | |
'devel': bool(codename == devel)}) | |
return ret | |
import pprint, sys | |
date = None | |
if len(sys.argv) > 1: | |
date = distro_info.convert_date(sys.argv[1]) | |
pprint.pprint(get_ubuntu_info(date=date)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment