Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes
cupshelpers.xmldriverprefs.PreferenceOrder Class Reference

List of all members.

Public Member Functions

def __init__
def load
def get_ordered_types

Public Attributes

 ptypes

Detailed Description

A policy for choosing the preference order for drivers.

Definition at line 406 of file xmldriverprefs.py.


Constructor & Destructor Documentation

Definition at line 411 of file xmldriverprefs.py.

00411 
00412     def __init__ (self):
00413         self.ptypes = []


Member Function Documentation

def cupshelpers.xmldriverprefs.PreferenceOrder.get_ordered_types (   self,
  drivertypes,
  make_and_model,
  deviceid 
)
Return an accumulated list of driver types from all printer
types that match a given printer's device-make-and-model and
IEEE 1284 Device ID.

The deviceid parameter must be None or a dict indexed by
short-form upper-case field keys.

Definition at line 446 of file xmldriverprefs.py.

00446 
00447     def get_ordered_types (self, drivertypes, make_and_model, deviceid):
00448         """
00449         Return an accumulated list of driver types from all printer
00450         types that match a given printer's device-make-and-model and
00451         IEEE 1284 Device ID.
00452 
00453         The deviceid parameter must be None or a dict indexed by
00454         short-form upper-case field keys.
00455         """
00456 
00457         if deviceid == None:
00458             deviceid = {}
00459 
00460         if make_and_model == None:
00461             make_and_model = ""
00462 
00463         orderedtypes = []
00464         blacklist = set()
00465         avoidtypes = set()
00466         for ptype in self.ptypes:
00467             if ptype.match (make_and_model, deviceid):
00468                 for pattern in ptype.get_drivertype_patterns ():
00469                     # Match against the glob pattern
00470                     for drivertype in drivertypes.filter (pattern):
00471                         # Add each result if not already in the list.
00472                         if drivertype not in orderedtypes:
00473                             orderedtypes.append (drivertype)
00474 
00475                 for pattern in ptype.get_avoidtype_patterns ():
00476                     # Match against the glob pattern.
00477                     for drivertype in drivertypes.filter (pattern):
00478                         # Add each result to the set.
00479                         avoidtypes.add (drivertype)
00480 
00481                 for pattern in ptype.get_blacklist ():
00482                     # Match against the glob pattern.
00483                     for drivertype in drivertypes.filter (pattern):
00484                         # Add each result to the set.
00485                         blacklist.add (drivertype)
00486 
00487         if avoidtypes:
00488             avoided = []
00489             for t in avoidtypes:
00490                 try:
00491                     i = orderedtypes.index (t)
00492                     del orderedtypes[i]
00493                     avoided.append (t)
00494                 except IndexError:
00495                     continue
00496 
00497             orderedtypes.extend (avoided)
00498 
00499         if blacklist:
00500             # Remove blacklisted drivers.
00501             remaining = []
00502             for t in orderedtypes:
00503                 if t not in blacklist:
00504                     remaining.append (t)
00505 
00506             orderedtypes = remaining
00507 
00508         return orderedtypes
00509 

def cupshelpers.xmldriverprefs.PreferenceOrder.load (   self,
  preferreddrivers 
)
Load the policy from an XML file.

Definition at line 414 of file xmldriverprefs.py.

00414 
00415     def load (self, preferreddrivers):
00416         """
00417         Load the policy from an XML file.
00418         """
00419 
00420         for printer in preferreddrivers.getchildren ():
00421             ptype = PrinterType ()
00422             for child in printer.getchildren ():
00423                 if child.tag == "make-and-model":
00424                     ptype.add_make_and_model (child.attrib["match"])
00425                 elif child.tag == "deviceid":
00426                     deviceid_match = DeviceIDMatch ()
00427                     for field in child.getchildren ():
00428                         if field.tag == "field":
00429                             deviceid_match.add_field (field.attrib["name"],
00430                                                       field.attrib["match"])
00431                     ptype.add_deviceid_match (deviceid_match)
00432 
00433                 elif child.tag == "drivers":
00434                     for drivertype in child.getchildren ():
00435                         ptype.add_drivertype_pattern (drivertype.text)
00436 
00437                 elif child.tag == "avoid":
00438                     for drivertype in child.getchildren ():
00439                         ptype.add_avoidtype_pattern (drivertype.text)
00440 
00441                 elif child.tag == "blacklist":
00442                     for drivertype in child.getchildren ():
00443                         ptype.add_blacklisted (drivertype.text)
00444 
00445             self.ptypes.append (ptype)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 412 of file xmldriverprefs.py.


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