~mvo/update-manager/not-automatic

« back to all changes in this revision

Viewing changes to UpdateManagerHildon/UpdateManagerHildon.py

  • Committer: Michael Vogt
  • Date: 2008-05-21 16:01:17 UTC
  • mfrom: (952.1.10 hildon)
  • Revision ID: michael.vogt@ubuntu.com-20080521160117-lom591v3zpyk53yt
* UpdateManagerHildon/UpdateManagerHildon.py:
  - add hildon support (thanks to Tollef Fog Heen and
    Emmet Hikory)
  - make networkless upgrades more robust (LP: #227197)
* DistUpgrade/DistUpgradeViewGtk.py:
  - work around hang in svg loader (LP: #186465)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# UpdateManager.py 
 
2
#  
 
3
#  Copyright (c) 2008 Canonical
 
4
#  
 
5
#  Author: Tollef Fog Heen <tfheen@err.no>
 
6
#          Emmet Hikory <persia@ubuntu.com>
 
7
#          Michael Vogt <mvo@ubuntu.com>
 
8
 
9
#  This program is free software; you can redistribute it and/or 
 
10
#  modify it under the terms of the GNU General Public License as 
 
11
#  published by the Free Software Foundation; either version 2 of the
 
12
#  License, or (at your option) any later version.
 
13
 
14
#  This program is distributed in the hope that it will be useful,
 
15
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#  GNU General Public License for more details.
 
18
 
19
#  You should have received a copy of the GNU General Public License
 
20
#  along with this program; if not, write to the Free Software
 
21
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
22
#  USA
 
23
 
 
24
from UpdateManager.UpdateManager import UpdateManager
 
25
import hildon
 
26
 
 
27
import pygtk
 
28
pygtk.require('2.0')
 
29
import gtk
 
30
 
 
31
import apt
 
32
import apt_pkg
 
33
from gettext import gettext as _
 
34
from UpdateManager.Common.utils import *
 
35
 
 
36
import logging
 
37
import time
 
38
import os
 
39
 
 
40
# actions for "invoke_manager"
 
41
(INSTALL, UPDATE) = range(2)
 
42
 
 
43
# DistUpgrade.DistUpgradeViewGtk.GtkInstallProgressAdapter is better,
 
44
# but requires more effort, and vte.  This is a simpler implementation.
 
45
 
 
46
from DistUpgrade.DistUpgradeViewGtk import DistUpgradeViewGtk, GtkFetchProgressAdapter, GtkInstallProgressAdapter
 
47
from DistUpgrade.DistUpgradeView import (STEP_PREPARE, 
 
48
                                         STEP_MODIFY_SOURCES, 
 
49
                                         STEP_FETCH, 
 
50
                                         STEP_INSTALL, 
 
51
                                         STEP_CLEANUP, 
 
52
                                         STEP_REBOOT,
 
53
                                         STEP_N)
 
54
 
 
55
class HildonFetchProgress(GtkFetchProgressAdapter):
 
56
  def __init__(self, parent, header, msg):
 
57
    GtkFetchProgressAdapter.__init__(self, parent)
 
58
    # hide all steps
 
59
    for i in range(1,STEP_N):
 
60
      parent.hideStep(i)
 
61
    parent.label_title.set_markup("<b><big>%s</big></b>" % header)
 
62
  def start(self):
 
63
    GtkFetchProgressAdapter.start(self)
 
64
    # this is only needed when a InstallProgressAdapter is used
 
65
    # in addition to the FetchProgress one - they share the 
 
66
    # same parent
 
67
    self.parent.setStep(STEP_FETCH)
 
68
 
 
69
class HildonInstallProgressAdapter(GtkInstallProgressAdapter):
 
70
  def __init__(self, parent, header, msg):
 
71
    GtkInstallProgressAdapter.__init__(self, parent)
 
72
    # hide step not relevant
 
73
    for i in (STEP_PREPARE, 
 
74
              STEP_MODIFY_SOURCES, 
 
75
              STEP_CLEANUP, 
 
76
              STEP_REBOOT):
 
77
      parent.hideStep(i)
 
78
    # and show only those two
 
79
    for i in (STEP_FETCH, 
 
80
                STEP_INSTALL):
 
81
        parent.showStep(i)
 
82
    parent.label_title.set_markup("<b><big>%s</big></b>" % header)
 
83
  def startUpdate(self):
 
84
    GtkInstallProgressAdapter.startUpdate(self)
 
85
    self.parent.setStep(STEP_INSTALL)
 
86
 
 
87
class UpdateManagerHildon(UpdateManager):
 
88
 
 
89
  def __init__(self, datadir):
 
90
      UpdateManager.__init__(self, datadir)
 
91
      self.program = hildon.Program()
 
92
      self.program.__init__()
 
93
 
 
94
      self.window = hildon.Window()
 
95
      self.window.set_title("PyGlade")
 
96
      self.program.add_window(self.window)
 
97
      #print dir(self.glade)
 
98
      for widget in [ "window_main", "dialog_release_notes", "window_fetch", 
 
99
                      "dialog_manual_update", "dialog_cacheprogress", 
 
100
                      "dialog_dist_upgrade" ]:
 
101
          self.glade.get_widget(widget).reparent(self.window)
 
102
      self.view = None
 
103
 
 
104
  # FIXME: below is still too much duplicated code m'kay
 
105
  def invoke_manager(self, action):
 
106
    # don't display apt-listchanges, we already showed the changelog
 
107
    os.environ["APT_LISTCHANGES_FRONTEND"]="none"
 
108
    os.environ["DEBIAN_FRONTEND"] = "noninteractive"
 
109
    # Do not suspend during the update process
 
110
    (dev, cookie) = inhibit_sleep()
 
111
    # set window to insensitive
 
112
    self.window_main.set_sensitive(False)
 
113
    self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
 
114
 
 
115
    self.run_synaptic(None, action, None)
 
116
 
 
117
    s = _("Reading package information")
 
118
    self.label_cache_progress_title.set_label("<b><big>%s</big></b>" % s)
 
119
    self.fillstore()
 
120
 
 
121
    # Allow suspend after synaptic is finished
 
122
    if cookie != False:
 
123
        allow_sleep(dev, cookie)
 
124
    self.window_main.set_sensitive(True)
 
125
    self.window_main.window.set_cursor(None)
 
126
    
 
127
 
 
128
  def run_synaptic(self, id, action, lock):
 
129
    try:
 
130
      apt_pkg.PkgSystemUnLock()
 
131
    except SystemError:
 
132
      pass
 
133
    
 
134
    if self.view == None:
 
135
      self.view = DistUpgradeViewGtk("/usr/share/update-manager")
 
136
      self.view.window_main.set_transient_for(self.window_main)
 
137
 
 
138
    fprogress = HildonFetchProgress(self.view, 
 
139
                _("Downloading Package Information"),
 
140
                _("The repositories will be checked for new, removed, or "
 
141
                  "updated software packages"))
 
142
    self.view.window_main.show()
 
143
 
 
144
    # FIXME: add error handling (commit() and update() both can
 
145
    #        throw SystemErrors 
 
146
    if action == INSTALL:
 
147
      iprogress = HildonInstallProgressAdapter(self.view, 
 
148
                    _("Downloading Package Updates"),
 
149
                    _("The selected package updates are being downloaded and "
 
150
                      "installed on the system"))
 
151
      self.cache.commit(fprogress, iprogress)
 
152
    elif action == UPDATE:
 
153
      self.cache.update(fprogress)
 
154
    else:
 
155
      print _("run_synaptic called with unknown action")
 
156
      return False
 
157
    self.view.window_main.hide()
 
158
    #lock.release()
 
159