~mvo/update-manager/not-automatic

« back to all changes in this revision

Viewing changes to UpdateManager/Common/MyCache.py

  • Committer: Michael Vogt
  • Date: 2009-01-20 11:01:45 UTC
  • Revision ID: michael.vogt@ubuntu.com-20090120110145-wxawnyuvw3i91d0f
AutoUpgradeTester/UpgradeTestBackendQemu.py: move VncNum, SshPort, BaseImage, SwapImage, CacheBaseImage options from the NonInteraction section to the new KVM section

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/%s"
 
37
CHANGELOGS_URI="http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/changelog"
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 = {}
50
49
        # on broken packages, try to fix via saveDistUpgrade()
51
50
        if self._depcache.BrokenCount > 0:
52
51
            self.saveDistUpgrade()
82
81
        assert self._depcache.BrokenCount == 0 and self._depcache.DelCount == 0
83
82
        self._depcache.Upgrade()
84
83
        return wouldDelete
85
 
    def _has_ver_with_not_automatic_origin(self, pkg):
86
 
        """
87
 
        internal helper that checks if one pkg version has the
88
 
        NotAutomatic flag
89
 
        """
90
 
        for ver in pkg._pkg.VersionList:
91
 
            for (verFileIter, index) in ver.FileList:
92
 
                if verFileIter.NotAutomatic:
93
 
                    return True
94
 
        return False
95
 
    def notAutomaticUpgradable(self, pkg):
96
 
        """
97
 
        check if 'pkg' is upgradable but has the 'NotAutomatic' flag
98
 
        """
99
 
        if ( pkg.isInstalled and
100
 
             not pkg.isUpgradable and
101
 
             pkg.candidateOrigin and
102
 
             self._has_ver_with_not_automatic_origin(pkg)
103
 
            ):
104
 
            # now check if there is a higher NotAutomatic version
105
 
            candVer = pkg._depcache.GetCandidateVer(pkg._pkg)
106
 
            for ver in pkg._pkg.VersionList:
107
 
                if apt_pkg.VersionCompare(ver.VerStr, candVer.VerStr) > 0:
108
 
                    return True
109
 
        return False
110
 
    def markUpgradeInstall(self, pkg):
111
 
        """
112
 
        mark package for upgrade/install. we have a special version
113
 
        here because update-manager deals with NotAutomatic by
114
 
        explictely selecting it if there is no candidate already
115
 
        """
116
 
        # handle NotAutomatic: yes packages special
117
 
        if self.notAutomaticUpgradable(pkg):
118
 
            for ver in pkg._pkg.VersionList:
119
 
                print "looking at: ", ver
120
 
                for (verFileIter, index) in ver.FileList:
121
 
                    if verFileIter.NotAutomatic:
122
 
                        print "setting candidate ver: ", ver
123
 
                        pkg._depcache.SetCandidateVer(pkg._pkg, ver)
124
 
                        print "new cand: ", pkg._depcache.GetCandidateVer(pkg._pkg)
125
 
                        pkg._depcache.MarkInstall(pkg._pkg)
126
 
                        print "new cand: ", pkg._depcache.GetCandidateVer(pkg._pkg)
127
 
                        break
128
 
        pkg.markInstall()
129
 
        print pkg.markedInstall
130
 
        print pkg.markedUpgrade
131
 
        
132
84
    def matchPackageOrigin(self, pkg, matcher):
