~ubuntu-branches/ubuntu/lucid/software-store/lucid

« back to all changes in this revision

Viewing changes to softwarestore/apt/aptcache.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt, Andrew Higginson, Michael Vogt
  • Date: 2009-09-15 11:35:48 UTC
  • Revision ID: james.westby@ubuntu.com-20090915113548-rj13zzz8kgtk9zkk
Tags: 0.3.3
[ Andrew Higginson ]
* softwarestore/view/widgets/searchentry.py:
  - Included clearing of the main pane timeout
    when clicking the clear button in the search
    entry (LP: #423747)
  - Added correct behaviour when the search icon
    in the search entry is clicked
* softwarestore/data/ui/SoftwareStore.ui:
  - Made menu items have images (if they are enabled)
  - Added Undo, Redo, Cut, Copy, Paste, Delete Menu 
    items (LP: #426218)
  - Version bump and correct logo in about 
    dialog (LP: #428677)
* softwarestore/app.py:
  - Added functions for when the Edit menu items are 
    clicked (but not for Undo/Redo yet).
  - Added code to hide the Edit menu items when the 
    search entry is not focused
* data/icons/scalable/apps/software-store.svg:
  - removed obselete file
* data/icons/*/status/softwarestore-progress-*.png:
  - re-exported icons to be 24x24 and optimised
* software-store:
  - version bump
* data/templates/AppDetailsView.html:
  - made install/remove button disable itself 
    after click
* softwarestore/view/appdetailsview.py:
  - removed implemented FIXME

[ Michael Vogt ]
* softwarestore/view/appdetailsview.py:
  - ensure the gnome debconf frontend is used
  - make screenshot loading url configurable
  - cleanup
  - use internal viewer for large screenshot display 
    (thanks to Andrew Higginson)
  - made install/remove button enable again if the user
    cancels the action
  - use the new ShowImageDialog
  - detect if a package is not available for the given 
    architecture
  - add maintainance time to the status (LP: #427266)
* softwarestore/view/widgets/imagedialog.py:
  - new widget for the large screenshot display
* merged the help xml fixes from Matthew East (many thanks!)
  LP: #429897
* fix icon display in the progress view (LP: #428679)
* softwarestore/view/appview.py:
  - fix crash for applications with no summary
* softwarestore/view/widgets/searchentry.py:
  - add undo/redo (LP: #428291)
* softwarestore/app.py:
  - simply the copy/cut/paste
  - use undo/redo from searchentry 
  - fix crash for packages not available in cache (LP #428356)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Canonical
 
2
#
 
3
# Authors:
 
4
#  Michael Vogt
 
5
#
 
6
# Parts taken from gnome-app-install:utils.py (also written by Michael Vogt)
 
7
#
 
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
 
11
# version.
 
12
#
 
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
 
16
# details.
 
17
#
 
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
1
21
 
2
22
import apt
 
23
import apt_pkg
 
24
import datetime
 
25
import locale
3
26
import glib
4
27
import gobject
5
28
import gtk
 
29
import os
 
30
import subprocess
6
31
import time
7
32
 
 
33
from gettext import gettext as _
 
34
 
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()
13
40
 
 
41
# FIXME: this stuff should move into a seperate per-distro backend
 
42
def get_maintenance_end_date(release_date, m_months):
 
43
    """
 
44
    get the (year, month) tuple when the maintenance for the distribution
 
45
    ends
 
46
    """
 
47
    years = m_months / 12
 
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)
 
52
 
 
53
def get_release_date_from_release_file(path):
 
54
    """
 
55
    return the release date as time_t for the given release file
 
56
    """
 
57
    if not path or not os.path.exists(path):
 
58
        return None
 
59
    tag = apt_pkg.ParseTagFile(open(path))
 
60
    tag.Step()
 
61
    if not tag.Section.has_key("Date"):
 
62
        return None
 
63
    date = tag.Section["Date"]
 
64
    return apt_pkg.StrToTime(date)
 
65
 
 
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):
 
69
        return None
 
70
    pkg = cache[pkgname]
 
71
    ver = None
 
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:
 
76
            continue
 
77
        for verFile, index in aver.FileList:
 
78
            #print verFile
 
79
            if (verFile.Origin == label and
 
80
                verFile.Label == label and
 
81
                verFile.Archive == release):
 
82
                ver = aver
 
83
    if not ver:
 
84
        return None
 
85
    indexfile = cache._list.FindIndex(ver.FileList[0][0])
 
86
    for metaindex in cache._list.List:
 
87
        for m in metaindex.IndexFiles:
 
88
            if (indexfile and
 
89
                indexfile.Describe == m.Describe and
 
90
                indexfile.IsTrusted):
 
91
                dir = apt_pkg.Config.FindDir("Dir::State::lists")
 
92
                name = apt_pkg.URItoFileName(metaindex.URI)+"dists_%s_Release" % metaindex.Dist
 
93
                return dir+name
 
94
    return None
 
95
 
 
96
 
14
97
class AptCache(gobject.GObject):
15
98
    """ 
16
99
    A apt cache that opens in the background and keeps the UI alive
50
133
    def ready(self):
51
134
        return self._ready
52
135
 
 
136
    # FIXME: sucks here
 
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()
 
142
       return self.codename
 
143
 
 
144
    def get_maintenance_status(self, appname, pkgname, component, channel):
 
145
 
 
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
 
150
        # updated regularly)
 
151
        releasef = get_release_filename_for_pkg(self._cache, pkgname, 
 
152
                                                "Ubuntu", 
 
153
                                                self.get_distro_codename())
 
154
        time_t = get_release_date_from_release_file(releasef)
 
155
        # check the release date and show support information
 
156
        # based on this
 
157
        if time_t:
 
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
 
163
 
 
164
            # mvo: we do not define the end date very precisely
 
165
            #      currently this is why it will just display a end
 
166
            #      range
 
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":
 
173
                if support_ended:
 
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())
 
178
                else:
 
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":
 
185
                if support_ended:
 
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())
 
190
                else:
 
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}
 
197
               
 
198
        # if we couldn't fiure a support date, use a generic maintenance
 
199
        # string without the date
 
200
        if channel:
 
201
            return _("Canonical does not provide updates for %s. "
 
202
                     "Some updates may be provided by the third party "
 
203
                     "vendor.") % appname
 
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
 
214
 
53
215
if __name__ == "__main__":
54
216
    c = AptCache()
 
217
    c.open()
 
218
    print c.get_maintenance_status("synaptic app", "synaptic", "main", None)
 
219
    print c.get_maintenance_status("3dchess app", "3dchess", "universe", None)