Back to index

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

List of all members.

Public Member Functions

def __init__
def __del__
def fetch_ppd

Private Member Functions

def _connect
def _got_ppd
def _got_ppd3
def _connected
def _schedule_callback

Private Attributes

 _cups
 _exc
 _cache
 _modtimes
 _host
 _port
 _encryption
 _queued
 _connecting

Detailed Description

Definition at line 31 of file ppdcache.py.


Constructor & Destructor Documentation

def ppdcache.PPDCache.__init__ (   self,
  host = None,
  port = None,
  encryption = None 
)

Definition at line 32 of file ppdcache.py.

00032 
00033     def __init__ (self, host=None, port=None, encryption=None):
00034         self._cups = None
00035         self._exc = None
00036         self._cache = dict()
00037         self._modtimes = dict()
00038         self._host = host
00039         self._port = port
00040         self._encryption = encryption
00041         self._queued = list()
00042         self._connecting = False
00043         debugprint ("+%s" % self)

def ppdcache.PPDCache.__del__ (   self)

Definition at line 44 of file ppdcache.py.

00044 
00045     def __del__ (self):
00046         debugprint ("-%s" % self)
00047         if self._cups:
00048             self._cups.destroy ()


Member Function Documentation

def ppdcache.PPDCache._connect (   self,
  callback = None 
) [private]

Definition at line 100 of file ppdcache.py.

00100 
00101     def _connect (self, callback=None):
00102         self._connecting = True
00103         asyncconn.Connection (host=self._host, port=self._port,
00104                               encryption=self._encryption,
00105                               reply_handler=self._connected,
00106                               error_handler=self._connected)

Here is the call graph for this function:

Here is the caller graph for this function:

def ppdcache.PPDCache._connected (   self,
  connection,
  exc 
) [private]

Definition at line 157 of file ppdcache.py.

00157 
00158     def _connected (self, connection, exc):
00159         self._connecting = False
00160         if isinstance (exc, Exception):
00161             self._cups = None
00162             self._exc = exc
00163         else:
00164             self._cups = connection
00165 
00166         queued = self._queued
00167         self._queued = list()
00168         for name, callback in queued:
00169             self.fetch_ppd (name, callback)

Here is the call graph for this function:

Here is the caller graph for this function:

def ppdcache.PPDCache._got_ppd (   self,
  connection,
  name,
  result,
  callback 
) [private]

Definition at line 107 of file ppdcache.py.

00107 
00108     def _got_ppd (self, connection, name, result, callback):
00109         if isinstance (result, Exception):
00110             self._schedule_callback (callback, name, result, None)
00111         else:
00112             # Store an open file object, then remove the actual file.
00113             # This way we don't leave temporary files around.
00114             self._cache[name] = file (result)
00115             debugprint ("%s: caching %s (fd %d)" % (self, result,
00116                                                     self._cache[name].fileno()))
00117             os.unlink (result)
00118             self.fetch_ppd (name, callback)

Here is the call graph for this function:

def ppdcache.PPDCache._got_ppd3 (   self,
  connection,
  name,
  result,
  callback 
) [private]

Definition at line 119 of file ppdcache.py.

00119 
00120     def _got_ppd3 (self, connection, name, result, callback):
00121         (status, modtime, filename) = result
00122         if status in [cups.HTTP_OK, cups.HTTP_NOT_MODIFIED]:
00123             if status == cups.HTTP_NOT_MODIFIED:
00124                 # The file is no newer than the one we already have.
00125 
00126                 # CUPS before 1.5.3 created a temporary file in error
00127                 # in this situation (STR #4018) so remove that.
00128                 try:
00129                     os.unlink (filename)
00130                 except OSError:
00131                     pass
00132 
00133             elif status == cups.HTTP_OK:
00134                 # Our version of the file was older.  Cache the new version.
00135 
00136                 # Store an open file object, then remove the actual
00137                 # file.  This way we don't leave temporary files
00138                 # around.
00139                 try:
00140                     self._cache[name] = file (filename)
00141                     debugprint ("%s: caching %s (fd %d) "
00142                                 "(%s) - %s" % (self, filename,
00143                                                self._cache[name].fileno (),
00144                                                modtime, status))
00145                     os.unlink (filename)
00146                     self._modtimes[name] = modtime
00147                 except IOError:
00148                     # File disappeared?
00149                     debugprint ("%s: file %s disappeared? Unable to cache it"
00150                                 % (self, filename))
00151 
00152             # Now fetch it from our own cache.
00153             self.fetch_ppd (name, callback, check_uptodate=False)
00154         else:
00155             self._schedule_callback (callback, name,
00156                                      None, cups.HTTPError (status))

Here is the call graph for this function:

Here is the caller graph for this function:

def ppdcache.PPDCache._schedule_callback (   self,
  callback,
  name,
  result,
  exc 
) [private]

Definition at line 170 of file ppdcache.py.

00170 
00171     def _schedule_callback (self, callback, name, result, exc):
00172         def cb_func (callback, name, result, exc):
00173             gtk.gdk.threads_enter ()
00174             callback (name, result, exc)
00175             gtk.gdk.threads_leave ()
00176             return False
00177 
00178         gobject.idle_add (cb_func, callback, name, result, exc)

Here is the caller graph for this function:

def ppdcache.PPDCache.fetch_ppd (   self,
  name,
  callback,
  check_uptodate = True 
)

Definition at line 49 of file ppdcache.py.

00049 
00050     def fetch_ppd (self, name, callback, check_uptodate=True):
00051         if check_uptodate and self._modtimes.has_key (name):
00052             # We have getPPD3 so we can check whether the PPD is up to
00053             # date.
00054             debugprint ("%s: check if %s is up to date" % (self, name))
00055             self._cups.getPPD3 (name,
00056                                 modtime=self._modtimes[name],
00057                                 reply_handler=lambda c, r:
00058                                     self._got_ppd3 (c, name, r, callback),
00059                                 error_handler=lambda c, r:
00060                                     self._got_ppd3 (c, name, r, callback))
00061             return
00062 
00063         try:
00064             f = self._cache[name]
00065         except RuntimeError, e:
00066             self._schedule_callback (callback, name, None, e)
00067             return
00068         except KeyError:
00069             if not self._cups:
00070                 self._queued.append ((name, callback))
00071                 if not self._connecting:
00072                     self._connect ()
00073 
00074                 return
00075 
00076             debugprint ("%s: fetch PPD for %s" % (self, name))
00077             self._cups.getPPD3 (name,
00078                                 reply_handler=lambda c, r:
00079                                     self._got_ppd3 (c, name, r, callback),
00080                                 error_handler=lambda c, r:
00081                                     self._got_ppd3 (c, name, r, callback))
00082             return
00083 
00084         # Copy from our file object to a new temporary file, create a
00085         # PPD object from it, then remove the file.  This way we don't
00086         # leave temporary files around even though we are caching...
00087         f.seek (0)
00088         (tmpfd, tmpfname) = tempfile.mkstemp ()
00089         tmpf = file (tmpfname, "w")
00090         tmpf.writelines (f.readlines ())
00091         del tmpf
00092         os.close (tmpfd)
00093         try:
00094             ppd = cups.PPD (tmpfname)
00095             os.unlink (tmpfname)
00096             self._schedule_callback (callback, name, ppd, None)
00097         except Exception, e:
00098             os.unlink (tmpfname)
00099             self._schedule_callback (callback, name, None, e)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 35 of file ppdcache.py.

Definition at line 41 of file ppdcache.py.

Definition at line 33 of file ppdcache.py.

Definition at line 39 of file ppdcache.py.

Definition at line 34 of file ppdcache.py.

Definition at line 37 of file ppdcache.py.

Definition at line 36 of file ppdcache.py.

Definition at line 38 of file ppdcache.py.

Definition at line 40 of file ppdcache.py.


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