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


I ran accross a issue on a install when the package list information
was only partly there, the attached patch adds a check for this.

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

  * GnomeCodecInstall/MainWindow.py:
    - if no codecs are found, check if the apt package lists
      are complete and if not ask if the user wants to perform
      a update and redo the search (LP: #510033)

We thought you might be interested in doing the same. 

Thanks,
 Michael

-- System Information:
Debian Release: squeeze/sid
  APT prefers karmic-updates
  APT policy: (500, 'karmic-updates'), (500, 'karmic-security'), (500, 
'karmic-proposed'), (500, 'karmic-backports'), (500, 'karmic')
Architecture: i386 (i686)

Kernel: Linux 2.6.31-15-generic (SMP w/2 CPU cores)
Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -Nru gnome-codec-install-0.4.2ubuntu1/debian/changelog gnome-codec-install-0.4.2ubuntu2/debian/changelog
diff -Nru gnome-codec-install-0.4.2ubuntu1/GnomeCodecInstall/MainWindow.py gnome-codec-install-0.4.2ubuntu2/GnomeCodecInstall/MainWindow.py
--- gnome-codec-install-0.4.2ubuntu1/GnomeCodecInstall/MainWindow.py	2010-01-21 12:02:51.000000000 +0100
+++ gnome-codec-install-0.4.2ubuntu2/GnomeCodecInstall/MainWindow.py	2010-01-21 12:05:32.000000000 +0100
@@ -9,6 +9,8 @@
 import gst
 import gst.pbutils
 import apt
+import apt_pkg
+import os
 import PackageWorker
 
 # the list columns
@@ -421,16 +423,56 @@
       self._return_code = gst.pbutils.INSTALL_PLUGINS_ERROR
     gtk.main_quit()
 
+  def _apt_lists_dir_has_missing_files(self):
+    """ check if sources.list contains entries that are not in
+        /var/lib/apt/lists - this can happen if the lists/ dir
+        is not fresh
+
+        Returns True if there is a file missing
+    """
+    for metaindex in self.cache._list.List:
+      for m in metaindex.IndexFiles:
+        if m.Label == "Debian Package Index" and not m.Exists:
+          print "Missing package list: ", m
+          return True
+    return False
+          
+  def _ask_perform_update(self):
+    dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
+                            gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
+                            _("Update package list?"))
+    dlg.format_secondary_text(_("The package information is incomplete "
+                                "and needs to be updated."))
+    btn = dlg.add_button(_("_Update"), gtk.RESPONSE_YES)
+    btn.grab_focus()
+    dlg.set_title("")
+    dlg.set_transient_for(self._window)
+    res = dlg.run()
+    dlg.destroy()
+    return res == gtk.RESPONSE_YES
+
+  def _show_no_codecs_error(self):
+    plugins = ""
+    for request in self._requests:
+      plugins += "\n" + request.description
+    self.modal_dialog(gtk.MESSAGE_WARNING,
+                      _("No packages with the requested plugins found"),
+                      _("The requested plugins are:\n") + plugins)
+
   def main(self):
     npackages = self._populate_list()
     if npackages == 0:
-      plugins = ""
-      for request in self._requests:
-        plugins += "\n" + request.description
-      self.modal_dialog(gtk.MESSAGE_WARNING,
-                        _("No packages with the requested plugins found"),
-                        _("The requested plugins are:\n") + plugins)
-      return gst.pbutils.INSTALL_PLUGINS_NOT_FOUND
+      if self._apt_lists_dir_has_missing_files():
+        if self._ask_perform_update():
+          worker = PackageWorker.PackageWorker()
+          worker.perform_update(self._window)
+          npackages = self._populate_list()
+          if npackages == 0:
+            self._show_no_codecs_error()
+            return gst.pbutils.INSTALL_PLUGINS_NOT_FOUND
+      else:
+        self._show_no_codecs_error()
+        return gst.pbutils.INSTALL_PLUGINS_NOT_FOUND
     gtk.main()
     return self._return_code
 
diff -Nru gnome-codec-install-0.4.2ubuntu1/GnomeCodecInstall/PackageWorker.py gnome-codec-install-0.4.2ubuntu2/GnomeCodecInstall/PackageWorker.py
--- gnome-codec-install-0.4.2ubuntu1/GnomeCodecInstall/PackageWorker.py	2010-01-21 12:02:51.000000000 +0100
+++ gnome-codec-install-0.4.2ubuntu2/GnomeCodecInstall/PackageWorker.py	2010-01-21 12:05:32.000000000 +0100
@@ -59,7 +59,21 @@
         lock.release()
         f.close()
 
-   
+    def perform_update(self, window_main):
+        window_main.set_sensitive(False)
+        if window_main.window:
+          window_main.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+        lock = thread.allocate_lock()
+        lock.acquire()
+        t = thread.start_new_thread(self.run_synaptic,(window_main.window.xid,lock, [], [], self.UPDATE))
+        while lock.locked():
+            while gtk.events_pending():
+                gtk.main_iteration()
+            time.sleep(0.05)
+        window_main.set_sensitive(True)
+        if window_main.window:
+          window_main.window.set_cursor(None)
+
     def perform_action(self, window_main, to_add=None, to_rm=None):
         """ 
         install/remove the given set of packages 

Reply via email to