Package: gnome-codec-install
Version: 0.4.5
Severity: wishlist
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu maverick ubuntu-patch


Hi,

In Ubuntu, we've applied the attached patch to achieve the following:

  * GnomeCodecInstall/PackageWorker.py:
    - add aptdaemon backend (and use that by default)
  * debian/control:
    - add (or) dependency to python-aptdaemon-gtk

We thought you might be interested in doing the same. 

Cheers,
 Michael

-- System Information:
Debian Release: squeeze/sid
  APT prefers maverick-updates
  APT policy: (500, 'maverick-updates'), (500, 'maverick-proposed'), (500, 
'maverick')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.34-4-generic (SMP w/2 CPU cores)
Locale: LANG=en_DK.utf8, LC_CTYPE=en_DK.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -Nru gnome-codec-install-0.4.5ubuntu1/debian/changelog gnome-codec-install-0.4.5ubuntu2/debian/changelog
diff -Nru gnome-codec-install-0.4.5ubuntu1/debian/control gnome-codec-install-0.4.5ubuntu2/debian/control
--- gnome-codec-install-0.4.5ubuntu1/debian/control	2010-06-01 10:57:38.000000000 +0200
+++ gnome-codec-install-0.4.5ubuntu2/debian/control	2010-06-01 13:20:02.000000000 +0200
@@ -25,7 +25,7 @@
          python-apt (>= 0.7.93.2),
          python-gst0.10,
          python-gtk2 (>= 2.10.1),
-         synaptic (>= 0.57.8)
+	 python-aptdaemon-gtk | synaptic (>= 0.57.8)
 Replaces: gnome-app-install (<= 0.5.5.1-1)
 XB-Python-Version: ${python:Versions}
 Description: GStreamer codec installer
diff -Nru gnome-codec-install-0.4.5ubuntu1/GnomeCodecInstall/MainWindow.py gnome-codec-install-0.4.5ubuntu2/GnomeCodecInstall/MainWindow.py
--- gnome-codec-install-0.4.5ubuntu1/GnomeCodecInstall/MainWindow.py	2010-06-01 10:57:38.000000000 +0200
+++ gnome-codec-install-0.4.5ubuntu2/GnomeCodecInstall/MainWindow.py	2010-06-01 13:20:02.000000000 +0200
@@ -13,6 +13,7 @@
 import os
 import PackageWorker
 
+
 # the list columns
 (LIST_PKG_TO_INSTALL,
  LIST_PKG_NAME,
@@ -403,7 +404,7 @@
     if not self._confirm_codec_install(set([package[LIST_PKG_TO_INSTALL] for package in packages])):
       return
 
-    worker = PackageWorker.PackageWorker()
+    worker = PackageWorker.get_worker()
     install_success = worker.perform_action(self._window, set([package[LIST_PKG_TO_INSTALL] for package in packages]), set())
 
     if install_success:
@@ -468,7 +469,7 @@
     if npackages == 0:
       if self._apt_lists_dir_has_missing_files():
         if self._ask_perform_update():
-          worker = PackageWorker.PackageWorker()
+          worker = PackageWorker.get_worker()
           worker.perform_update(self._window)
           npackages = self._populate_list()
           if npackages == 0:
diff -Nru gnome-codec-install-0.4.5ubuntu1/GnomeCodecInstall/PackageWorker.py gnome-codec-install-0.4.5ubuntu2/GnomeCodecInstall/PackageWorker.py
--- gnome-codec-install-0.4.5ubuntu1/GnomeCodecInstall/PackageWorker.py	2010-06-01 10:57:38.000000000 +0200
+++ gnome-codec-install-0.4.5ubuntu2/GnomeCodecInstall/PackageWorker.py	2010-06-01 13:20:02.000000000 +0200
@@ -11,6 +11,13 @@
 import tempfile
 from gettext import gettext as _
 
+try:
+  from aptdaemon import client, errors
+  from aptdaemon.defer import inline_callbacks
+  from aptdaemon.gtkwidgets import AptProgressDialog
+except ImportError:
+  pass
+
 class GtkOpProgress(apt.progress.base.OpProgress):
   " a simple helper that keeps the GUI alive "
 
@@ -18,8 +25,53 @@
     while gtk.events_pending():
       gtk.main_iteration()
 
-
 class PackageWorker(object):
+  """ base class """
+  def perform_action(self, window_main, to_add=None, to_rm=None):
+    raise NotImplemented
+  def perform_update(self, window_main):
+    raise NotImplemented
+
+class PackageWorkerAptdaemon(PackageWorker):
+
+  def __init__(self):
+    self.client = client.AptClient()
+    self._result = None
+
+  def perform_action(self, parent_window, install, remove):
+    self._perform_action(parent_window, install, remove)
+    return self._result
+
+  @inline_callbacks
+  def _perform_action(self, parent_window, install, remove):
+    """Commit a list of package adds and removes"""
+    trans = yield self.client.commit_packages(
+      list(install), [], list(remove), [], [], defer=True)
+    self._run_in_dialog(trans, parent_window)
+
+  def perform_update(self, parent_window):
+    return self._perform_update()
+
+  @inline_callbacks
+  def _perform_update(self, parent_window=None):
+    trans = yield self.client.update_cache(defer=True)
+    self._run_in_dialog(trans, parent_window)
+
+  def _run_in_dialog(self, trans, parent_window):
+    dia = AptProgressDialog(trans, parent=parent_window)
+    dia.connect("finished", self._on_finished)
+    dia.run()
+    while self._result is None:
+      while gtk.events_pending():
+        gtk.main_iteration()
+      time.sleep(0.01)
+
+  def _on_finished(self, dialog):
+    dialog.hide()
+    self._result = True
+
+
+class PackageWorkerSynaptic(PackageWorker):
     """
     A class which does the actual package installing/removing.
     """
@@ -109,3 +161,19 @@
         if window_main.window:
           window_main.window.set_cursor(None)
         return result
+
+
+def get_worker():
+  if (os.path.exists("/usr/sbin/aptd") and
+      not "CODEC_INSTALLER_FORCE_BACKEND_SYNAPTIC" in os.environ):
+    return PackageWorkerAptdaemon()
+  if os.path.exists("/usr/sbin/synaptic"):
+    return PackageWorkerSynaptic()
+
+if __name__ == "__main__":
+  worker = get_worker()
+  print worker
+  res = worker.perform_update()
+  print res
+  res = worker.perform_action(None, ["2vcard"], [])
+  print res

Reply via email to