~ubuntu-branches/ubuntu/maverick/update-manager/maverick-updates

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeViewGtk.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2010-07-09 10:07:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100709100734-nq8qt37ppszfy1mu
Tags: 1:0.142.3
* merged lp:~and471/update-manager/fix-bug-386196, many thanks
* DistUpgrade/DistUpgradeView*.py:
  - port progress to new python-apt 0.8 API
* merged lp:~mdz/update-manager/small-fixes-20100707, many thanks
* DistUpgrade/DistUpgradeViewGtk.py:
  - call progressbar.set_fraction() less often to avoid too much
    CPU consumption on certain graphic drivers
* UpdateManager/GtkProgress.py:
  - limit the amount of set_fraction() here too (LP: #595845)
* UpdateManager/UpdateManager.py:
  - disconnect the model before adding lots of new items, this
    speeds up the building of the view massively

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    def changeCdrom(self):
70
70
        return False
71
71
 
72
 
class GtkOpProgress(apt.progress.OpProgress):
 
72
class GtkOpProgress(apt.progress.base.OpProgress):
73
73
  def __init__(self, progressbar):
74
74
      self.progressbar = progressbar
75
75
      #self.progressbar.set_pulse_step(0.01)
76
76
      #self.progressbar.pulse()
 
77
      self.fraction = 0.0
77
78
 
78
79
  def update(self, percent):
79
80
      #if percent > 99:
80
81
      #    self.progressbar.set_fraction(1)
81
82
      #else:
82
83
      #    self.progressbar.pulse()
83
 
      self.progressbar.set_fraction(percent/100.0)
 
84
      new_fraction = percent/100.0
 
85
      if abs(self.fraction-new_fraction) > 0.1:
 
86
        self.fraction = new_fraction
 
87
        self.progressbar.set_fraction(self.fraction)
84
88
      while gtk.events_pending():
85
89
          gtk.main_iteration()
86
90
 
93
97
    # xy in the gui
94
98
    # FIXME2: we need to thing about mediaCheck here too
95
99
    def __init__(self, parent):
96
 
        FetchProgress.__init__(self)
 
100
        super(GtkFetchProgressAdapter, self).__init__()
97
101
        # if this is set to false the download will cancel
98
102
        self.status = parent.label_status
99
103
        self.progress = parent.progressbar_cache
104
108
    def cancelClicked(self, widget):
105
109
        logging.debug("cancelClicked")
106
110
        self.canceled = True
107
 
    def mediaChange(self, medium, drive):
 
111
    def media_change(self, medium, drive):
108
112
        #print "mediaChange %s %s" % (medium, drive)
109
113
        msg = _("Please insert '%s' into the drive '%s'") % (medium,drive)
110
114
        dialog = gtk.MessageDialog(parent=self.parent.window_main,
120
124
        return False
121
125
    def start(self):
122
126
        #logging.debug("start")
123
 
        FetchProgress.start(self)
 
127
        super(GtkFetchProgressAdapter, self).start()
124
128
        self.progress.set_fraction(0)
125
129
        self.status.show()
126
130
        self.button_cancel.show()
129
133
        self.progress.set_text(" ")
130
134
        self.status.set_text(_("Fetching is complete"))
131
135
        self.button_cancel.hide()
132
 
    def pulse(self):
133
 
        # FIXME: move the status_str and progress_str into python-apt
134
 
        # (python-apt need i18n first for this)
135
 
        FetchProgress.pulse(self)
136
 
        self.progress.set_fraction(self.percent/100.0)
137
 
        currentItem = self.currentItems + 1
138
 
        if currentItem > self.totalItems:
139
 
            currentItem = self.totalItems
140
 
 
141
 
        if self.currentCPS > 0:
142
 
            self.status.set_text(_("Fetching file %li of %li at %sB/s") % (currentItem, self.totalItems, apt_pkg.SizeToStr(self.currentCPS)))
143
 
            self.progress.set_text(_("About %s remaining") % FuzzyTimeToStr(self.eta))
144
 
        else:
145
 
            self.status.set_text(_("Fetching file %li of %li") % (currentItem, self.totalItems))
146
 
            self.progress.set_text("  ")
147
 
 
 
136
    def pulse(self, owner):
 
137
        super(GtkFetchProgressAdapter, self).pulse(owner)
 
138
        # only update if there is a noticable change
 
139
        if abs(self.percent-self.progress.get_fraction()*100.0) > 0.1:
 
140
          self.progress.set_fraction(self.percent/100.0)
 
141
          currentItem = self.current_items + 1
 
142
          if currentItem > self.total_items:
 
143
            currentItem = self.total_items
 
144
            if self.current_cps > 0:
 
145
              self.status.set_text(_("Fetching file %li of %li at %sB/s") % (
 
146
                  currentItem, self.total_items, 
 
147
                  apt_pkg.size_to_str(self.current_cps)))
 
148
              self.progress.set_text(_("About %s remaining") % FuzzyTimeToStr(
 
149
                  self.eta))
 
150
            else:
 
151
              self.status.set_text(_("Fetching file %li of %li") % (
 
152
                  currentItem, self.total_items))
 
153
              self.progress.set_text("  ")
148
154
        while gtk.events_pending():
149
155
            gtk.main_iteration()
150
156
        return (not self.canceled)
168
174
        # some options for dpkg to make it die less easily
169
175
        apt_pkg.Config.set("DPkg::StopOnError","False")
170
176
 
171
 
    def startUpdate(self):
172
 
        InstallProgress.startUpdate(self)
 
177
    def start_update(self):
 
178
        InstallProgress.start_update(self)
173
179
        self.finished = False
174
180
        # FIXME: add support for the timeout
175
181
        # of the terminal (to display something useful then)
259
265
          sys.exitfunc = lambda: True
260
266
        return pid
261
267
 
262
 
    def statusChange(self, pkg, percent, status):
 
268
    def status_change(self, pkg, percent, status):
263
269
        # start the timer when the first package changes its status
264
270
        if self.start_time == 0.0:
265
271
          #print "setting start time to %s" % self.start_time
266
272
          self.start_time = time.time()
267
 
        self.progress.set_fraction(float(percent)/100.0)
268
 
        self.label_status.set_text(status.strip())
 
273
        # only update if there is a noticable change
 
274
        if abs(percent-self.progress.get_fraction()*100.0) > 0.1:
 
275
          self.progress.set_fraction(float(percent)/100.0)
 
276
          self.label_status.set_text(status.strip())
269
277
        # start showing when we gathered some data
270
278
        if percent > 1.0:
271
279
          self.last_activity = time.time()
290
298
        self.apt_status = status
291
299
        self.finished = True
292
300
 
293
 
    def waitChild(self):
 
301
    def wait_child(self):
294
302
        while not self.finished:
295
 
            self.updateInterface()
 
303
            self.update_interface()
296
304
        return self.apt_status
297
305
 
298
 
    def finishUpdate(self):
 
306
    def finish_update(self):
299
307
        self.label_status.set_text("")
300
308
    
301
 
    def updateInterface(self):
302
 
        InstallProgress.updateInterface(self)
 
309
    def update_interface(self):
 
310
        InstallProgress.update_interface(self)
303
311
        # check if we haven't started yet with packages, pulse then
304
312
        if self.start_time == 0.0:
305
313
          self.progress.pulse()
311
319
            logging.warning("no activity on terminal for %s seconds (%s)" % (self.TIMEOUT_TERMINAL_ACTIVITY, self.label_status.get_text()))
312
320
            self.activity_timeout_reported = True
313
321
          self.parent.expander_terminal.set_expanded(True)
 
322
        # process events
314
323
        while gtk.events_pending():
315
324
            gtk.main_iteration()
316
 
        time.sleep(0.005)
 
325
        time.sleep(0.01)
317
326
 
318
327
class DistUpgradeVteTerminal(object):
319
328
  def __init__(self, parent, term):