Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Private Member Functions | Private Attributes
asyncpk1.PK1Connection Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def destroy
def getDevices
def cancelJob
def setJobHoldUntil
def restartJob
def getFile

Private Member Functions

def _make_binding
def _coerce
def _args_kwds_to_tuple
def _call_with_pk
def _nothing_to_unpack
def _unpack_getDevices_reply

Private Attributes

 _conn
 _system_bus
 _bindings

Detailed Description

Definition at line 203 of file asyncpk1.py.


Constructor & Destructor Documentation

def asyncpk1.PK1Connection.__init__ (   self,
  reply_handler = None,
  error_handler = None,
  host = None,
  port = None,
  encryption = None,
  parent = None 
)

Definition at line 205 of file asyncpk1.py.

00205 
00206                  host=None, port=None, encryption=None, parent=None):
00207         self._conn = asyncipp.IPPAuthConnection  (reply_handler=reply_handler,
00208                                                   error_handler=error_handler,
00209                                                   host=host, port=port,
00210                                                   encryption=encryption,
00211                                                   parent=parent)
00212 
00213         try:
00214             self._system_bus = dbus.SystemBus()
00215         except (dbus.exceptions.DBusException, AttributeError):
00216             # No system D-Bus.
00217             self._system_bus = None
00218 
00219         global _DevicesGet_uses_new_api
00220         if _DevicesGet_uses_new_api == None and self._system_bus:
00221             try:
00222                 obj = self._system_bus.get_object(CUPS_PK_NAME, CUPS_PK_PATH)
00223                 proxy = dbus.Interface (obj, dbus.INTROSPECTABLE_IFACE)
00224                 api = proxy.Introspect ()
00225                 top = xml.etree.ElementTree.XML (api)
00226                 for interface in top.findall ("interface"):
00227                     if interface.attrib.get ("name") != CUPS_PK_IFACE:
00228                         continue
00229 
00230                     for method in interface.findall ("method"):
00231                         if method.attrib.get ("name") != "DevicesGet":
00232                             continue
00233 
00234                         num_args = 0
00235                         for arg in method.findall ("arg"):
00236                             direction = arg.attrib.get ("direction")
00237                             if direction != "in":
00238                                 continue
00239 
00240                             num_args += 1
00241 
00242                         _DevicesGet_uses_new_api = num_args == 4
00243                         debugprint ("DevicesGet new API: %s" % (num_args == 4))
00244                         break
00245 
00246                     break
00247 
00248             except Exception, e:
00249                 debugprint ("Exception assessing DevicesGet API: %s" % e)
00250 
00251         methodtype = type (self._conn.getPrinters)
00252         bindings = []
00253         for fname in dir (self._conn):
00254             if fname.startswith ('_'):
00255                 continue
00256             fn = getattr (self._conn, fname)
00257             if type (fn) != methodtype:
00258                 continue
00259             if not hasattr (self, fname):
00260                 setattr (self, fname, self._make_binding (fn))
00261                 bindings.append (fname)
00262 
00263         self._bindings = bindings
00264         debugprint ("+%s" % self)

Definition at line 265 of file asyncpk1.py.

00265 
00266     def __del__ (self):
00267         debug.debugprint ("-%s" % self)


Member Function Documentation

def asyncpk1.PK1Connection._args_kwds_to_tuple (   self,
  types,
  params,
  args,
  kwds 
) [private]
Collapse args and kwds into a single tuple.

Definition at line 288 of file asyncpk1.py.

00288 
00289     def _args_kwds_to_tuple (self, types, params, args, kwds):
00290         """Collapse args and kwds into a single tuple."""
00291         leftover_kwds = kwds.copy ()
00292         reply_handler = leftover_kwds.get ("reply_handler")
00293         error_handler = leftover_kwds.get ("error_handler")
00294         if leftover_kwds.has_key ("reply_handler"):
00295             del leftover_kwds["reply_handler"]
00296         if leftover_kwds.has_key ("error_handler"):
00297             del leftover_kwds["error_handler"]
00298         if leftover_kwds.has_key ("auth_handler"):
00299             del leftover_kwds["auth_handler"]
00300 
00301         result = [True, reply_handler, error_handler, ()]
00302         if self._system_bus == None:
00303             return result
00304 
00305         tup = []
00306         argindex = 0
00307         for arg in args:
00308             try:
00309                 val = self._coerce (types[argindex], arg)
00310             except IndexError:
00311                 # More args than types.
00312                 kw, default = params[argindex]
00313                 if default != arg:
00314                     return result
00315 
00316                 # It's OK, this is the default value anyway and can be
00317                 # ignored.  Skip to the next one.
00318                 argindex += 1
00319                 continue
00320             except TypeError, e:
00321                 debugprint ("Error converting %s to %s" %
00322                             (repr (arg), types[argindex]))
00323                 return result
00324 
00325             tup.append (val)
00326             argindex += 1
00327 
00328         for kw, default in params[argindex:]:
00329             if leftover_kwds.has_key (kw):
00330                 try:
00331                     val = self._coerce (types[argindex], leftover_kwds[kw])
00332                 except TypeError, e:
00333                     debugprint ("Error converting %s to %s" %
00334                                 (repr (leftover_kwds[kw]), types[argindex]))
00335                     return result
00336 
00337                 tup.append (val)
00338                 del leftover_kwds[kw]
00339             else:
00340                 tup.append (default)
00341 
00342             argindex += 1
00343 
00344         if leftover_kwds:
00345             debugprint ("Leftover keywords: %s" % repr (leftover_kwds.keys ()))
00346             return result
00347 
00348         result[0] = False
00349         result[3] = tuple (tup)
00350         debugprint ("Converted %s/%s to %s" % (args, kwds, tuple (tup)))
00351         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncpk1.PK1Connection._call_with_pk (   self,
  use_pycups,
  pk_method_name,
  pk_args,
  reply_handler,
  error_handler,
  unpack_fn,
  fallback_fn,
  args,
  kwds 
) [private]

Definition at line 354 of file asyncpk1.py.

00354 
00355                        fallback_fn, args, kwds):
00356         asyncmethodcall = _PK1AsyncMethodCall (self._system_bus, self,
00357                                                pk_method_name, pk_args,
00358                                                reply_handler,
00359                                                error_handler,
00360                                                unpack_fn, fallback_fn,
00361                                                args, kwds)
00362 
00363         if not use_pycups:
00364             try:
00365                 debugprint ("Calling PK method %s" % pk_method_name)
00366                 asyncmethodcall.call ()
00367             except dbus.DBusException, e:
00368                 debugprint ("D-Bus call failed: %s" % repr (e))
00369                 use_pycups = True
00370 
00371         if use_pycups:
00372             return asyncmethodcall.call_fallback_fn ()

Here is the caller graph for this function:

def asyncpk1.PK1Connection._coerce (   self,
  typ,
  val 
) [private]

Definition at line 285 of file asyncpk1.py.

00285 
00286     def _coerce (self, typ, val):
00287         return typ (val)

Here is the caller graph for this function:

def asyncpk1.PK1Connection._make_binding (   self,
  fn 
) [private]

Definition at line 268 of file asyncpk1.py.

00268 
00269     def _make_binding (self, fn):
00270         def binding (*args, **kwds):
00271             op = _PK1AsyncMethodCall (None, self, None, None,
00272                                       kwds.get ("reply_handler"),
00273                                       kwds.get ("error_handler"),
00274                                       None, fn, args, kwds)
00275             op.call_fallback_fn ()
00276 
00277         return binding

Definition at line 373 of file asyncpk1.py.

00373 
00374     def _nothing_to_unpack (self):
00375         return None

Here is the caller graph for this function:

def asyncpk1.PK1Connection._unpack_getDevices_reply (   self,
  dbusdict 
) [private]

Definition at line 413 of file asyncpk1.py.

00413 
00414     def _unpack_getDevices_reply (self, dbusdict):
00415         result_str = dict()
00416         for key, value in dbusdict.iteritems ():
00417             if type (key) == dbus.String:
00418                 result_str[str (key)] = str (value)
00419             else:
00420                 result_str[key] = value
00421 
00422         # cups-pk-helper returns all devices in one dictionary.
00423         # Keys of different devices are distinguished by ':n' postfix.
00424 
00425         devices = dict()
00426         n = 0
00427         affix = ':' + str (n)
00428         device_keys = [x for x in result_str.keys () if x.endswith (affix)]
00429         while len (device_keys) > 0:
00430             device_uri = None
00431             device_dict = dict()
00432             for keywithaffix in device_keys:
00433                 key = keywithaffix[:len (keywithaffix) - len (affix)]
00434                 if key != 'device-uri':
00435                     device_dict[key] = result_str[keywithaffix]
00436                 else:
00437                     device_uri = result_str[keywithaffix]
00438 
00439             if device_uri != None:
00440                 devices[device_uri] = device_dict
00441 
00442             n += 1
00443             affix = ':' + str (n)
00444             device_keys = [x for x in result_str.keys () if x.endswith (affix)]
00445 
00446         return devices

Here is the caller graph for this function:

def asyncpk1.PK1Connection.cancelJob (   self,
  args,
  kwds 
)

Definition at line 447 of file asyncpk1.py.

00447 
00448     def cancelJob (self, *args, **kwds):
00449         (use_pycups, reply_handler, error_handler,
00450          tup) = self._args_kwds_to_tuple ([int, bool],
00451                                           [(None, None),
00452                                            (None, False)], # purge_job
00453                                           args, kwds)
00454 
00455         self._call_with_pk (use_pycups,
00456                             'JobCancelPurge', tup, reply_handler, error_handler,
00457                             self._nothing_to_unpack,
00458                             self._conn.cancelJob, args, kwds)

Here is the call graph for this function:

Definition at line 278 of file asyncpk1.py.

00278 
00279     def destroy (self):
00280         debugprint ("DESTROY: %s" % self)
00281         self._conn.destroy ()
00282 
00283         for binding in self._bindings:
00284             delattr (self, binding)

def asyncpk1.PK1Connection.getDevices (   self,
  args,
  kwds 
)

Definition at line 376 of file asyncpk1.py.

00376 
00377     def getDevices (self, *args, **kwds):
00378         global _DevicesGet_uses_new_api
00379         if _DevicesGet_uses_new_api:
00380             (use_pycups, reply_handler, error_handler,
00381              tup) = self._args_kwds_to_tuple ([int, int, list, list],
00382                                               [("timeout", 0),
00383                                                ("limit", 0),
00384                                                ("include_schemes", []),
00385                                                ("exclude_schemes", [])],
00386                                               args, kwds)
00387         else:
00388             (use_pycups, reply_handler, error_handler,
00389              tup) = self._args_kwds_to_tuple ([int, list, list],
00390                                               [("limit", 0),
00391                                                ("include_schemes", []),
00392                                                ("exclude_schemes", [])],
00393                                               args, kwds)
00394 
00395             if not use_pycups:
00396                 # Special handling for include_schemes/exclude_schemes.
00397                 # Convert from list to ","-separated string.
00398                 newtup = list (tup)
00399                 for paramindex in [1, 2]:
00400                     if len (newtup[paramindex]) > 0:
00401                         newtup[paramindex] = reduce (lambda x, y:
00402                                                          x + "," + y,
00403                                                      newtup[paramindex])
00404                     else:
00405                         newtup[paramindex] = ""
00406 
00407                 tup = tuple (newtup)
00408 
00409         self._call_with_pk (use_pycups,
00410                             'DevicesGet', tup, reply_handler, error_handler,
00411                             self._unpack_getDevices_reply,
00412                             self._conn.getDevices, args, kwds)

Here is the call graph for this function:

def asyncpk1.PK1Connection.getFile (   self,
  args,
  kwds 
)

Definition at line 482 of file asyncpk1.py.

00482 
00483     def getFile (self, *args, **kwds):
00484         (use_pycups, reply_handler, error_handler,
00485          tup) = self._args_kwds_to_tuple ([str, str],
00486                                           [("resource", None),
00487                                            ("filename", None)],
00488                                           args, kwds)
00489 
00490         # getFile(resource, filename=None, fd=-1, file=None) -> None
00491         if use_pycups:
00492             if ((len (args) == 0 and kwds.has_key ('resource')) or
00493                 (len (args) == 1)):
00494                 can_use_tempfile = True
00495                 for each in kwds.keys ():
00496                     if each not in ['resource', 'fd', 'file',
00497                                     'reply_handler', 'error_handler']:
00498                         can_use_tempfile = False
00499                         break
00500 
00501                 if can_use_tempfile:
00502                     # We can still use PackageKit for this.
00503                     if len (args) == 0:
00504                         resource = kwds["resource"]
00505                     else:
00506                         resource = args[0]
00507 
00508                     wrapper = _WriteToTmpFile (kwds,
00509                                                reply_handler,
00510                                                error_handler)
00511                     self._call_with_pk (False,
00512                                         'FileGet',
00513                                         (resource, wrapper.get_filename ()),
00514                                         wrapper.reply_handler,
00515                                         wrapper.error_handler,
00516                                         self._nothing_to_unpack,
00517                                         self._conn.getFile, args, kwds)
00518                     return
00519 
00520         self._call_with_pk (use_pycups,
00521                             'FileGet', tup, reply_handler,
00522                             error_handler, self._nothing_to_unpack,
00523                             self._conn.getFile, args, kwds)

Here is the call graph for this function:

def asyncpk1.PK1Connection.restartJob (   self,
  args,
  kwds 
)

Definition at line 471 of file asyncpk1.py.

00471 
00472     def restartJob (self, *args, **kwds):
00473         (use_pycups, reply_handler, error_handler,
00474          tup) = self._args_kwds_to_tuple ([int],
00475                                           [(None, None)],
00476                                           args, kwds)
00477 
00478         self._call_with_pk (use_pycups,
00479                             'JobRestart', tup, reply_handler,
00480                             error_handler, self._nothing_to_unpack,
00481                             self._conn.restartJob, args, kwds)

Here is the call graph for this function:

def asyncpk1.PK1Connection.setJobHoldUntil (   self,
  args,
  kwds 
)

Definition at line 459 of file asyncpk1.py.

00459 
00460     def setJobHoldUntil (self, *args, **kwds):
00461         (use_pycups, reply_handler, error_handler,
00462          tup) = self._args_kwds_to_tuple ([int, str],
00463                                           [(None, None),
00464                                            (None, None)],
00465                                           args, kwds)
00466 
00467         self._call_with_pk (use_pycups,
00468                             'JobSetHoldUntil', tup, reply_handler,
00469                             error_handler, self._nothing_to_unpack,
00470                             self._conn.setJobHoldUntil, args, kwds)

Here is the call graph for this function:


Member Data Documentation

Definition at line 262 of file asyncpk1.py.

Definition at line 206 of file asyncpk1.py.

Definition at line 213 of file asyncpk1.py.


The documentation for this class was generated from the following file: