Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
cupshelpers.xmldriverprefs.DriverType Class Reference
Collaboration diagram for cupshelpers.xmldriverprefs.DriverType:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def add_ppd_name
def add_attribute
def add_deviceid_match
def add_fit
def set_packagehint
def get_name
def __repr__
def match
def get_packagehint

Public Attributes

 name
 ppd_name
 attributes
 deviceid

Static Public Attributes

string FIT_EXACT_CMD = "exact-cmd"
string FIT_EXACT = "exact"
string FIT_CLOSE = "close"
string FIT_GENERIC = "generic"
string FIT_NONE = "none"

Private Attributes

 _fit
 _packagehint
 _packagekit

Detailed Description

A type of driver.

Definition at line 71 of file xmldriverprefs.py.


Constructor & Destructor Documentation

Definition at line 82 of file xmldriverprefs.py.

00082 
00083     def __init__ (self, name):
00084         self.name = name
00085         self.ppd_name = None
00086         self.attributes = []
00087         self.deviceid = []
00088 
00089         class AlwaysTrue:
00090             def get (self, k, d=None):
00091                 return True
00092 
00093         self._fit = AlwaysTrue ()
00094         self._packagehint = None


Member Function Documentation

Definition at line 151 of file xmldriverprefs.py.

00151 
00152     def __repr__ (self):
00153         return "<DriverType %s instance at 0x%x>" % (self.name, id (self))

Here is the caller graph for this function:

def cupshelpers.xmldriverprefs.DriverType.add_attribute (   self,
  name,
  pattern 
)
An optional IPP attribute name and regular expression to match
against its values.

Definition at line 120 of file xmldriverprefs.py.

00120 
00121     def add_attribute (self, name, pattern):
00122         """
00123         An optional IPP attribute name and regular expression to match
00124         against its values.
00125         """
00126         self.attributes.append ((name, re.compile (pattern, re.I)))

def cupshelpers.xmldriverprefs.DriverType.add_deviceid_match (   self,
  deviceid_match 
)
An optional IEEE 1284 Device ID match.

Definition at line 127 of file xmldriverprefs.py.

00127 
00128     def add_deviceid_match (self, deviceid_match):
00129         """
00130         An optional IEEE 1284 Device ID match.
00131         """
00132         self.deviceid.append (deviceid_match)

Definition at line 133 of file xmldriverprefs.py.

00133 
00134     def add_fit (self, text):
00135         self._fit = {}
00136         for fittype in text.split():
00137             self._fit[fittype] = True
00138 
00139             # <fit>exact</fit> matches exact-cmd as well
00140             if fittype == self.FIT_EXACT:
00141                 self._fit[self.FIT_EXACT_CMD] = True

An optional PPD name regular expression.

Definition at line 95 of file xmldriverprefs.py.

00095 
00096     def add_ppd_name (self, pattern):
00097         """
00098         An optional PPD name regular expression.
00099         """
00100         self.ppd_name = re.compile (pattern, re.I)
00101 
00102         # If the PPD name pattern includes a scheme, we can perhaps
00103         # deduce which package would provide this driver type.
00104         if self._packagehint != None:
00105             return
00106 
00107         parts = pattern.split (":", 1)
00108         if len (parts) > 1:
00109             scheme = parts[0]
00110             if scheme == "drv":
00111                 rest = parts[1]
00112                 if rest.startswith ("///"):
00113                     drv = rest[3:]
00114                     f = drv.rfind ("/")
00115                     if f != -1:
00116                         drv = drv[:f]
00117                         self._packagehint = "/usr/share/cups/drv/%s" % drv
00118             else:
00119                 self._packagehint = "/usr/lib/cups/driver/%s" % scheme

Return the name for this driver type.

Definition at line 145 of file xmldriverprefs.py.

00145 
00146     def get_name (self):
00147         """
00148         Return the name for this driver type.
00149         """
00150         return self.name

Definition at line 214 of file xmldriverprefs.py.

00214 
00215     def get_packagehint (self):
00216         return None

def cupshelpers.xmldriverprefs.DriverType.match (   self,
  ppd_name,
  attributes,
  fit 
)
Return True if there is a match for all specified criteria.

ppdname: string

attributes: dict

fit: string

Definition at line 154 of file xmldriverprefs.py.

00154 
00155     def match (self, ppd_name, attributes, fit):
00156         """
00157         Return True if there is a match for all specified criteria.
00158 
00159         ppdname: string
00160 
00161         attributes: dict
00162 
00163         fit: string
00164         """
00165 
00166         matches = self._fit.get (fit, False)
00167         if matches and self.ppd_name and not self.ppd_name.match (ppd_name):
00168             matches = False
00169 
00170         if matches:
00171             for name, match in self.attributes:
00172                 if not attributes.has_key (name):
00173                     matches = False
00174                     break
00175 
00176                 values = attributes[name]
00177                 if not isinstance (values, list):
00178                     # In case getPPDs() was used instead of getPPDs2()
00179                     values = [values]
00180 
00181                 any_value_matches = False
00182                 for value in values:
00183                     if match.match (value):
00184                         any_value_matches = True
00185                         break
00186 
00187                 if not any_value_matches:
00188                     matches = False
00189                     break
00190 
00191         if matches:
00192             if self.deviceid and not attributes.has_key ("ppd-device-id"):
00193                 matches = False
00194             elif self.deviceid:
00195                 # This is a match if any of the ppd-device-id values
00196                 # match.
00197                 deviceidlist = attributes["ppd-device-id"]
00198                 if not isinstance (deviceidlist, list):
00199                     # In case getPPDs() was used instead of getPPDs2()
00200                     deviceidlist = [deviceidlist]
00201 
00202                 any_id_matches = False
00203                 for deviceidstr in deviceidlist:
00204                     deviceid = parseDeviceID (deviceidstr)
00205                     for match in self.deviceid:
00206                         if match.match (deviceid):
00207                             any_id_matches = True
00208                             break
00209 
00210                 if not any_id_matches:
00211                     matches = False
00212 
00213         return matches

Here is the caller graph for this function:

Definition at line 142 of file xmldriverprefs.py.

00142 
00143     def set_packagehint (self, hint):
00144         self._packagekit = hint


Member Data Documentation

Definition at line 92 of file xmldriverprefs.py.

Definition at line 93 of file xmldriverprefs.py.

Definition at line 143 of file xmldriverprefs.py.

Definition at line 85 of file xmldriverprefs.py.

Definition at line 86 of file xmldriverprefs.py.

Definition at line 78 of file xmldriverprefs.py.

Definition at line 77 of file xmldriverprefs.py.

Definition at line 76 of file xmldriverprefs.py.

Definition at line 79 of file xmldriverprefs.py.

Definition at line 80 of file xmldriverprefs.py.

Definition at line 83 of file xmldriverprefs.py.

Definition at line 84 of file xmldriverprefs.py.


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