Back to index

system-config-printer  1.3.9+20120706
installdriver.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## system-config-printer
00004 
00005 ## Copyright (C) 2010 Red Hat, Inc.
00006 ## Author: Tim Waugh <twaugh@redhat.com>
00007 
00008 ## This program is free software; you can redistribute it and/or modify
00009 ## it under the terms of the GNU General Public License as published by
00010 ## the Free Software Foundation; either version 2 of the License, or
00011 ## (at your option) any later version.
00012 
00013 ## This program is distributed in the hope that it will be useful,
00014 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ## GNU General Public License for more details.
00017 
00018 ## You should have received a copy of the GNU General Public License
00019 ## along with this program; if not, write to the Free Software
00020 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 
00022 import dbus
00023 import dbus.glib
00024 import dbus.service
00025 from . import _debugprint, set_debugprint_fn
00026 
00027 class PrinterDriversInstaller(dbus.service.Object):
00028     DBUS_PATH  = "/com/redhat/PrinterDriversInstaller"
00029     DBUS_IFACE = "com.redhat.PrinterDriversInstaller"
00030     DBUS_OBJ   = "com.redhat.PrinterDriversInstaller"
00031 
00032     def __init__ (self, bus):
00033         self.bus = bus
00034         bus_name = dbus.service.BusName (self.DBUS_OBJ, bus=bus)
00035         dbus.service.Object.__init__ (self, bus_name, self.DBUS_PATH)
00036 
00037     @dbus.service.method(DBUS_IFACE,
00038                          in_signature="sss",
00039                          async_callbacks=("reply_handler",
00040                                           "error_handler"))
00041     def InstallDrivers (self, mfg, mdl, cmd,
00042                        reply_handler, error_handler):
00043         bus = dbus.SessionBus ()
00044         obj = bus.get_object ("org.freedesktop.PackageKit",
00045                               "/org/freedesktop/PackageKit")
00046         proxy = dbus.Interface (obj, "org.freedesktop.PackageKit.Modify")
00047         xid = 0
00048         resources = ["MFG:%s;MDL:%s;" % (mfg, mdl)]
00049         interaction = "hide-finished"
00050         _debugprint ("Calling InstallPrinterDrivers (%s, %s, %s)" %
00051                      (repr (xid), repr (resources), repr (interaction)))
00052         proxy.InstallPrinterDrivers (dbus.UInt32 (xid),
00053                                      resources, interaction,
00054                                      reply_handler=reply_handler,
00055                                      error_handler=error_handler,
00056                                      timeout=3600)
00057 
00058 def client_test():
00059     bus = dbus.SystemBus ()
00060     import sys
00061     obj = bus.get_object (PrinterDriversInstaller.DBUS_OBJ,
00062                           PrinterDriversInstaller.DBUS_PATH)
00063     proxy = dbus.Interface (obj, PrinterDriversInstaller.DBUS_IFACE)
00064     print proxy.InstallDrivers ("MFG", "MDL", "CMD")