summaryrefslogtreecommitdiff
path: root/UpdateManager
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2006-08-15 18:07:35 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2006-08-15 18:07:35 +0200
commit1d6a496ee2f9e8946e94591569c9d1c06794f497 (patch)
treee611e832ffa5e3a56a79387f00af63962e855edc /UpdateManager
parent141d62c9fdbd18027d79869ddf1ab54ad67e3b15 (diff)
parenta53e49c46faae31eccd7e65b8ffbcb91fbcaf18a (diff)
downloadpython-apt-1d6a496ee2f9e8946e94591569c9d1c06794f497.tar.gz
* merged from glatzor
* send Inhibit command to gnome-power-manager when applying updates
Diffstat (limited to 'UpdateManager')
-rw-r--r--UpdateManager/UpdateManager.py65
1 files changed, 58 insertions, 7 deletions
diff --git a/UpdateManager/UpdateManager.py b/UpdateManager/UpdateManager.py
index 5bdea61a..1cf97da0 100644
--- a/UpdateManager/UpdateManager.py
+++ b/UpdateManager/UpdateManager.py
@@ -43,6 +43,7 @@ import os
import os.path
import urllib2
import re
+import locale
import tempfile
import pango
import subprocess
@@ -589,14 +590,31 @@ class UpdateManager(SimpleGladeApp):
self.remove_update(pkg)
iter = self.store.iter_next(iter)
+ def humanize_size(self, bytes):
+ """
+ Convert a given size in bytes to a nicer better readable unit
+ """
+ if bytes == 0:
+ # TRANSLATORS: download size is 0
+ return _("None")
+ elif bytes < 1024:
+ # TRANSLATORS: download size of very small updates
+ return _("1 KB")
+ elif bytes < 1024 * 1024:
+ # TRANSLATORS: download size of small updates, e.g. "250 KB"
+ return locale.format(_("%.0f KB"), bytes/1024)
+ else:
+ # TRANSLATORS: download size of updates, e.g. "2.3 MB"
+ return locale.format(_("%.1f MB"), bytes / 1024 / 1024)
+
def remove_update(self, pkg):
name = pkg.name
if name in self.packages:
self.packages.remove(name)
self.dl_size -= pkg.packageSize
# TRANSLATORS: b stands for Bytes
- self.label_downsize.set_markup(_("Download size: %sb" % \
- apt_pkg.SizeToStr(self.dl_size)))
+ self.label_downsize.set_markup(_("Download size: %s" % \
+ self.humanize_size(self.dl_size)))
if len(self.packages) == 0:
self.button_install.set_sensitive(False)
@@ -606,7 +624,7 @@ class UpdateManager(SimpleGladeApp):
self.packages.append(name)
self.dl_size += pkg.packageSize
self.label_downsize.set_markup(_("Download size: %s" % \
- apt_pkg.SizeToStr(self.dl_size)))
+ self.humanize_size(self.dl_size)))
if len(self.packages) > 0:
self.button_install.set_sensitive(True)
@@ -629,7 +647,7 @@ class UpdateManager(SimpleGladeApp):
"You can install %s updates",
self.list.num_updates) % \
self.list.num_updates + "</b></big>"
- text_download = _("Download size: %s") % apt_pkg.SizeToStr(self.dl_size)
+ text_download = _("Download size: %s") % self.humanize_size(self.dl_size)
self.notebook_details.set_sensitive(True)
self.treeview_update.set_sensitive(True)
self.button_install.grab_default()
@@ -694,6 +712,9 @@ class UpdateManager(SimpleGladeApp):
# don't display apt-listchanges, we already showed the changelog
os.environ["APT_LISTCHANGES_FRONTEND"]="none"
+ # Do not suspend during the update process
+ (dev, cookie) = self.inhibit_sleep()
+
# set window to insensitive
self.window_main.set_sensitive(False)
self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
@@ -708,12 +729,36 @@ class UpdateManager(SimpleGladeApp):
while gtk.events_pending():
gtk.main_iteration()
self.fillstore()
+
+ # Allow suspend after synaptic is finished
+ if cookie != False:
+ self.allow_sleep(dev, cookie)
self.window_main.set_sensitive(True)
self.window_main.window.set_cursor(None)
- def toggled(self, renderer, path_string):
+ def inhibit_sleep(self):
+ """Send a dbus signal to gnome-power-manager to not suspend
+ the system"""
+ try:
+ import dbus
+ bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
+ devobj = bus.get_object('org.gnome.PowerManager',
+ '/org/gnome/PowerManager')
+ dev = dbus.Interface(devobj, "org.gnome.PowerManager")
+ cookie = dev.Inhibit('UpdateManager', 'Updating system')
+ return (dev, cookie)
+ except:
+ print "could not send the dbus InhibitInactiveSleep signal"
+ return (False, False)
+
+ def allow_sleep(self, dev, cookie):
+ """Send a dbus signal to gnome-power-manager to allow a suspending
+ the system"""
+ dev.UnInhibit(cookie)
+
+ def toggled(self, renderer, path):
""" a toggle button in the listview was toggled """
- iter = self.store.get_iter_from_string(path_string)
+ iter = self.store.get_iter(path)
if self.store.get_value(iter, LIST_INSTALL):
self.store.set_value(iter, LIST_INSTALL, False)
self.remove_update(self.store.get_value(iter, LIST_PKG))
@@ -721,6 +766,12 @@ class UpdateManager(SimpleGladeApp):
self.store.set_value(iter, LIST_INSTALL, True)
self.add_update(self.store.get_value(iter, LIST_PKG))
+ def on_treeview_update_row_activated(self, treeview, path, column, *args):
+ """
+ If an update row was activated (by pressing space), toggle the
+ install check box
+ """
+ self.toggled(None, path)
def exit(self):
""" exit the application, save the state """
@@ -780,7 +831,7 @@ class UpdateManager(SimpleGladeApp):
else:
contents += _("Version %s") % pkg.candidateVersion
#TRANSLATORS: the b stands for Bytes
- contents += " " + _("(Size: %sb)") % apt.SizeToStr(pkg.packageSize)
+ contents += " " + _("(Size: %s)") % self.humanize_size(pkg.packageSize)
contents += "</small>"
iter = self.store.append([True, contents, pkg.name, pkg])