Back to index

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

List of all members.

Public Member Functions

def __init__
def add_printer
def update_from_attrs
def remove_printer
def lookup
def all_printer_names
def lookup_cached_by_name

Public Attributes

 printer
 names

Private Member Functions

def _collect_names
def _map_printer

Detailed Description

Definition at line 69 of file jobviewer.py.


Constructor & Destructor Documentation

def jobviewer.PrinterURIIndex.__init__ (   self,
  names = [] 
)

Definition at line 70 of file jobviewer.py.

00070 
00071     def __init__ (self, names=[]):
00072         self.printer = {}
00073         self.names = names
00074         self._collect_names ()


Member Function Documentation

def jobviewer.PrinterURIIndex._collect_names (   self,
  connection = None 
) [private]

Definition at line 75 of file jobviewer.py.

00075 
00076     def _collect_names (self, connection=None):
00077         if not self.names:
00078             return
00079 
00080         if not connection:
00081             try:
00082                 c = cups.Connection ()
00083             except RuntimeError:
00084                 return
00085 
00086         for name in self.names:
00087             self.add_printer (name, connection=c)
00088 
00089         self.names = []

Here is the call graph for this function:

Here is the caller graph for this function:

def jobviewer.PrinterURIIndex._map_printer (   self,
  uri = None,
  name = None,
  connection = None 
) [private]

Definition at line 138 of file jobviewer.py.

00138 
00139     def _map_printer (self, uri=None, name=None, connection=None):
00140         try:
00141             if connection == None:
00142                 connection = cups.Connection ()
00143 
00144             r = ['printer-name', 'printer-uri-supported', 'printer-more-info']
00145             if uri != None:
00146                 attrs = connection.getPrinterAttributes (uri=uri,
00147                                                          requested_attributes=r)
00148             else:
00149                 attrs = connection.getPrinterAttributes (name,
00150                                                          requested_attributes=r)
00151         except RuntimeError:
00152             # cups.Connection() failed
00153             raise KeyError
00154         except cups.IPPError:
00155             # URI not known.
00156             raise KeyError
00157 
00158         name = attrs['printer-name']
00159         self.update_from_attrs (name, attrs)
00160         if uri != None:
00161             self.printer[uri] = name
00162         return name
00163 

Here is the call graph for this function:

Here is the caller graph for this function:

def jobviewer.PrinterURIIndex.add_printer (   self,
  printer,
  connection = None 
)

Definition at line 90 of file jobviewer.py.

00090 
00091     def add_printer (self, printer, connection=None):
00092         try:
00093             self._map_printer (name=printer, connection=connection)
00094         except KeyError:
00095             return

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file jobviewer.py.

00126 
00127     def all_printer_names (self):
00128         self._collect_names ()
00129         return set (self.printer.values ())

Here is the call graph for this function:

def jobviewer.PrinterURIIndex.lookup (   self,
  uri,
  connection = None 
)

Definition at line 119 of file jobviewer.py.

00119 
00120     def lookup (self, uri, connection=None):
00121         self._collect_names ()
00122         try:
00123             return self.printer[uri]
00124         except KeyError:
00125             return self._map_printer (uri=uri, connection=connection)

Here is the call graph for this function:

Definition at line 130 of file jobviewer.py.

00130 
00131     def lookup_cached_by_name (self, name):
00132         self._collect_names ()
00133         for uri, printer in self.printer.iteritems ():
00134             if printer == name:
00135                 return uri
00136 
00137         raise KeyError

Here is the call graph for this function:

def jobviewer.PrinterURIIndex.remove_printer (   self,
  printer 
)

Definition at line 111 of file jobviewer.py.

00111 
00112     def remove_printer (self, printer):
00113         # Remove references to this printer in the URI map.
00114         self._collect_names ()
00115         uris = self.printer.keys ()
00116         for uri in uris:
00117             if self.printer[uri] == printer:
00118                 del self.printer[uri]

Here is the call graph for this function:

def jobviewer.PrinterURIIndex.update_from_attrs (   self,
  printer,
  attrs 
)

Definition at line 96 of file jobviewer.py.

00096 
00097     def update_from_attrs (self, printer, attrs):
00098         uris = []
00099         if attrs.has_key ('printer-uri-supported'):
00100             uri_supported = attrs['printer-uri-supported']
00101             if type (uri_supported) != list:
00102                 uri_supported = [uri_supported]
00103             uris.extend (uri_supported)
00104         if attrs.has_key ('notify-printer-uri'):
00105             uris.append (attrs['notify-printer-uri'])
00106         if attrs.has_key ('printer-more-info'):
00107             uris.append (attrs['printer-more-info'])
00108 
00109         for uri in uris:
00110             self.printer[uri] = printer

Here is the caller graph for this function:


Member Data Documentation

Definition at line 72 of file jobviewer.py.

Definition at line 71 of file jobviewer.py.


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