1
# Copyright (C) 2009 Canonical
6
# Parts taken from gnome-app-install:utils.py (also written by Michael Vogt)
8
# This program is free software; you can redistribute it and/or modify it under
9
# the terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 3 of the License, or (at your option) any later
13
# This program is distributed in the hope that it will be useful, but WITHOUT
14
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
# You should have received a copy of the GNU General Public License along with
19
# this program; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33
from gettext import gettext as _
8
35
class GtkMainIterationProgress(apt.progress.OpProgress):
9
36
"""Progress that just runs the main loop"""
10
37
def update(self, percent):
11
38
while gtk.events_pending():
12
39
gtk.main_iteration()
41
# FIXME: this stuff should move into a seperate per-distro backend
42
def get_maintenance_end_date(release_date, m_months):
44
get the (year, month) tuple when the maintenance for the distribution
48
months = m_months % 12
49
support_end_year = release_date.year + years + (release_date.month + months)/12
50
support_end_month = (release_date.month + months) % 12
51
return (support_end_year, support_end_month)
53
def get_release_date_from_release_file(path):
55
return the release date as time_t for the given release file
57
if not path or not os.path.exists(path):
59
tag = apt_pkg.ParseTagFile(open(path))
61
if not tag.Section.has_key("Date"):
63
date = tag.Section["Date"]
64
return apt_pkg.StrToTime(date)
66
def get_release_filename_for_pkg(cache, pkgname, label, release):
67
" get the release file that provides this pkg "
68
if not cache.has_key(pkgname):
72
# look for the version that comes from the repos with
73
# the given label and origin
74
for aver in pkg._pkg.VersionList:
75
if aver == None or aver.FileList == None:
77
for verFile, index in aver.FileList:
79
if (verFile.Origin == label and
80
verFile.Label == label and
81
verFile.Archive == release):
85
indexfile = cache._list.FindIndex(ver.FileList[0][0])
86
for metaindex in cache._list.List:
87
for m in metaindex.IndexFiles:
89
indexfile.Describe == m.Describe and
91
dir = apt_pkg.Config.FindDir("Dir::State::lists")
92
name = apt_pkg.URItoFileName(metaindex.URI)+"dists_%s_Release" % metaindex.Dist
14
97
class AptCache(gobject.GObject):
16
99
A apt cache that opens in the background and keeps the UI alive
51
134
return self._ready
137
def get_distro_codename(self):
138
if not hasattr(self ,"codename"):
139
self.codename = subprocess.Popen(
140
["lsb_release","-c","-s"],
141
stdout=subprocess.PIPE).communicate()[0].strip()
144
def get_maintenance_status(self, appname, pkgname, component, channel):
146
# try to figure out the support dates of the release and make
147
# sure to look only for stuff in "Ubuntu" and "distro_codename"
148
# (to exclude stuff in ubuntu-updates for the support time
149
# calculation because the "Release" file time for that gets
151
releasef = get_release_filename_for_pkg(self._cache, pkgname,
153
self.get_distro_codename())
154
time_t = get_release_date_from_release_file(releasef)
155
# check the release date and show support information
158
release_date = datetime.datetime.fromtimestamp(time_t)
159
#print "release_date: ", release_date
160
now = datetime.datetime.now()
161
release_age = (now - release_date).days
162
#print "release age: ", release_age
164
# mvo: we do not define the end date very precisely
165
# currently this is why it will just display a end
167
(support_end_year, support_end_month) = get_maintenance_end_date(release_date, 18)
168
support_end_month_str = locale.nl_langinfo(getattr(locale,"MON_%d" % support_end_month))
169
# check if the support has ended
170
support_ended = (now.year >= support_end_year and
171
now.month > support_end_month)
172
if component == "main":
174
return _("Canonical does no longer provide "
175
"updates for %s in Ubuntu %s. "
176
"Updates may be available in a newer version of "
177
"Ubuntu.") % (appname, self.get_distro_release())
179
return _("Canonical provides critical updates for "
180
"%(appname)s until %(support_end_month_str)s "
181
"%(support_end_year)s.") % {'appname' : appname,
182
'support_end_month_str' : support_end_month_str,
183
'support_end_year' : support_end_year}
184
elif component == "restricted":
186
return _("Canonical does no longer provide "
187
"updates for %s in Ubuntu %s. "
188
"Updates may be available in a newer version of "
189
"Ubuntu.") % (appname, self.get_distro_release())
191
return _("Canonical provides critical updates supplied "
192
"by the developers of %(appname)s until "
193
"%(support_end_month_str)s "
194
"%(support_end_year)s.") % {'appname' : appname,
195
'support_end_month_str' : support_end_month_str,
196
'support_end_year' : support_end_year}
198
# if we couldn't fiure a support date, use a generic maintenance
199
# string without the date
201
return _("Canonical does not provide updates for %s. "
202
"Some updates may be provided by the third party "
204
elif component == "main":
205
return _("Canonical provides critical updates for %s.") % appname
206
elif component == "restricted":
207
return _("Canonical provides critical updates supplied by the "
208
"developers of %s.") % appname
209
elif component == "universe" or component == "multiverse":
210
return _("Canonical does not provide updates for %s. "
211
"Some updates may be provided by the "
212
"Ubuntu community.") % appname
213
return _("Application %s has a unkown maintenance status.") % appname
53
215
if __name__ == "__main__":
218
print c.get_maintenance_status("synaptic app", "synaptic", "main", None)
219
print c.get_maintenance_status("3dchess app", "3dchess", "universe", None)