~mvo/update-manager/not-automatic

« back to all changes in this revision

Viewing changes to UpdateManager/Core/MyCache.py

  • Committer: Michael Vogt
  • Date: 2009-02-16 10:30:51 UTC
  • mfrom: (1256.1.14 main)
  • Revision ID: michael.vogt@ubuntu.com-20090216103051-m2aa2cgx0s2facxh
merge from the mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from gettext import gettext as _
35
35
 
36
36
SYNAPTIC_PINFILE = "/var/lib/synaptic/preferences"
37
 
CHANGELOGS_URI="http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/changelog"
 
37
CHANGELOGS_URI="http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/%s"
38
38
 
39
39
 
40
40
class MyCache(DistUpgrade.DistUpgradeCache.MyCache):
46
46
        # init the regular cache
47
47
        self._initDepCache()
48
48
        self.all_changes = {}
 
49
        self.all_news = {}
49
50
        # on broken packages, try to fix via saveDistUpgrade()
50
51
        if self._depcache.BrokenCount > 0:
51
52
            self.saveDistUpgrade()
107
108
                        if match.importance > update_origin.importance:
108
109
                            update_origin = match
109
110
        return update_origin
 
111
 
 
112
    def _strip_epoch(self, verstr):
 
113
        " strip of the epoch "
 
114
        l = string.split(verstr,":")
 
115
        if len(l) > 1:
 
116
            verstr = "".join(l[1:])
 
117
        return verstr
110
118
        
111
 
    def get_changelog(self, name, lock):
 
119
    def _get_changelog_or_news(self, name, fname, strict_versioning=False):
 
120
        " helper that fetches the file in question "
112
121
        # don't touch the gui in this function, it needs to be thread-safe
113
122
        pkg = self[name]
114
123
 
122
131
 
123
132
        # get the source version, start with the binaries version
124
133
        binver = pkg.candidateVersion
125
 
        srcver = pkg.candidateVersion
 
134
        srcver_epoch = pkg.candidateVersion
 
135
        srcver = self._strip_epoch(srcver_epoch)
126
136
        #print "bin: %s" % binver
127
137
 
128
138
        l = section.split("/")
134
144
        if srcpkg.startswith("lib"):
135
145
            prefix = "lib" + srcpkg[3]
136
146
 
137
 
        # stip epoch, but save epoch for later when displaying the
138
 
        # launchpad changelog
139
 
        srcver_epoch = srcver
140
 
        l = string.split(srcver,":")
141
 
        if len(l) > 1:
142
 
            srcver = "".join(l[1:])
143
 
 
144
 
        try:
145
 
            uri = CHANGELOGS_URI % (src_section,prefix,srcpkg,srcpkg, srcver)
146
 
            # print "Trying: %s " % uri
147
 
            changelog = urllib2.urlopen(uri)
148
 
            #print changelog.read()
149
 
            # do only get the lines that are new
150
 
            alllines = ""
151
 
            regexp = "^%s \((.*)\)(.*)$" % (re.escape(srcpkg))
152
 
 
153
 
            i=0
154
 
            while True:
155
 
                line = changelog.readline()
156
 
                if line == "":
157
 
                    break
158
 
                match = re.match(regexp,line)
159
 
                if match:
160
 
                    # strip epoch from installed version
161
 
                    # and from changelog too
162
 
                    installed = pkg.installedVersion
163
 
                    if installed and ":" in installed:
164
 
                        installed = installed.split(":",1)[1]
165
 
                    changelogver = match.group(1)
166
 
                    if changelogver and ":" in changelogver:
167
 
                        changelogver = changelogver.split(":",1)[1]
168
 
                    # we test for "==" here to ensure that the version
169
 
                    # is actually really in the changelog - if not
170
 
                    # just display it all, this catches cases like:
171
 
                    # gcc-defaults with "binver=4.3.1" and srcver=1.76
 
147
        uri = CHANGELOGS_URI % (src_section,prefix,srcpkg,srcpkg, srcver, fname)
 
148
        # print "Trying: %s " % uri
 
149
        changelog = urllib2.urlopen(uri)
 
150
        #print changelog.read()
 
151
        # do only get the lines that are new
 
152
        alllines = ""
 
