From 2560aa210b1c3628dc76029cccfe7a64b8083f04 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 11 Jun 2011 05:06:51 -0700 Subject: [PATCH] ubuntutools.distro_info: Add a function to find the distribution that used a given release codename. --- debian/changelog | 4 +++- ubuntutools/distro_info.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index db65216..9d57fea 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,8 +26,10 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low * ubuntutools.misc: Add a new "system_distribution_chain", which returns a list starting with the current distribution and working its way up each distribution's parent. + * ubuntutools.distro_info: Add a function to find the distribution that + used a given release codename. - -- Evan Broder Sat, 11 Jun 2011 05:05:21 -0700 + -- Evan Broder Sat, 11 Jun 2011 05:06:44 -0700 ubuntu-dev-tools (0.124) unstable; urgency=low diff --git a/ubuntutools/distro_info.py b/ubuntutools/distro_info.py index d170f8c..c8025d5 100644 --- a/ubuntutools/distro_info.py +++ b/ubuntutools/distro_info.py @@ -18,6 +18,8 @@ import csv import datetime import os +from ubuntutools.misc import system_distribution_chain + def convert_date(string): """Convert a date string in ISO 8601 into a datetime object.""" if not string: @@ -195,3 +197,29 @@ class UbuntuDistroInfo(DistroInfo): if date <= x["eol"] or (x["eol-server"] is not None and date <= x["eol-server"])] return distros + +_vendor_to_distroinfo = {"Debian": DebianDistroInfo, + "Ubuntu": UbuntuDistroInfo} +def vendor_to_distroinfo(vendor): + """ vendor_to_distroinfo(string) -> DistroInfo class + + Convert a string name of a distribution into a DistroInfo subclass + representing that distribution, or None if the distribution is + unknown. + """ + return _vendor_to_distroinfo.get(vendor) + +def codename_to_distribution(codename): + """ codename_to_distribution(string) -> string + + Finds a given release codename in your distribution's genaology + (i.e. looking at the current distribution and its parents), or + print an error message and return None if it can't be found + """ + for distro in system_distribution_chain(): + info = vendor_to_distroinfo(distro) + if not info: + continue + + if codename in info().all: + return distro