Back to index

system-config-printer  1.3.9+20120706
cupspk.py
Go to the documentation of this file.
00001 # vim: set ts=4 sw=4 et: coding=UTF-8
00002 #
00003 # Copyright (C) 2008 Novell, Inc.
00004 # Copyright (C) 2008, 2009, 2010 Red Hat, Inc.
00005 # Copyright (C) 2008, 2009, 2010 Tim Waugh <twaugh@redhat.com>
00006 #
00007 # Authors: Vincent Untz
00008 #
00009 # This program is free software; you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation; either version 2 of the License, or
00012 # (at your option) any later version.
00013 #
00014 # This program is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 #
00019 # You should have received a copy of the GNU General Public License
00020 # along with this program; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022 #
00023 
00024 # check FIXME/TODO here
00025 # check FIXME/TODO in cups-pk-helper
00026 # define fine-grained policy (more than one level of permission)
00027 # add missing methods
00028 
00029 import os
00030 import sys
00031 
00032 import tempfile
00033 
00034 import cups
00035 import dbus
00036 import gtk
00037 from debug import debugprint
00038 
00039 from dbus.mainloop.glib import DBusGMainLoop
00040 DBusGMainLoop(set_as_default=True)
00041 
00042 CUPS_PK_NAME  = 'org.opensuse.CupsPkHelper.Mechanism'
00043 CUPS_PK_PATH  = '/'
00044 CUPS_PK_IFACE = 'org.opensuse.CupsPkHelper.Mechanism'
00045 
00046 CUPS_PK_NEED_AUTH = 'org.opensuse.CupsPkHelper.Mechanism.NotPrivileged'
00047 
00048 
00049 # we can't subclass cups.Connection, even when adding
00050 # Py_TPFLAGS_BASETYPE to cupsconnection.c
00051 # So we'll hack this...
00052 class Connection:
00053     def __init__(self, host, port, encryption):
00054         self._parent = None
00055 
00056         try:
00057             self._session_bus = dbus.SessionBus()
00058             self._system_bus = dbus.SystemBus()
00059         except dbus.exceptions.DBusException:
00060             # One or other bus not running.
00061             self._session_bus = self._system_bus = None
00062 
00063         self._connection = cups.Connection(host=host,
00064                                            port=port,
00065                                            encryption=encryption)
00066 
00067         self._hack_subclass()
00068 
00069 
00070     def _hack_subclass(self):
00071         # here's how to subclass without really subclassing. Just provide
00072         # the same methods
00073         methodtype = type(self._connection.getPrinters)
00074         for fname in dir(self._connection):
00075             if fname[0] == '_':
00076                 continue
00077             fn = getattr(self._connection, fname)
00078             if type(fn) != methodtype:
00079                 continue
00080             if not hasattr(self, fname):
00081                 setattr(self, fname, fn.__call__)
00082 
00083 
00084     def set_parent(self, parent):
00085         self._parent = parent
00086 
00087 
00088     def _get_cups_pk(self):
00089         try:
00090             object = self._system_bus.get_object(CUPS_PK_NAME, CUPS_PK_PATH)
00091             return dbus.Interface(object, CUPS_PK_IFACE)
00092         except dbus.exceptions.DBusException:
00093             # Failed to get object or interface.
00094             return None
00095         except AttributeError:
00096             # No system D-Bus
00097             return None
00098 
00099 
00100     def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fallback_function, *args, **kwds):
00101         pk_function = None
00102 
00103         if not use_fallback:
00104             cups_pk = self._get_cups_pk()
00105             if cups_pk:
00106                 try:
00107                     pk_function = cups_pk.get_dbus_method(pk_function_name)
00108                 except dbus.exceptions.DBusException:
00109                     pass
00110 
00111         if use_fallback or not pk_function:
00112             return fallback_function(*args, **kwds)
00113 
00114         pk_retval = 'PolicyKit communication issue'
00115 
00116         while True:
00117             try:
00118                 # FIXME: async call or not?
00119                 pk_retval = pk_function(*pk_args)
00120 
00121                 # if the PK call has more than one return values, we pop the
00122                 # first one as the error message
00123                 if type(pk_retval) == tuple:
00124                     retval = pk_retval[1:]
00125                     # if there's no error, then we can safely return what we
00126                     # got
00127                     if pk_retval[0] == '':
00128                         # if there's only one item left in the tuple, we don't
00129                         # want to return the tuple, but the item
00130                         if len(retval) == 1:
00131                             return retval[0]
00132                         else:
00133                             return retval
00134                 break
00135             except dbus.exceptions.DBusException, e:
00136                 if e.get_dbus_name() == CUPS_PK_NEED_AUTH:
00137                     raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, 'pkcancel')
00138 
00139                 break
00140 
00141         # The PolicyKit call did not work (either a PK-error and we got a dbus
00142         # exception that wasn't handled, or an error in the mechanism itself)
00143         if pk_retval != '':
00144             debugprint ('PolicyKit call to %s did not work: %s' %
00145                         (pk_function_name, pk_retval))
00146             return fallback_function(*args, **kwds)
00147 
00148 
00149     def _args_to_tuple(self, types, *args):
00150         retval = [ False ]
00151 
00152         if len(types) != len(args):
00153             retval[0] = True
00154             # We do this to have the right length for the returned value
00155             retval.extend(types)
00156             return tuple(types)
00157 
00158         exception = False
00159 
00160         for i in range(len(types)):
00161             if type(args[i]) != types[i]:
00162                 if types[i] == str and type(args[i]) == unicode:
00163                     # we accept a mix between unicode and str
00164                     pass
00165                 elif types[i] == str and type(args[i]) == int:
00166                     # we accept a mix between int and str
00167                     retval.append(str(args[i]))
00168                     continue
00169                 elif types[i] == str and type(args[i]) == float:
00170                     # we accept a mix between float and str
00171                     retval.append(str(args[i]))
00172                     continue
00173                 elif types[i] == str and type(args[i]) == bool:
00174                     # we accept a mix between bool and str
00175                     retval.append(str(args[i]))
00176                     continue
00177                 elif types[i] == str and args[i] == None:
00178                     # None is an empty string for dbus
00179                     retval.append('')
00180                     continue
00181                 elif types[i] == list and type(args[i]) == tuple:
00182                     # we accept a mix between list and tuple
00183                     retval.append(list(args[i]))
00184                     continue
00185                 elif types[i] == list and args[i] == None:
00186                     # None is an empty list
00187                     retval.append([])
00188                     continue
00189                 else:
00190                     exception = True
00191             retval.append(args[i])
00192 
00193         retval[0] = exception
00194 
00195         return tuple(retval)
00196 
00197 
00198     def _kwds_to_vars(self, names, **kwds):
00199         ret = []
00200 
00201         for name in names:
00202             if kwds.has_key(name):
00203                 ret.append(kwds[name])
00204             else:
00205                 ret.append('')
00206 
00207         return tuple(ret)
00208 
00209 
00210 #    getPrinters
00211 #    getDests
00212 #    getClasses
00213 #    getPPDs
00214 #    getServerPPD
00215 #    getDocument
00216 
00217 
00218     def getDevices(self, *args, **kwds):
00219         use_pycups = False
00220 
00221         limit = 0
00222         include_schemes = []
00223         exclude_schemes = []
00224         timeout = 0
00225 
00226         if len(args) == 4:
00227             (use_pycups, limit, include_schemes, exclude_schemes, timeout) = self._args_to_tuple([int, str, str, int], *args)
00228         else:
00229             if kwds.has_key('timeout'):
00230                 timeout = kwds['timeout']
00231 
00232             if kwds.has_key('limit'):
00233                 limit = kwds['limit']
00234 
00235             if kwds.has_key('include_schemes'):
00236                 include_schemes = kwds['include_schemes']
00237 
00238             if kwds.has_key('exclude_schemes'):
00239                 exclude_schemes = kwds['exclude_schemes']
00240 
00241         pk_args = (timeout, limit, include_schemes, exclude_schemes)
00242 
00243         try:
00244             result = self._call_with_pk_and_fallback(use_pycups,
00245                                                      'DevicesGet', pk_args,
00246                                                      self._connection.getDevices,
00247                                                      *args, **kwds)
00248         except TypeError:
00249             debugprint ("DevicesGet API exception; using old signature")
00250             if kwds.has_key ('timeout'):
00251                 use_pycups = True
00252 
00253             # Convert from list to string
00254             if len (include_schemes) > 0:
00255                 include_schemes = reduce (lambda x, y: x + "," + y,
00256                                           include_schemes)
00257             else:
00258                 include_schemes = ""
00259 
00260             if len (exclude_schemes) > 0:
00261                 exclude_schemes = reduce (lambda x, y: x + "," + y,
00262                                           exclude_schemes)
00263             else:
00264                 exclude_schemes = ""
00265 
00266             pk_args = (limit, include_schemes, exclude_schemes)
00267             result = self._call_with_pk_and_fallback(use_pycups,
00268                                                      'DevicesGet', pk_args,
00269                                                      self._connection.getDevices,
00270                                                      *args, **kwds)
00271 
00272         # return 'result' if fallback was called
00273         if len (result.keys()) > 0 and type (result[result.keys()[0]]) == dict:
00274              return result
00275 
00276         result_str = {}
00277         if result != None:
00278             for i in result.keys():
00279                 if type(i) == dbus.String:
00280                     result_str[str(i)] = str(result[i])
00281                 else:
00282                     result_str[i] = result[i]
00283 
00284         # cups-pk-helper returns all devices in one dictionary.
00285         # Keys of different devices are distinguished by ':n' postfix.
00286 
00287         devices = {}
00288         n = 0
00289         postfix = ':' + str (n)
00290         device_keys = [x for x in result_str.keys() if x.endswith(postfix)]
00291         while len (device_keys) > 0:
00292 
00293             device_uri = None
00294             device_dict = {}
00295             for i in device_keys:
00296                 key = i[:len(i) - len(postfix)]
00297                 if key != 'device-uri':
00298                     device_dict[key] = result_str[i]
00299                 else:
00300                     device_uri = result_str[i]
00301 
00302             if device_uri != None:
00303                 devices[device_uri] = device_dict
00304 
00305             n += 1
00306             postfix = ':' + str (n)
00307             device_keys = [x for x in result_str.keys() if x.endswith(postfix)]
00308 
00309         return devices
00310 
00311 
00312 #    getJobs
00313 #    getJobAttributes
00314 
00315     def cancelJob(self, *args, **kwds):
00316         (use_pycups, jobid) = self._args_to_tuple([int], *args)
00317         pk_args = (jobid, )
00318 
00319         self._call_with_pk_and_fallback(use_pycups,
00320                                         'JobCancel', pk_args,
00321                                         self._connection.cancelJob,
00322                                         *args, **kwds)
00323 
00324 
00325 #    cancelAllJobs
00326 #    authenticateJob
00327     def setJobHoldUntil(self, *args, **kwds):
00328         (use_pycups, jobid, job_hold_until) = self._args_to_tuple([int, str], *args)
00329         pk_args = (jobid, job_hold_until, )
00330 
00331         self._call_with_pk_and_fallback(use_pycups,
00332                                         'JobSetHoldUntil', pk_args,
00333                                         self._connection.setJobHoldUntil,
00334                                         *args, **kwds)
00335 
00336     def restartJob(self, *args, **kwds):
00337         (use_pycups, jobid) = self._args_to_tuple([int], *args)
00338         pk_args = (jobid, )
00339         
00340         self._call_with_pk_and_fallback(use_pycups,
00341                                         'JobRestart', pk_args,
00342                                         self._connection.restartJob,
00343                                         *args, **kwds)
00344 
00345     def getFile(self, *args, **kwds):
00346         ''' Keeping this as an alternative for the code.
00347             We don't use it because it's not possible to know if the call was a
00348             PK-one (and so we push the content of a temporary filename to fd or
00349             file) or a non-PK-one (in which case nothing should be done).
00350 
00351                 filename = None
00352                 fd = None
00353                 file = None
00354                 if use_pycups:
00355                     if len(kwds) != 1:
00356                         use_pycups = True
00357                     elif kwds.has_key('filename'):
00358                         filename = kwds['filename']
00359                     elif kwds.has_key('fd'):
00360                         fd = kwds['fd']
00361                     elif kwds.has_key('file'):
00362                         file = kwds['file']
00363                     else:
00364                         use_pycups = True
00365 
00366                     if fd or file:
00367         '''
00368 
00369         file_object = None
00370         fd = None
00371         if len(args) == 2:
00372             (use_pycups, resource, filename) = self._args_to_tuple([str, str], *args)
00373         else:
00374             (use_pycups, resource) = self._args_to_tuple([str], *args)
00375             if kwds.has_key('filename'):
00376                 filename = kwds['filename']
00377             elif kwds.has_key('fd'):
00378                 fd = kwds['fd']
00379             elif kwds.has_key('file'):
00380                 file_object = kwds['file']
00381             else:
00382                 if not use_pycups:
00383                     raise TypeError()
00384                 else:
00385                     filename = None
00386 
00387         if (not use_pycups) and (fd != None or file_object != None):
00388             # Create the temporary file in /tmp to ensure that
00389             # cups-pk-helper-mechanism is able to write to it.
00390             (tmpfd, tmpfname) = tempfile.mkstemp(dir="/tmp")
00391             os.close (tmpfd)
00392 
00393             pk_args = (resource, tmpfname)
00394             self._call_with_pk_and_fallback(use_pycups,
00395                                             'FileGet', pk_args,
00396                                             self._connection.getFile,
00397                                             *args, **kwds)
00398 
00399             tmpfd = os.open (tmpfname, os.O_RDONLY)
00400             tmpfile = os.fdopen (tmpfd, 'r')
00401             tmpfile.seek (0)
00402 
00403             if fd != None:
00404                 os.lseek (fd, 0, os.SEEK_SET)
00405                 line = tmpfile.readline()
00406                 while line != '':
00407                     os.write (fd, line)
00408                     line = tmpfile.readline()
00409             else:
00410                 file_object.seek (0)
00411                 line = tmpfile.readline()
00412                 while line != '':
00413                     file_object.write (line)
00414                     line = tmpfile.readline()
00415 
00416             tmpfile.close ()
00417             os.remove (tmpfname)
00418         else:
00419             pk_args = (resource, filename)
00420 
00421             self._call_with_pk_and_fallback(use_pycups,
00422                                             'FileGet', pk_args,
00423                                             self._connection.getFile,
00424                                             *args, **kwds)
00425 
00426 
00427     def putFile(self, *args, **kwds):
00428         if len(args) == 2:
00429             (use_pycups, resource, filename) = self._args_to_tuple([str, str], *args)
00430         else:
00431             (use_pycups, resource) = self._args_to_tuple([str], *args)
00432             if kwds.has_key('filename'):
00433                 filename = kwds['filename']
00434             elif kwds.has_key('fd'):
00435                 fd = kwds['fd']
00436             elif kwds.has_key('file'):
00437                 file_object = kwds['file']
00438             else:
00439                 if not use_pycups:
00440                     raise TypeError()
00441                 else:
00442                     filename = None
00443 
00444         if (not use_pycups) and (fd != None or file_object != None):
00445             (tmpfd, tmpfname) = tempfile.mkstemp()
00446             os.lseek (tmpfd, 0, os.SEEK_SET)
00447 
00448             if fd != None:
00449                 os.lseek (fd, 0, os.SEEK_SET)
00450                 buf = os.read (fd, 512)
00451                 while buf != '':
00452                     os.write (tmpfd, buf)
00453                     buf = os.read (fd, 512)
00454             else:
00455                 file_object.seek (0)
00456                 line = file_object.readline ()
00457                 while line != '':
00458                     os.write (tmpfd, line)
00459                     line = file_object.readline ()
00460 
00461             os.close (tmpfd)
00462 
00463             pk_args = (resource, tmpfname)
00464 
00465             self._call_with_pk_and_fallback(use_pycups,
00466                                             'FilePut', pk_args,
00467                                             self._connection.putFile,
00468                                             *args, **kwds)
00469 
00470             os.remove (tmpfname)
00471         else:
00472 
00473             pk_args = (resource, filename)
00474 
00475             self._call_with_pk_and_fallback(use_pycups,
00476                                             'FilePut', pk_args,
00477                                             self._connection.putFile,
00478                                             *args, **kwds)
00479 
00480 
00481     def addPrinter(self, *args, **kwds):
00482         (use_pycups, name) = self._args_to_tuple([str], *args)
00483         (filename, ppdname, info, location, device, ppd) = self._kwds_to_vars(['filename', 'ppdname', 'info', 'location', 'device', 'ppd'], **kwds)
00484 
00485         need_unlink = False
00486         if not ppdname and not filename and ppd:
00487             (fd, filename) = tempfile.mkstemp ()
00488             ppd.writeFd(fd)
00489             os.close(fd)
00490             need_unlink = True
00491 
00492         if filename and not ppdname:
00493             pk_args = (name, device, filename, info, location)
00494             self._call_with_pk_and_fallback(use_pycups,
00495                                             'PrinterAddWithPpdFile', pk_args,
00496                                             self._connection.addPrinter,
00497                                             *args, **kwds)
00498             if need_unlink:
00499                 os.unlink(filename)
00500         else:
00501             pk_args = (name, device, ppdname, info, location)
00502             self._call_with_pk_and_fallback(use_pycups,
00503                                             'PrinterAdd', pk_args,
00504                                             self._connection.addPrinter,
00505                                             *args, **kwds)
00506 
00507 
00508     def setPrinterDevice(self, *args, **kwds):
00509         (use_pycups, name, device) = self._args_to_tuple([str, str], *args)
00510         pk_args = (name, device)
00511 
00512         self._call_with_pk_and_fallback(use_pycups,
00513                                         'PrinterSetDevice', pk_args,
00514                                         self._connection.setPrinterDevice,
00515                                         *args, **kwds)
00516 
00517 
00518     def setPrinterInfo(self, *args, **kwds):
00519         (use_pycups, name, info) = self._args_to_tuple([str, str], *args)
00520         pk_args = (name, info)
00521 
00522         self._call_with_pk_and_fallback(use_pycups,
00523                                         'PrinterSetInfo', pk_args,
00524                                         self._connection.setPrinterInfo,
00525                                         *args, **kwds)
00526 
00527 
00528     def setPrinterLocation(self, *args, **kwds):
00529         (use_pycups, name, location) = self._args_to_tuple([str, str], *args)
00530         pk_args = (name, location)
00531 
00532         self._call_with_pk_and_fallback(use_pycups,
00533                                         'PrinterSetLocation', pk_args,
00534                                         self._connection.setPrinterLocation,
00535                                         *args, **kwds)
00536 
00537 
00538     def setPrinterShared(self, *args, **kwds):
00539         (use_pycups, name, shared) = self._args_to_tuple([str, bool], *args)
00540         pk_args = (name, shared)
00541 
00542         self._call_with_pk_and_fallback(use_pycups,
00543                                         'PrinterSetShared', pk_args,
00544                                         self._connection.setPrinterShared,
00545                                         *args, **kwds)
00546 
00547 
00548     def setPrinterJobSheets(self, *args, **kwds):
00549         (use_pycups, name, start, end) = self._args_to_tuple([str, str, str], *args)
00550         pk_args = (name, start, end)
00551 
00552         self._call_with_pk_and_fallback(use_pycups,
00553                                         'PrinterSetJobSheets', pk_args,
00554                                         self._connection.setPrinterJobSheets,
00555                                         *args, **kwds)
00556 
00557 
00558     def setPrinterErrorPolicy(self, *args, **kwds):
00559         (use_pycups, name, policy) = self._args_to_tuple([str, str], *args)
00560         pk_args = (name, policy)
00561 
00562         self._call_with_pk_and_fallback(use_pycups,
00563                                         'PrinterSetErrorPolicy', pk_args,
00564                                         self._connection.setPrinterErrorPolicy,
00565                                         *args, **kwds)
00566 
00567 
00568     def setPrinterOpPolicy(self, *args, **kwds):
00569         (use_pycups, name, policy) = self._args_to_tuple([str, str], *args)
00570         pk_args = (name, policy)
00571 
00572         self._call_with_pk_and_fallback(use_pycups,
00573                                         'PrinterSetOpPolicy', pk_args,
00574                                         self._connection.setPrinterOpPolicy,
00575                                         *args, **kwds)
00576 
00577 
00578     def setPrinterUsersAllowed(self, *args, **kwds):
00579         (use_pycups, name, users) = self._args_to_tuple([str, list], *args)
00580         pk_args = (name, users)
00581 
00582         self._call_with_pk_and_fallback(use_pycups,
00583                                         'PrinterSetUsersAllowed', pk_args,
00584                                         self._connection.setPrinterUsersAllowed,
00585                                         *args, **kwds)
00586 
00587 
00588     def setPrinterUsersDenied(self, *args, **kwds):
00589         (use_pycups, name, users) = self._args_to_tuple([str, list], *args)
00590         pk_args = (name, users)
00591 
00592         self._call_with_pk_and_fallback(use_pycups,
00593                                         'PrinterSetUsersDenied', pk_args,
00594                                         self._connection.setPrinterUsersDenied,
00595                                         *args, **kwds)
00596 
00597     def addPrinterOptionDefault(self, *args, **kwds):
00598         # The values can be either a single string, or a list of strings, so
00599         # we have to handle this
00600         (use_pycups, name, option, value) = self._args_to_tuple([str, str, str], *args)
00601         # success
00602         if not use_pycups:
00603             values = (value,)
00604         # okay, maybe we directly have values
00605         else:
00606             (use_pycups, name, option, values) = self._args_to_tuple([str, str, list], *args)
00607         pk_args = (name, option, values)
00608 
00609         self._call_with_pk_and_fallback(use_pycups,
00610                                         'PrinterAddOptionDefault', pk_args,
00611                                         self._connection.addPrinterOptionDefault,
00612                                         *args, **kwds)
00613 
00614 
00615     def deletePrinterOptionDefault(self, *args, **kwds):
00616         (use_pycups, name, option) = self._args_to_tuple([str, str], *args)
00617         pk_args = (name, option)
00618 
00619         self._call_with_pk_and_fallback(use_pycups,
00620                                         'PrinterDeleteOptionDefault', pk_args,
00621                                         self._connection.deletePrinterOptionDefault,
00622                                         *args, **kwds)
00623 
00624 
00625     def deletePrinter(self, *args, **kwds):
00626         (use_pycups, name) = self._args_to_tuple([str], *args)
00627         pk_args = (name,)
00628 
00629         self._call_with_pk_and_fallback(use_pycups,
00630                                         'PrinterDelete', pk_args,
00631                                         self._connection.deletePrinter,
00632                                         *args, **kwds)
00633 
00634 #    getPrinterAttributes
00635 
00636     def addPrinterToClass(self, *args, **kwds):
00637         (use_pycups, printer, name) = self._args_to_tuple([str, str], *args)
00638         pk_args = (name, printer)
00639 
00640         self._call_with_pk_and_fallback(use_pycups,
00641                                         'ClassAddPrinter', pk_args,
00642                                         self._connection.addPrinterToClass,
00643                                         *args, **kwds)
00644 
00645 
00646     def deletePrinterFromClass(self, *args, **kwds):
00647         (use_pycups, printer, name) = self._args_to_tuple([str, str], *args)
00648         pk_args = (name, printer)
00649 
00650         self._call_with_pk_and_fallback(use_pycups,
00651                                         'ClassDeletePrinter', pk_args,
00652                                         self._connection.deletePrinterFromClass,
00653                                         *args, **kwds)
00654 
00655 
00656     def deleteClass(self, *args, **kwds):
00657         (use_pycups, name) = self._args_to_tuple([str], *args)
00658         pk_args = (name,)
00659 
00660         self._call_with_pk_and_fallback(use_pycups,
00661                                         'ClassDelete', pk_args,
00662                                         self._connection.deleteClass,
00663                                         *args, **kwds)
00664 
00665 #    getDefault
00666 
00667     def setDefault(self, *args, **kwds):
00668         (use_pycups, name) = self._args_to_tuple([str], *args)
00669         pk_args = (name,)
00670 
00671         self._call_with_pk_and_fallback(use_pycups,
00672                                         'PrinterSetDefault', pk_args,
00673                                         self._connection.setDefault,
00674                                         *args, **kwds)
00675 
00676 #    getPPD
00677 
00678     def enablePrinter(self, *args, **kwds):
00679         (use_pycups, name) = self._args_to_tuple([str], *args)
00680         pk_args = (name, True)
00681 
00682         self._call_with_pk_and_fallback(use_pycups,
00683                                         'PrinterSetEnabled', pk_args,
00684                                         self._connection.enablePrinter,
00685                                         *args, **kwds)
00686 
00687 
00688     def disablePrinter(self, *args, **kwds):
00689         (use_pycups, name) = self._args_to_tuple([str], *args)
00690         pk_args = (name, False)
00691 
00692         self._call_with_pk_and_fallback(use_pycups,
00693                                         'PrinterSetEnabled', pk_args,
00694                                         self._connection.disablePrinter,
00695                                         *args, **kwds)
00696 
00697 
00698     def acceptJobs(self, *args, **kwds):
00699         (use_pycups, name) = self._args_to_tuple([str], *args)
00700         pk_args = (name, True, '')
00701 
00702         self._call_with_pk_and_fallback(use_pycups,
00703                                         'PrinterSetAcceptJobs', pk_args,
00704                                         self._connection.acceptJobs,
00705                                         *args, **kwds)
00706 
00707 
00708     def rejectJobs(self, *args, **kwds):
00709         (use_pycups, name) = self._args_to_tuple([str], *args)
00710         (reason,) = self._kwds_to_vars(['reason'], **kwds)
00711         pk_args = (name, False, reason)
00712 
00713         self._call_with_pk_and_fallback(use_pycups,
00714                                         'PrinterSetAcceptJobs', pk_args,
00715                                         self._connection.rejectJobs,
00716                                         *args, **kwds)
00717 
00718 
00719 #    printTestPage
00720 
00721     def adminGetServerSettings(self, *args, **kwds):
00722         use_pycups = False
00723         pk_args = ()
00724 
00725         result = self._call_with_pk_and_fallback(use_pycups,
00726                                                'ServerGetSettings', pk_args,
00727                                                self._connection.adminGetServerSettings,
00728                                                *args, **kwds)
00729         settings = {}
00730         if result != None:
00731             for i in result.keys():
00732                 if type(i) == dbus.String:
00733                     settings[str(i)] = str(result[i])
00734                 else:
00735                     settings[i] = result[i]
00736 
00737         return settings
00738 
00739 
00740     def adminSetServerSettings(self, *args, **kwds):
00741         (use_pycups, settings) = self._args_to_tuple([dict], *args)
00742         pk_args = (settings,)
00743 
00744         self._call_with_pk_and_fallback(use_pycups,
00745                                         'ServerSetSettings', pk_args,
00746                                         self._connection.adminSetServerSettings,
00747                                         *args, **kwds)
00748 
00749 
00750 #    getSubscriptions
00751 #    createSubscription
00752 #    getNotifications
00753 #    cancelSubscription
00754 #    renewSubscription
00755 #    printFile
00756 #    printFiles