153
        regexp = "^%s \((.*)\)(.*)$" % (re.escape(srcpkg))
 
154
        
 
155
        i=0
 
156
        while True:
 
157
            line = changelog.readline()
 
158
            if line == "":
 
159
                break
 
160
            match = re.match(regexp,line)
 
161
            if match:
 
162
                # strip epoch from installed version
 
163
                # and from changelog too
 
164
                installed = pkg.installedVersion
 
165
                if installed and ":" in installed:
 
166
                    installed = installed.split(":",1)[1]
 
167
                changelogver = match.group(1)
 
168
                if changelogver and ":" in changelogver:
 
169
                    changelogver = changelogver.split(":",1)[1]
 
170
                # we test for "==" here for changelogs 
 
171
                # to ensure that the version
 
172
                # is actually really in the changelog - if not
 
173
                # just display it all, this catches cases like:
 
174
                # gcc-defaults with "binver=4.3.1" and srcver=1.76
 
175
                # 
 
176
                # for NEWS.Debian we do require the changelogver > installed
 
177
                if strict_versioning:
 
178
                    if (installed and 
 
179
                        apt_pkg.VersionCompare(changelogver,installed)<0):
 
180
                        break
 
181
                else:
172
182
                    if (installed and 
173
183
                        apt_pkg.VersionCompare(changelogver,installed)==0):
174
184
                        break
175
 
                alllines = alllines + line
176
 
 
177
 
            # Print an error if we failed to extract a changelog
178
 
            if len(alllines) == 0:
179
 
                alllines = _("The changelog does not contain any relevant changes.\n\n"
180
 
                             "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
181
 
                             "until the changes become available or try again "
182
 
                             "later.") % (srcpkg, srcver_epoch)
183
 
            # only write if we where not canceld
184
 
            if lock.locked():
185
 
                self.all_changes[name] = [alllines, srcpkg]
 
185
            alllines = alllines + line
 
186
        return alllines
 
187
        
 
188
    def get_news_and_changelog(self, name, lock):
 
189
        self.get_news(name)
 
190
        self.get_changelog(name)
 
191
        lock.release()        
 
192
    
 
193
    def get_news(self, name):
 
194
        " get the NEWS.Debian file from the changelogs location "
 
195
        try:
 
196
            news = self._get_changelog_or_news(name, "NEWS.Debian", True)
 
197
        except Exception, e:
 
198
            return
 
199
        if news:
 
200
            self.all_news[name] = news
 
201
                    
 
202
    def get_changelog(self, name):
 
203
        " get the changelog file from the changelog location "
 
204
        srcpkg = self[name].sourcePackageName
 
205
        srcver_epoch = self[name].candidateVersion
 
206
        try:
 
207
            changelog = self._get_changelog_or_news(name, "changelog")
 
208
            if len(changelog) == 0:
 
209
                changelog = _("The changelog does not contain any relevant changes.\n\n"
 
210
                              "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
 
211
                              "until the changes become available or try again "
 
212
                              "later.") % (srcpkg, srcver_epoch)
186
213
        except urllib2.HTTPError, e:
187
 
            if lock.locked():
188
 
                self.all_changes[name] = [
189
 
                    _("The list of changes is not available yet.\n\n"
190
 
                      "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
191
 
                      "until the changes become available or try again "
192
 
                      "later.") % (srcpkg, srcver_epoch),
193
 
                    srcpkg]
 
214
            changelog = _("The list of changes is not available yet.\n\n"
 
215
                          "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
 
216
                          "until the changes become available or try again "
 
217
                          "later.") % (srcpkg, srcver_epoch)
194
218
        except (IOError, httplib.BadStatusLine, socket.error), e:
195
219
            print "caught exception: ", e
196
220
            if lock.locked():
197
 
                self.all_changes[name] = [_("Failed to download the list "
198
 
                                            "of changes. \nPlease "
199
 
                                            "check your Internet "
200
 
                                            "connection."), srcpkg]
201
 
        if lock.locked():
202
 
            lock.release()
 
221
                self.all_changes[name] = _("Failed to download the list "
 
222
                                           "of changes. \nPlease "
 
223
                                           "check your Internet "
 
224
                                           "connection.")
 
225
        self.all_changes[name] = changelog
 
226
 
 
227
 
203
228