diff options
Diffstat (limited to 'DistUpgrade/DistUpgradeControler.py')
| -rw-r--r-- | DistUpgrade/DistUpgradeControler.py | 110 |
1 files changed, 88 insertions, 22 deletions
diff --git a/DistUpgrade/DistUpgradeControler.py b/DistUpgrade/DistUpgradeControler.py index 9a03f288..c89f6a34 100644 --- a/DistUpgrade/DistUpgradeControler.py +++ b/DistUpgrade/DistUpgradeControler.py @@ -57,10 +57,9 @@ class DistUpgradeControler(object): self.cache = MyCache(self._view.getOpCacheProgress()) - def updateSourcesList(self): + def rewriteSourcesList(self, mirror_check=True): + logging.debug("rewriteSourcesList()") - logging.debug("updateSourcesList()") - # this must map, i.e. second in "from" must be the second in "to" # (but they can be different, so in theory we could exchange # component names here) @@ -76,49 +75,92 @@ class DistUpgradeControler(object): ] # list of valid mirrors that we can add - valid_mirrors = self.config.getlist("Sources","ValidMirrors") + valid_mirrors = self.config.getListFromFile("Sources","ValidMirrors") + + self.sources_disabled = False # look over the stuff we have foundToDist = False for entry in self.sources: - # ignore invalid records (but update disabled ones) - if entry.invalid: + # ignore invalid records (but update disabled ones) + # or cdrom entries + if entry.invalid or entry.uri.startswith("cdrom:"): continue logging.debug("examining: '%s'" % entry) # check if it's a mirror (or offical site) validMirror = False for mirror in valid_mirrors: - if is_mirror(mirror,entry.uri): + if not mirror_check or is_mirror(mirror,entry.uri): validMirror = True + # security is a special case + res = not entry.uri.startswith("http://security.ubuntu.com") and not entry.disabled if entry.dist in toDists: # so the self.sources.list is already set to the new # distro logging.debug("entry '%s' is already set to new dist" % entry) - foundToDist = True + foundToDist |= res elif entry.dist in fromDists: - foundToDist = True + foundToDist |= res entry.dist = toDists[fromDists.index(entry.dist)] logging.debug("entry '%s' updated to new dist" % entry) else: # disable all entries that are official but don't - # point to the "from" dist + # point to either "to" or "from" dist entry.disabled = True + self.sources_disabled = True logging.debug("entry '%s' was disabled (unknown dist)" % entry) # it can only be one valid mirror, so we can break here break # disable anything that is not from a official mirror if not validMirror: entry.disabled = True + self.sources_disabled = True logging.debug("entry '%s' was disabled (unknown mirror)" % entry) + return foundToDist - if not foundToDist: - # FIXME: offer to write a new self.sources.list entry - # DONT'T ERROR, write a line with mirror here - logging.error("No valid entry found") - return self._view.error(_("No valid entry found"), - _("While scaning your repository " - "information no valid entry for " - "the upgrade was found.\n")) + def updateSourcesList(self): + logging.debug("updateSourcesList()") + self.sources = SourcesList() + if not self.rewriteSourcesList(mirror_check=True): + logging.error("No valid mirror found") + res = self._view.askYesNoQuestion(_("No valid mirror found"), + _("While scaning your repository " + "information no mirror entry for " + "the upgrade was found." + "This cam happen if you run a internal " + "mirror or if the mirror information is " + "out of date.\n\n" + "Do you want to rewrite your " + "'sources.list' file anyway? If you choose " + "'Yes' here it will update all '%s' to '%s' " + "entries.\n" + "If you select 'no' the update will cancel." + ) % (self.fromDist, self.toDist)) + if res: + # re-init the sources and try again + self.sources = SourcesList() + if not self.rewriteSourcesList(mirror_check=False): + #hm, still nothing useful ... + prim = _("Generate default sources?") + secon = _("After scanning your 'sources.list' no " + "valid entry for '%s' was found.\n\n" + "Should default entries for '%s' be " + "added? If you select 'No' the update " + "will cancel.") % (self.fromDist, self.toDist) + if not self._view.askYesNoQuestion(prim, secon): + self.abort() + + # add some defaults here + # FIXME: find mirror here + uri = "http://archive.ubuntu.com/ubuntu" + comps = ["main","restricted"] + self.sources.add("deb", uri, self.toDist, comps) + self.sources.add("deb", uri, self.toDist+"-updates", comps) + self.sources.add("deb", + "http://security.ubuntu.com/ubuntu/", + self.toDist+"-security", comps) + else: + self.abort() # write (well, backup first ;) ! self.sources.backup(self.sources_backup_ext) @@ -139,6 +181,14 @@ class DistUpgradeControler(object): "resulted in a invalid file. Please " "report this as a bug.")) return False + + if self.sources_disabled: + self._view.information(_("Third party sources disabled"), + _("Some third party entries in your souces.list " + "where disabled. You can re-enable them " + "after the upgrade with the " + "'software-properties' tool or with synaptic." + )) return True def _logChanges(self): @@ -223,12 +273,12 @@ class DistUpgradeControler(object): res = self.cache.commit(fprogress,iprogress) except SystemError, e: # installing the packages failed, can't be retried + self._view.getTerminal().call(["dpkg","--configure","-a"]) self._view.error(_("Could not install the upgrades"), _("The upgrade aborts now. Your system " "can be in an unusable state. A recovery " - "is now run (dpkg --configure -a)."), + "was run (dpkg --configure -a)."), "%s" % e) - self._view.getTerminal().call(["dpkg","--configure","-a"]) return False except IOError, e: # fetch failed, will be retried @@ -303,6 +353,8 @@ class DistUpgradeControler(object): def abort(self): """ abort the upgrade, cleanup (as much as possible) """ self.sources.restoreBackup(self.sources_backup_ext) + # generate a new cache + self.openCache() sys.exit(1) @@ -313,8 +365,6 @@ class DistUpgradeControler(object): self._view.setStep(1) self.openCache() - self.sources = SourcesList() - if not self.cache.sanityCheck(self._view): abort(1) @@ -337,6 +387,22 @@ class DistUpgradeControler(object): # then open the cache (again) self._view.updateStatus(_("Checking package manager")) self.openCache() + # now check if we still have some key packages after the update + # if not something went seriously wrong + for pkg in self.config.getlist("Distro","BaseMetaPkgs"): + if not self.cache.has_key(pkg): + # FIXME: we could offer to add default source entries here, + # but we need to be careful to not duplicate them + # (i.e. the error here could be something else than + # missing sources entires but network errors etc) + logging.error("No '%s' after sources.list rewrite+update") + self._view.error(_("Inavlid package information"), + _("After your package information was " + "updated the essential package '%s' can " + "not be found anymore.\n" + "This indicates a serious error, please " + "report this as a bug.") % pkg) + self.abort() # calc the dist-upgrade and see if the removals are ok/expected # do the dist-upgrade |
