summaryrefslogtreecommitdiff
path: root/DistUpgrade/DistUpgrade.py
blob: efe4879b6c2c9b2e63c39532393aded1810e9834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 = "<b>%s</b>" % 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("http://archive.ubuntu.com/ubuntu",entry.uri):
                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()