[debian-edu-commits] r78777 - in trunk/src/hw-support-handler: . debian

pere at alioth.debian.org pere at alioth.debian.org
Thu Jan 17 21:47:06 UTC 2013


Author: pere
Date: 2013-01-17 21:47:06 +0000 (Thu, 17 Jan 2013)
New Revision: 78777

Modified:
   trunk/src/hw-support-handler/debian/control
   trunk/src/hw-support-handler/hw-support-handlerd
Log:
Get installation working using aptdaemon/PackageKit API.

Modified: trunk/src/hw-support-handler/debian/control
===================================================================
--- trunk/src/hw-support-handler/debian/control	2013-01-17 17:32:48 UTC (rev 78776)
+++ trunk/src/hw-support-handler/debian/control	2013-01-17 21:47:06 UTC (rev 78777)
@@ -21,6 +21,9 @@
   , python-dbus
   , python-gobject
   , python-notify
+  , aptdaemon
+  , python-aptdaemon-gtk
+  , libgnome2-perl
 Description: Suggest packages to install when inserting new hardware
  Try to figure out what packages are need freshly inserted hardware
  dongle.

Modified: trunk/src/hw-support-handler/hw-support-handlerd
===================================================================
--- trunk/src/hw-support-handler/hw-support-handlerd	2013-01-17 17:32:48 UTC (rev 78776)
+++ trunk/src/hw-support-handler/hw-support-handlerd	2013-01-17 21:47:06 UTC (rev 78777)
@@ -1,20 +1,129 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+Provides a graphical demo application for aptdaemon
+"""
+# Copyright (C) 2013 Petter Reinholdtsen <pere at hungry.com>
+# AptDaemon gtk client code based on gtk-demo, copyright (C) 2008-2009
+# Sebastian Heinlein <sevel at glatzor.de>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+__author__ = "Petter Reinholdtsen <pere at hungry.com>"
+
 import string
 import dbus
 from dbus.mainloop.glib import DBusGMainLoop
 #import pygtk
-#import gtk
+import gtk
 import gobject
 import pynotify
 import subprocess
 import glob
 import fnmatch
 import hwsupport.lookup
+from aptdaemon.gtkwidgets import AptErrorDialog, \
+                                 AptConfirmDialog, \
+                                 AptProgressDialog
+import aptdaemon.errors
 
 hw_seen = {}
 pkg_suggested = {}
 
+class AptDaemonDemo:
+
+    """Provides a graphical test application."""
+
+    def _run_transaction(self, transaction):
+        dia = AptProgressDialog(transaction, parent=self.win)
+        dia.run(close_on_finished=True, show_error=True,
+                reply_handler=lambda: True,
+                error_handler=self._on_error)
+
+    def _simulate_trans(self, trans):
+        trans.simulate(reply_handler=lambda: self._confirm_deps(trans),
+                       error_handler=self._on_error)
+
+    def _confirm_deps(self, trans):
+        if [pkgs for pkgs in trans.dependencies if pkgs]:
+            dia = AptConfirmDialog(trans, parent=self.win)
+            res = dia.run()
+            dia.hide()
+            if res != gtk.RESPONSE_OK:
+                return
+        self._run_transaction(trans)
+
+    def _on_error(self, error):
+        try:
+            raise error
+        except aptdaemon.errors.NotAuthorizedError:
+            # Silently ignore auth failures
+            return
+        except aptdaemon.errors.TransactionFailed, error:
+            pass
+        except Exception, error:
+            error = aptdaemon.errors.TransactionFailed(ERROR_UNKNOWN,
+                                                       str(error))
+        dia = AptErrorDialog(error)
+        dia.run()
+        dia.hide()
+
+    def _on_upgrade_clicked(self, *args):
+        self.ac.upgrade_system(reply_handler=self._simulate_trans,
+                               error_handler=self._on_error)
+
+    def _on_update_clicked(self, *args):
+        self.ac.update_cache(reply_handler=self._run_transaction,
+                             error_handler=self._on_error)
+
+    def _on_install_clicked(self, *args):
+        self.ac.install_packages([self.package],
+                                 reply_handler=self._simulate_trans,
+                                 error_handler=self._on_error)
+
+    def _on_install_file_clicked(self, *args):
+        chooser = gtk.FileChooserDialog(parent=self.win,
+                                        action=gtk.FILE_CHOOSER_ACTION_OPEN,
+                                        buttons=(gtk.STOCK_CANCEL,
+                                                 gtk.RESPONSE_CANCEL,
+                                                 gtk.STOCK_OPEN,
+                                                 gtk.RESPONSE_OK))
+        chooser.set_local_only(True)
+        chooser.run()
+        chooser.hide()
+        path = chooser.get_filename()
+        self.ac.install_file(path, reply_handler=self._simulate_trans,
+                             error_handler=self._on_error)
+
+    def _on_remove_clicked(self, *args):
+        self.ac.remove_packages([self.package],
+                                reply_handler=self._simulate_trans,
+                                error_handler=self._on_error)
+
+    def __init__(self, package):
+        self.win = None
+        self.package = package
+        self.loop = gobject.MainLoop()
+        self.ac = aptdaemon.client.AptClient()
+
+    def run(self):
+        self.loop.run()
+
+
 # Keep refs needed for callback to work
 n = None
 npkgs = None
@@ -23,20 +132,20 @@
     pkgs = data
     pkgsstr = string.join(pkgs, " ")
 #    print pkgs
-    print "info: button clicked, should call \"apt-get install %s\"" % pkgsstr
+    print "info: button clicked, installing %s" % pkgsstr
+    demo = AptDaemonDemo(pkgs[0])
+    demo._on_install_clicked()
 
 def notify(bus, vendor, device, pkgs):
     pkgstr = string.join(pkgs, " ")
-    info = "New %s device [%04x:%04x] supported by package(s) %s." \
+    text = "New %s device [%04x:%04x] supported by package(s) %s." \
         % (bus, vendor, device, pkgstr)
-    instructions = "To install, run \"apt-get install %s\" as user root." % pkgstr
     title = "New %s device" % bus
-    text = info + "  " + instructions
 
-    print "info: " + info
+    print "info: " + text
 
     # Initializite pynotify
-    if not pynotify.init("test"):
+    if not pynotify.init("hw-support-handlerd"):
         return False
     global n
     global npkgs
@@ -109,7 +218,7 @@
     return hwsupport.lookup.pkgs_handling_apt_modaliases([modalias])
 
 def get_pkg_suggestions_mymodaliases(bus, vendor, device):
-    print "info: checking my modaliases file"
+    print "info: checking my modaliases file (from svn)"
     modalias = devid2modalias(bus, vendor, device)
 
     if modalias is None:




More information about the debian-edu-commits mailing list