Merge lp://qastaging/~glatzor/update-manager/ubuntu-glatzor into lp://qastaging/update-manager

Proposed by Sebastian Heinlein
Status: Merged
Merged at revision: 1828
Proposed branch: lp://qastaging/~glatzor/update-manager/ubuntu-glatzor
Merge into: lp://qastaging/update-manager
Diff against target: 366 lines (+128/-144)
4 files modified
UpdateManager/UpdateManager.py (+34/-13)
UpdateManager/backend/InstallBackend.py (+12/-1)
UpdateManager/backend/InstallBackendAptdaemon.py (+42/-76)
UpdateManager/backend/InstallBackendSynaptic.py (+40/-54)
To merge this branch: bzr merge lp://qastaging/~glatzor/update-manager/ubuntu-glatzor
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+16123@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Sebastian Heinlein (glatzor) wrote :

Ported to latest aptdaemon API and simplified the InstallBackends

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UpdateManager/UpdateManager.py'
--- UpdateManager/UpdateManager.py 2009-11-23 11:09:20 +0000
+++ UpdateManager/UpdateManager.py 2009-12-14 12:35:26 +0000
@@ -121,6 +121,12 @@
121 except:121 except:
122 logging.exception("setlocale failed")122 logging.exception("setlocale failed")
123123
124 # Used for inhibiting power management
125 self.sleep_cookie = None
126 self.sleep_dev = None
127
128 self.reboot_required = False
129
124 self.image_logo.set_from_icon_name("update-manager", gtk.ICON_SIZE_DIALOG)130 self.image_logo.set_from_icon_name("update-manager", gtk.ICON_SIZE_DIALOG)
125 self.window_main.set_sensitive(False)131 self.window_main.set_sensitive(False)
126 self.window_main.grab_focus()132 self.window_main.grab_focus()
@@ -213,7 +219,7 @@
213 self.window_main.show()219 self.window_main.show()
214 # get the install backend220 # get the install backend
215 self.install_backend = backend.backend_factory(self.window_main)221 self.install_backend = backend.backend_factory(self.window_main)
216222 self.install_backend.connect("action-done", self._on_backend_done)
217 # it can only the iconified *after* it is shown (even if the docs223 # it can only the iconified *after* it is shown (even if the docs
218 # claim otherwise)224 # claim otherwise)
219 if options.no_focus_on_map:225 if options.no_focus_on_map:
@@ -615,29 +621,44 @@
615 os.environ["APT_LISTCHANGES_FRONTEND"]="none"621 os.environ["APT_LISTCHANGES_FRONTEND"]="none"
616622
617 # Do not suspend during the update process623 # Do not suspend during the update process
618 (dev, cookie) = inhibit_sleep()624 (self.sleep_dev, self.sleep_cookie) = inhibit_sleep()
619625
620 # set window to insensitive626 # set window to insensitive
621 self.window_main.set_sensitive(False)627 self.window_main.set_sensitive(False)
622 self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))628 self.window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
623629#
624 # do it630 # do it
625 if action == UPDATE:631 if action == UPDATE:
626 self.install_backend.update()632 self.install_backend.update()
627 elif action == INSTALL:633 elif action == INSTALL:
628 has_reboot = os.path.exists(REBOOT_REQUIRED_FILE)634 # If the progress dialog should be closed automatically afterwards
629 # do it635 gconfclient = gconf.client_get_default()
630 self.install_backend.commit(self.cache)636 close_on_done = gconfclient.get_bool("/apps/update-manager/"
631 # check if there is a new reboot required notification637 "autoclose_install_window")
632 if not has_reboot and os.path.exists(REBOOT_REQUIRED_FILE):638 # Get the packages which should be installed and update
633 self.show_reboot_required_dialog()639 pkgs_install = []
634 s = _("Reading package information")640 pkgs_upgrade = []
635 self.label_cache_progress_title.set_label("<b><big>%s</big></b>" % s)641 for pkg in self.cache:
642 if pkg.markedInstall:
643 pkgs_install.append(pkg.name)
644 elif pkg.markedUpgrade:
645 pkgs_upgrade.append(pkg.name)
646 self.reboot_required = os.path.exists(REBOOT_REQUIRED_FILE)
647 self.install_backend.commit(pkgs_install, pkgs_upgrade, close_on_done)
648
649 def _on_backend_done(self, backend, action):
650 # check if there is a new reboot required notification
651 if action == INSTALL and not self.reboot_required and \
652 os.path.exists(REBOOT_REQUIRED_FILE):
653 self.show_reboot_required_dialog()
654 msg = _("Reading package information")
655 self.label_cache_progress_title.set_label("<b><big>%s</big></b>" % msg)
636 self.fillstore()656 self.fillstore()
637657
638 # Allow suspend after synaptic is finished658 # Allow suspend after synaptic is finished
639 if cookie != False:659 if self.sleep_cookie:
640 allow_sleep(dev, cookie)660 allow_sleep(self.sleep_dev, self.sleep_cookie)
661 self.sleep_cookie = self.sleep_dev = None
641 self.window_main.set_sensitive(True)662 self.window_main.set_sensitive(True)
642 self.window_main.window.set_cursor(None)663 self.window_main.window.set_cursor(None)
643664
644665
=== modified file 'UpdateManager/backend/InstallBackend.py'
--- UpdateManager/backend/InstallBackend.py 2009-07-24 14:17:02 +0000
+++ UpdateManager/backend/InstallBackend.py 2009-12-14 12:35:26 +0000
@@ -1,18 +1,29 @@
1# (c) 2005-2009 Canonical, GPL1# (c) 2005-2009 Canonical, GPL
2#2#
33
4class InstallBackend(object):4import gobject
5
6class InstallBackend(gobject.GObject):
5 """The abstract backend that can install/remove packages"""7 """The abstract backend that can install/remove packages"""
8
9 __gsignals__ = {"action-done": (gobject.SIGNAL_RUN_FIRST,
10 gobject.TYPE_NONE, (gobject.TYPE_INT,))}
11
12 (INSTALL, UPDATE) = range(2)
13
6 def __init__(self, window_main):14 def __init__(self, window_main):
7 """init backend15 """init backend
8 takes a gtk main window as parameter16 takes a gtk main window as parameter
9 """17 """
18 gobject.GObject.__init__(self)
10 self.window_main = window_main19 self.window_main = window_main
1120
12 def commit(self, cache):21 def commit(self, cache):
13 """Commit the cache changes """22 """Commit the cache changes """
23 raise NotImplemented
1424
15 def update(self):25 def update(self):
16 """Run a update to refresh the package list"""26 """Run a update to refresh the package list"""
27 raise NotImplemented
1728
1829
1930
=== modified file 'UpdateManager/backend/InstallBackendAptdaemon.py'
--- UpdateManager/backend/InstallBackendAptdaemon.py 2009-10-08 07:51:51 +0000
+++ UpdateManager/backend/InstallBackendAptdaemon.py 2009-12-14 12:35:26 +0000
@@ -1,87 +1,53 @@
1# (c) 2005-2009 Canonical, GPL1# (c) 2005-2009 Canonical, GPL
2#2#
33
4import apt_pkg4from aptdaemon import client, enums
5import gobject5from aptdaemon.gtkwidgets import AptProgressDialog
6import gtk
7
8import dbus
9from aptdaemon import client
10from aptdaemon.enums import *
11from aptdaemon.gtkwidgets import (AptErrorDialog,
12 AptProgressDialog,
13 AptMessageDialog)
146
15from InstallBackend import InstallBackend7from InstallBackend import InstallBackend
168
9POLKIT_ERROR_NOT_AUTHORIZED = "org.freedesktop.PolicyKit.Error.NotAuthorized"
1710
18class InstallBackendAptdaemon(InstallBackend):11class InstallBackendAptdaemon(InstallBackend):
19 """The abstract backend that can install/remove packages"""12
2013 """Makes use of aptdaemon to refresh the cache and to install updates."""
21 def _get_icon(self):14
22 theme = gtk.icon_theme_get_default ()15 def update(self):
23 icon = theme.load_icon("update-manager", 16, 0)16 """Run a update to refresh the package list"""
24 return icon17 ac = client.AptClient()
2518 ac.update_cache(reply_handler=self._run_transaction,
26 def commit(self, cache):19 error_handler=self._on_error)
20
21 def commit(self, pkgs_install, pkgs_upgrade, close_on_done):
27 """Commit a list of package adds and removes"""22 """Commit a list of package adds and removes"""
28 try:23 ac = client.AptClient()
29 apt_pkg.PkgSystemUnLock()
30 except SystemError:
31 pass
32 self.ac = client.AptClient()
33 add = []
34 upgrade = []
35 for pkg in cache:
36 if pkg.markedInstall:
37 add.append(pkg.name)
38 elif pkg.markedUpgrade:
39 upgrade.append(pkg.name)
40 # parameter order: install, reinstall, remove, purge, upgrade24 # parameter order: install, reinstall, remove, purge, upgrade
41 t = self.ac.commit_packages(add, [], [], [], upgrade,25 _reply_handler = lambda trans: self._run_transaction(trans,
42 exit_handler=self._on_exit)26 close_on_done)
43 dia = AptProgressDialog(t, parent=self.window_main)27 ac.commit_packages(pkgs_install, [], [], [], pkgs_upgrade,
44 dia.set_icon(self._get_icon())28 reply_handler=_reply_handler,
45 try:29 error_handler=self._on_error)
46 dia.run()30
47 except dbus.exceptions.DBusException, e:31 def _run_transaction(self, trans, close=True):
48 if e._dbus_error_name == "org.freedesktop.PolicyKit.Error.NotAuthorized":32 dia = AptProgressDialog(trans, parent=self.window_main)
49 pass33 dia.set_icon_name("update-manager")
50 else:34 dia.connect("finished", self._on_finished)
51 raise35 dia.run(show_error=True, close_on_finished=close,
52 dia.hide()36 reply_handler=lambda: True,
53 self._show_messages(t)37 error_handler=self._on_error)
5438
55 def update(self):39 def _on_finished(self, dialog):
56 """Run a update to refresh the package list"""40 dialog.destroy()
57 try:41 if dialog._transaction.role == enums.ROLE_UPDATE_CACHE:
58 apt_pkg.PkgSystemUnLock()42 action = self.UPDATE
59 except SystemError:43 else:
44 action = self.INSTALL
45 self.emit("action-done", action)
46
47 def _on_error(self, error):
48 if error.get_dbus_name() == POLKIT_ERROR_NOT_AUTHORIZED:
49 # Should already be handled by the polkit agent
60 pass50 pass
61 self.ac = client.AptClient()51 else:
62 t = self.ac.update_cache(exit_handler=self._on_exit)52 #FIXME: Show an error dialog
63 dia = AptProgressDialog(t, parent=self.window_main, terminal=False)53 raise error
64 dia.set_icon(self._get_icon())
65 try:
66 dia.run()
67 except dbus.exceptions.DBusException, e:
68 if e._dbus_error_name == "org.freedesktop.PolicyKit.Error.NotAuthorized":
69 pass
70 else:
71 raise
72 dia.hide()
73 self._show_messages(t)
74
75 def _on_exit(self, trans, exit):
76 if exit == EXIT_FAILED:
77 d = AptErrorDialog(trans.get_error(), parent=self.window_main)
78 d.run()
79 d.hide()
80
81 def _show_messages(self, trans):
82 while gtk.events_pending():
83 gtk.main_iteration()
84 for msg in trans._messages:
85 d = AptMessageDialog(msg.enum, msg.details, parent=self.window_main)
86 d.run()
87 d.hide()
8854
=== modified file 'UpdateManager/backend/InstallBackendSynaptic.py'
--- UpdateManager/backend/InstallBackendSynaptic.py 2009-07-24 14:17:02 +0000
+++ UpdateManager/backend/InstallBackendSynaptic.py 2009-12-14 12:35:26 +0000
@@ -12,15 +12,14 @@
12import gconf12import gconf
13from gettext import gettext as _13from gettext import gettext as _
1414
15import gobject
16
15from InstallBackend import InstallBackend17from InstallBackend import InstallBackend
1618
17class InstallBackendSynaptic(InstallBackend):19class InstallBackendSynaptic(InstallBackend):
18 """ Install backend based on synaptic """20 """ Install backend based on synaptic """
19
20 # synaptic actions
21 (INSTALL, UPDATE) = range(2)
2221
23 def _run_synaptic(self, id, lock, cache=None, action=INSTALL):22 def _run_synaptic(self, action, opt, tempf):
24 try:23 try:
25 apt_pkg.PkgSystemUnLock()24 apt_pkg.PkgSystemUnLock()
26 except SystemError:25 except SystemError:
@@ -28,54 +27,41 @@
28 cmd = ["/usr/bin/gksu", 27 cmd = ["/usr/bin/gksu",
29 "--desktop", "/usr/share/applications/update-manager.desktop", 28 "--desktop", "/usr/share/applications/update-manager.desktop",
30 "--", "/usr/sbin/synaptic", "--hide-main-window", 29 "--", "/usr/sbin/synaptic", "--hide-main-window",
31 "--non-interactive", "--parent-window-id", "%s" % (id) ]30 "--non-interactive", "--parent-window-id",
32 if action == self.INSTALL:31 "%s" % self.window_main.window.xid ]
33 # close when update was successful (its ok to use a Synaptic::32 cmd.extend(opt)
34 # option here, it will not get auto-saved, because synaptic does33 flags = gobject.SPAWN_DO_NOT_REAP_CHILD
35 # not save options in non-interactive mode)34 (pid, stdin, stdout, stderr) = gobject.spawn_async(cmd, flags=flags)
36 gconfclient = gconf.client_get_default()35 gobject.child_watch_add(pid, self._on_synaptic_exit, (action, tempf))
37 if gconfclient.get_bool("/apps/update-manager/autoclose_install_window"):36
38 cmd.append("-o")37 def _on_synaptic_exit(self, pid, condition, data):
39 cmd.append("Synaptic::closeZvt=true")38 action, tempf = data
40 # custom progress strings39 if tempf:
41 cmd.append("--progress-str")40 tempf.close()
42 cmd.append("%s" % _("Please wait, this can take some time."))41 self.emit("action-done", action)
43 cmd.append("--finish-str")42
44 cmd.append("%s" % _("Update is complete"))
45 f = tempfile.NamedTemporaryFile()
46 for pkg in cache:
47 if pkg.markedInstall or pkg.markedUpgrade:
48 f.write("%s\tinstall\n" % pkg.name)
49 cmd.append("--set-selections-file")
50 cmd.append("%s" % f.name)
51 f.flush()
52 self.return_code = subprocess.call(cmd)
53 f.close()
54 elif action == self.UPDATE:
55 cmd.append("--update-at-startup")
56 self.return_code = subprocess.call(cmd)
57 else:
58 print "run_synaptic() called with unknown action"
59 return False
60 lock.release()
61
62 def _perform_action(self, action, cache=None):
63 lock = thread.allocate_lock()
64 lock.acquire()
65 t = thread.start_new_thread(self._run_synaptic,
66 (self.window_main.window.xid,
67 lock, cache, action))
68 while lock.locked():
69 while gtk.events_pending():
70 gtk.main_iteration()
71 time.sleep(0.05)
72 return self.return_code
73
74 def update(self):43 def update(self):
75 return self._perform_action(self.UPDATE)44 opt = ["--update-at-startup"]
7645 tempf = None
77 def commit(self, cache):46 self._run_synaptic(self.UPDATE, opt, tempf)
78 return self._perform_action(self.INSTALL, cache)47
7948 def commit(self, pkgs_install, pkgs_upgrade, close_on_done):
8049 # close when update was successful (its ok to use a Synaptic::
8150 # option here, it will not get auto-saved, because synaptic does
51 # not save options in non-interactive mode)
52 opt = []
53 if close_on_done:
54 opt.append("-o")
55 opt.append("Synaptic::closeZvt=true")
56 # custom progress strings
57 opt.append("--progress-str")
58 opt.append("%s" % _("Please wait, this can take some time."))
59 opt.append("--finish-str")
60 opt.append("%s" % _("Update is complete"))
61 tempf = tempfile.NamedTemporaryFile()
62 for pkg_name in pkgs_install + pkgs_upgrade:
63 tempf.write("%s\tinstall\n" % pkg_name)
64 opt.append("--set-selections-file")
65 opt.append("%s" % tempf.name)
66 tempf.flush()
67 self._run_synaptic(self.INSTALL, opt, tempf)

Subscribers

People subscribed via source and target branches

to status/vote changes: