From 94cf8cacad5850683d35b84682ab024fb7636df0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Dec 2005 13:58:50 +0100 Subject: * DistUpgrade/ tool started * SoftwareProperties/aptsources.py: - added "backup" and some comments * UpdateManager/UpdateManager.py: - comments updated --- DistUpgrade/DistUpgrade.glade | 76 ++++++++++++++++++++++++++++ DistUpgrade/DistUpgrade.py | 104 +++++++++++++++++++++++++++++++++++++++ SoftwareProperties/aptsources.py | 20 ++++++++ UpdateManager/UpdateManager.py | 5 ++ 4 files changed, 205 insertions(+) create mode 100644 DistUpgrade/DistUpgrade.glade create mode 100644 DistUpgrade/DistUpgrade.py diff --git a/DistUpgrade/DistUpgrade.glade b/DistUpgrade/DistUpgrade.glade new file mode 100644 index 00000000..bdd11f5d --- /dev/null +++ b/DistUpgrade/DistUpgrade.glade @@ -0,0 +1,76 @@ + + + + + + + 6 + True + Upgrade distribution + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + True + False + 0 + + + + True + <b>Upgrading</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + GTK_PROGRESS_LEFT_TO_RIGHT + 0 + 0.10000000149 + PANGO_ELLIPSIZE_NONE + + + 0 + False + False + + + + + + + + + + + diff --git a/DistUpgrade/DistUpgrade.py b/DistUpgrade/DistUpgrade.py new file mode 100644 index 00000000..0c6e9202 --- /dev/null +++ b/DistUpgrade/DistUpgrade.py @@ -0,0 +1,104 @@ +#!/usr/bin/python2.4 + +import pygtk +pygtk.require('2.0') +import gtk +import gtk.gdk +import gtk.glade + +import apt +from UpdateManager.Common.SimpleGladeApp import SimpleGladeApp +from UpdateManager.GtkProgress import GtkOpProgress +from SoftwareProperties.aptsources import SourcesList, SourceEntry +from gettext import gettext as _ + +class DistUpgradeProgress(object): + pass + + +class DistUpgradeView(object): + " abstraction for the upgrade view " + def __init__(self): + pass + def getOpCacheProgress(self): + " return a OpProgress() subclass for the given graphic" + return apt.progress.OpProgress() + def updateStatus(self, msg): + """ update the current status of the distUpgrade based + on the current view + """ + pass + def askYesNoQuestion(self,msg): + pass + +class GtkDistUpgradeView(DistUpgradeView,SimpleGladeApp): + " gtk frontend of the distUpgrade tool " + def __init__(self): + # FIXME: i18n must be somewhere relative do this dir + SimpleGladeApp.__init__(self, "DistUpgrade.glade", + None, domain="update-manager") + self._opCacheProgress = GtkOpProgress(self.progressbar_cache) + def getOpCacheProgress(self): + return self._opCacheProgress + def updateStatus(self, msg): + self.label_status = "%s" % msg + +class DistUpgradeControler(object): + def __init__(self, distUpgradeView): + self._view = distUpgradeView + + def sanityCheck(self): + pass + + def updateSourcesList(self, fromDist, to): + sources = SourcesList() + sources.backup() + for entry in sources: + # check if it's a mirror (or offical site) + if sources.is_mirror(entry.uri, "archive.ubuntu.com"): + if entry.dist == fromDist: + entry.dist = to + else: + # disable all entries that are official but don't + # point to the "from" dist + entry.disabled = True + else: + # disable non-official entries that point to dist + if entry.dist == fromDist: + entry.disabled = True + sources.save() + + def breezyUpgrade(self): + # sanity check (check for ubuntu-desktop, brokenCache etc) + self._view.updateStatus(_("Checking the system")) + self.sanityCheck() + + # update sources.list + self._view.updateStatus(_("Updating repository information")) + self.updateSourcesList(fromDist="hoary",to="breezy") + + # then update the package index files + + + # then open the cache + self._view.updateStatus(_("Reading cache")) + self._cache = apt.Cache(self._view.getOpCacheProgress()) + + # do pre-upgrade stuff + + # calc the dist-upgrade and see if the removals are ok/expected + + # do the dist-upgrade + + # do post-upgrade stuff + + # done, ask for reboot + + def run(self): + self.breezyUpgrade() + + +if __name__ == "__main__": + view = GtkDistUpgradeView() + app = DistUpgradeControler(view) + app.run() diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index aa3cbb5a..d059a719 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -26,6 +26,8 @@ import gettext import re import apt_pkg import glob +import shutil +import time from UpdateManager.Common.DistInfo import DistInfo @@ -156,6 +158,11 @@ class SourcesList: for file in glob.glob("%s/*.list" % partsdir): self.load(file) + def __iter__(self): + for entry in self.list: + yield entry + raise StopIteration + def is_mirror(self, add_uri, orig_uri): """check if the given add_url is idential or a mirror of orig_uri e.g. add_uri = archive.ubuntu.com @@ -204,7 +211,19 @@ class SourcesList: def remove(self, source_entry): self.list.remove(source_entry) + 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) """ + already_backuped = set() + if backup_ext == None: + backup_ext = time.strftime("%d%m%y.%H%M") + for source in self.list: + if not source.file in already_backuped: + shutil.copy(source.file,"%s.%s" % (source.file,backup_ext)) + return backup_ext + def load(self,file): + """ (re)load the current sources """ f = open(file, "r") lines = f.readlines() for line in lines: @@ -213,6 +232,7 @@ class SourcesList: f.close() def save(self,file): + """ save the current sources """ files = {} for source in self.list: if not files.has_key(source.file): diff --git a/UpdateManager/UpdateManager.py b/UpdateManager/UpdateManager.py index 6527d4e9..62c48cf5 100644 --- a/UpdateManager/UpdateManager.py +++ b/UpdateManager/UpdateManager.py @@ -672,11 +672,16 @@ class UpdateManager(SimpleGladeApp): fetcher.Run() print "Done downloading" + # extract the tarbal print "extracting" tar = tarfile.open(tmpdir+"/"+os.path.basename(uri),"r") for tarinfo in tar: tar.extract(tarinfo) tar.close() + + # FIXME: check a internal dependency file to make sure + # that the script will run correctly + # see if we have a script file that we can run script = "%s/%s" % (tmpdir, self.new_dist.name) if not os.path.exists(script): -- cgit v1.2.3