133
85
        """ match 'pkg' origin against 'matcher', take versions between
134
86
            installedVersion and candidateVersion into account too
155
107
                        if match.importance > update_origin.importance:
156
108
                            update_origin = match
157
109
        return update_origin
158
 
 
159
 
    def _strip_epoch(self, verstr):
160
 
        " strip of the epoch "
161
 
        l = string.split(verstr,":")
162
 
        if len(l) > 1:
163
 
            verstr = "".join(l[1:])
164
 
        return verstr
165
110
        
166
 
    def _get_changelog_or_news(self, name, fname, strict_versioning=False):
167
 
        " helper that fetches the file in question "
 
111
    def get_changelog(self, name, lock):
168
112
        # don't touch the gui in this function, it needs to be thread-safe
169
113
        pkg = self[name]
170
114
 
178
122
 
179
123
        # get the source version, start with the binaries version
180
124
        binver = pkg.candidateVersion
181
 
        srcver_epoch = pkg.candidateVersion
182
 
        srcver = self._strip_epoch(srcver_epoch)
 
125
        srcver = pkg.candidateVersion
183
126
        #print "bin: %s" % binver
184
127
 
185
128
        l = section.split("/")
191
134
        if srcpkg.startswith("lib"):
192
135
            prefix = "lib" + srcpkg[3]
193
136
 
194
 
        uri = CHANGELOGS_URI % (src_section,prefix,srcpkg,srcpkg, srcver, fname)
195
 
        # print "Trying: %s " % uri
196
 
        changelog = urllib2.urlopen(uri)
197
 
        #print changelog.read()
198
 
        # do only get the lines that are new
199
 
        alllines = ""
200
 
        regexp = "^%s \((.*)\)(.*)$" % (re.escape(srcpkg))
201
 
        
202
 
        i=0
203
 
        while True:
204
 
            line = changelog.readline()
205
 
            if line == "":
206
 
                break
207
 
            match = re.match(regexp,line)
208
 
            if match:
209
 
                # strip epoch from installed version
210
 
                # and from changelog too
211
 
                installed = pkg.installedVersion
212
 
                if installed and ":" in installed:
213
 
                    installed = installed.split(":",1)[1]
214
 
                changelogver = match.group(1)
215
 
                if changelogver and ":" in changelogver:
216
 
                    changelogver = changelogver.split(":",1)[1]
217
 
                # we test for "==" here for changelogs 
218
 
                # to ensure that the version
219
 
                # is actually really in the changelog - if not
220
 
                # just display it all, this catches cases like:
221
 
                # gcc-defaults with "binver=4.3.1" and srcver=1.76
222
 
                # 
223
 
                # for NEWS.Debian we do require the changelogver > installed
224
 
                if strict_versioning:
225
 
                    if (installed and 
226
 
                        apt_pkg.VersionCompare(changelogver,installed)<0):
227
 
                        break
228
 
                else:
 
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
229
172
                    if (installed and 
230
173
                        apt_pkg.VersionCompare(changelogver,installed)==0):
231
174
                        break
232
 
            alllines = alllines + line
233
 
        return alllines
234
 
        
235
 
    def get_news_and_changelog(self, name, lock):
236
 
        self.get_news(name)
237
 
        self.get_changelog(name)
238
 
        lock.release()        
239
 
    
240
 
    def get_news(self, name):
241
 
        " get the NEWS.Debian file from the changelogs location "
242
 
        try:
243
 
            news = self._get_changelog_or_news(name, "NEWS.Debian", True)
244
 
        except Exception, e:
245
 
            return
246
 
        if news:
247
 
            self.all_news[name] = news
248
 
                    
249
 
    def get_changelog(self, name):
250
 
        " get the changelog file from the changelog location "
251
 
        srcpkg = self[name].sourcePackageName
252
 
        srcver_epoch = self[name].candidateVersion
253
 
        try:
254
 
            changelog = self._get_changelog_or_news(name, "changelog")
255
 
            if len(changelog) == 0:
256
 
                changelog = _("The changelog does not contain any relevant changes.\n\n"
257
 
                              "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
258
 
                              "until the changes become available or try again "
259
 
                              "later.") % (srcpkg, srcver_epoch)
 
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]
260
186
        except urllib2.HTTPError, e:
261
 
            changelog = _("The list of changes is not available yet.\n\n"
262
 
                          "Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog\n"
263
 
                          "until the changes become available or try again "
264
 
                          "later.") % (srcpkg, srcver_epoch)
 
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]
265
194
        except (IOError, httplib.BadStatusLine, socket.error), e:
266
195
            print "caught exception: ", e
267
196
            if lock.locked():
268
 
                self.all_changes[name] = _("Failed to download the list "
269
 
                                           "of changes. \nPlease "
270
 
                                           "check your Internet "
271
 
                                           "connection.")
272
 
        self.all_changes[name] = changelog
273
 
 
274
 
 
 
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()
275
203