diff options
| author | Michael Vogt <egon@top> | 2005-12-05 16:14:53 +0100 |
|---|---|---|
| committer | Michael Vogt <egon@top> | 2005-12-05 16:14:53 +0100 |
| commit | 66ba55b25018996af69e2a50d0623fd6893b7a61 (patch) | |
| tree | 54921477011015f10fd157d9616a6d103ae5c5c4 | |
| parent | a0ee71f0b7268127ec6da4ca22f002775aba64c0 (diff) | |
| download | python-apt-66ba55b25018996af69e2a50d0623fd6893b7a61.tar.gz | |
* sources.list does a proper backup now
| -rw-r--r-- | DistUpgrade/DistUpgrade.py | 25 | ||||
| -rw-r--r-- | SoftwareProperties/aptsources.py | 15 |
2 files changed, 36 insertions, 4 deletions
diff --git a/DistUpgrade/DistUpgrade.py b/DistUpgrade/DistUpgrade.py index 40cf3d1a..7e8242bd 100644 --- a/DistUpgrade/DistUpgrade.py +++ b/DistUpgrade/DistUpgrade.py @@ -7,6 +7,7 @@ import gtk.gdk import gtk.glade import apt +import apt_pkg import sys from UpdateManager.Common.SimpleGladeApp import SimpleGladeApp @@ -102,7 +103,11 @@ class DistUpgradeControler(object): # check if it's a mirror (or offical site) for mirror in valid_mirrors: if sources.is_mirror(mirror,entry.uri): - if entry.dist in fromDists: + if entry.dist in toDists: + # so the sources.list is already set to the new + # distro + foundToDist = True + elif entry.dist in fromDists: foundToDist = True entry.dist = toDists[fromDists.index(entry.dist)] else: @@ -124,8 +129,22 @@ class DistUpgradeControler(object): "the upgrade was found.\n")) # write (well, backup first ;) ! - sources.backup() + backup_ext = ".distUpgrade" + sources.backup(backup_ext) sources.save() + + # re-check if the written sources are valid, if not revert and + # bail out + try: + sourceslist = apt_pkg.GetPkgSourceList() + sourceslist.ReadMainList() + except SystemError: + sources.restoreBackup(backup_ext) + self._view.error(_("Repository information invalid"), + _("Upgrading the repository information " + "resulted in a invalid file. Please " + "report this as a bug.")) + return False return True def breezyUpgrade(self): @@ -142,7 +161,7 @@ class DistUpgradeControler(object): # then update the package index files - # then open the cache + # then open the cache (again) self._view.updateStatus(_("Reading cache")) self._cache = apt.Cache(self._view.getOpCacheProgress()) diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index e23a0007..540bb801 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -28,6 +28,7 @@ import apt_pkg import glob import shutil import time +import os.path from UpdateManager.Common.DistInfo import DistInfo @@ -223,6 +224,18 @@ class SourcesList: def remove(self, source_entry): self.list.remove(source_entry) + def restoreBackup(self, backup_ext): + " restore sources.list files based on the backup extension " + dir = apt_pkg.Config.FindDir("Dir::Etc") + file = apt_pkg.Config.Find("Dir::Etc::sourcelist") + if os.path.exists(dir+file+backup_ext): + shutil.copy(dir+file+backup_ext,dir+file) + # now sources.list.d + partsdir = apt_pkg.Config.FindDir("Dir::Etc::sourceparts") + for file in glob.glob("%s/*.list" % partsdir): + if os.path.exists(file+backup_ext): + shutil.copy(file+backup_ext,file) + def backup(self, backup_ext=None): """ make a backup of the current source files, if no backup extension is given, the current date/time is used (and returned) """ @@ -231,7 +244,7 @@ class SourcesList: backup_ext = time.strftime("%y%m%d.%H%M") for source in self.list: if not source.file in already_backuped: - shutil.copy(source.file,"%s.%s" % (source.file,backup_ext)) + shutil.copy(source.file,"%s%s" % (source.file,backup_ext)) return backup_ext def load(self,file): |
