From 5c125f3c54b4bbf5fb60c48aefd0fc4b9f736664 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 20 Jan 2010 17:34:17 +0100 Subject: * apt/utils.py: - add some misc utils like get_release_filename_for_pkg() --- apt/utils.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 2 ++ 2 files changed, 77 insertions(+) create mode 100644 apt/utils.py diff --git a/apt/utils.py b/apt/utils.py new file mode 100644 index 00000000..c4c4cb73 --- /dev/null +++ b/apt/utils.py @@ -0,0 +1,75 @@ +# Copyright (C) 2009 Canonical +# +# Authors: +# Michael Vogt +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; version 3. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import apt_pkg +import os.path + +def get_maintenance_end_date(release_date, m_months): + """ + get the (year, month) tuple when the maintenance for the distribution + ends. Needs the data of the release and the number of months that + its is supported as input + """ + years = m_months / 12 + months = m_months % 12 + support_end_year = release_date.year + years + (release_date.month + months)/12 + support_end_month = (release_date.month + months) % 12 + return (support_end_year, support_end_month) + +def get_release_date_from_release_file(path): + """ + return the release date as time_t for the given release file + """ + if not path or not os.path.exists(path): + return None + tag = apt_pkg.ParseTagFile(open(path)) + tag.Step() + if not tag.Section.has_key("Date"): + return None + date = tag.Section["Date"] + return apt_pkg.StrToTime(date) + +def get_release_filename_for_pkg(cache, pkgname, label, release): + " get the release file that provides this pkg " + if not cache.has_key(pkgname): + return None + pkg = cache[pkgname] + ver = None + # look for the version that comes from the repos with + # the given label and origin + for aver in pkg._pkg.VersionList: + if aver == None or aver.FileList == None: + continue + for verFile, index in aver.FileList: + #print verFile + if (verFile.Origin == label and + verFile.Label == label and + verFile.Archive == release): + ver = aver + if not ver: + return None + indexfile = cache._list.FindIndex(ver.FileList[0][0]) + for metaindex in cache._list.List: + for m in metaindex.IndexFiles: + if (indexfile and + indexfile.Describe == m.Describe and + indexfile.IsTrusted): + dir = apt_pkg.Config.FindDir("Dir::State::lists") + name = apt_pkg.URItoFileName(metaindex.URI)+"dists_%s_Release" % metaindex.Dist + return dir+name + return None diff --git a/debian/changelog b/debian/changelog index fa87d5a4..12359f49 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,8 @@ python-apt (0.7.13.5) UNRELEASED; urgency=low - add DepDpkgBreaks, DepEnhances constants * doc/source/apt_pkg/{cache.rst, index.rst}: - update documentation as well + * apt/utils.py: + - add some misc utils like get_release_filename_for_pkg() -- Michael Vogt Wed, 02 Dec 2009 16:50:55 +0100 -- cgit v1.2.3 From c62bdd0b1b633b134ba551847da0c1e8d12115c2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 20 Jan 2010 17:43:07 +0100 Subject: apt/utils.py: fix copyright info --- apt/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apt/utils.py b/apt/utils.py index c4c4cb73..df1d0397 100644 --- a/apt/utils.py +++ b/apt/utils.py @@ -3,9 +3,10 @@ # Authors: # Michael Vogt # -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation; version 3. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -- cgit v1.2.3