Back to index

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

List of all members.

Public Member Functions

def __init__
def add_device
def get_devices
def get_info
def set_data
def get_data
def __str__
def __repr__
def __cmp__

Public Attributes

 devices
 dnssd_hostname
 mfg
 mdl
 mfg_lower
 mdl_lower
 sn

Private Member Functions

def _canonical_id
def _get_host_from_uri

Private Attributes

 _network_host
 _user_data
 _ppdippstr

Detailed Description

Definition at line 27 of file PhysicalDevice.py.


Constructor & Destructor Documentation

def PhysicalDevice.PhysicalDevice.__init__ (   self,
  device 
)

Definition at line 28 of file PhysicalDevice.py.

00028 
00029     def __init__(self, device):
00030         self.devices = None
00031         self._network_host = None
00032         self.dnssd_hostname = None
00033         self.add_device (device)
00034         self._user_data = {}
00035         self._ppdippstr = ppdippstr.backends


Member Function Documentation

def PhysicalDevice.PhysicalDevice.__cmp__ (   self,
  other 
)

Definition at line 209 of file PhysicalDevice.py.

00209 
00210     def __cmp__(self, other):
00211         if other == None or type (other) != type (self):
00212             return 1
00213 
00214         if (self._network_host != None or
00215             other._network_host != None):
00216             return cmp (self._network_host, other._network_host)
00217 
00218         if (other.mfg == '' and other.mdl == '') or \
00219            (self.mfg == '' and self.mdl == ''):
00220             # One or other is just a backend, not a real physical device.
00221             if other.mfg == '' and other.mdl == '' and \
00222                self.mfg == '' and self.mdl == '':
00223                 return cmp (self.devices[0], other.devices[0])
00224 
00225             if other.mfg == '' and other.mdl == '':
00226                 return -1
00227             return 1
00228 
00229         if self.mfg == '' or self.mdl.lower ().startswith (self.mfg.lower ()):
00230             our_make_and_model = self.mdl
00231         else:
00232             our_make_and_model = "%s %s" % (self.mfg, self.mdl)
00233         (our_mfg, our_mdl) = \
00234             cupshelpers.ppds.ppdMakeModelSplit (our_make_and_model)
00235 
00236         if other.mfg == '' or \
00237                 other.mdl.lower ().startswith (other.mfg.lower ()):
00238             other_make_and_model = other.mdl
00239         else:
00240             other_make_and_model = "%s %s" % (other.mfg, other.mdl)
00241         (other_mfg, other_mdl) = \
00242             cupshelpers.ppds.ppdMakeModelSplit (other_make_and_model)
00243 
00244         mfgcmp = cmp (our_mfg.lower (), other_mfg.lower ())
00245         if mfgcmp != 0:
00246             return mfgcmp
00247         mdlcmp = cmp (our_mdl.lower (), other_mdl.lower ())
00248         if mdlcmp != 0:
00249             return mdlcmp
00250         if self.sn == '' or other.sn == '':
00251             return 0
00252         return cmp (self.sn, other.sn)

Definition at line 204 of file PhysicalDevice.py.

00204 
00205     def __repr__ (self):
00206         return "<PhysicalDevice.PhysicalDevice (%s,%s,%s)>" % (self.mfg,
00207                                                                self.mdl,
00208                                                                self.sn)

Here is the caller graph for this function:

Definition at line 201 of file PhysicalDevice.py.

00201 
00202     def __str__ (self):
00203         return "(description: %s)" % self.__repr__ ()

Here is the call graph for this function:

def PhysicalDevice.PhysicalDevice._canonical_id (   self,
  device 
) [private]

Definition at line 36 of file PhysicalDevice.py.

00036 
00037     def _canonical_id (self, device):
00038         if hasattr (device, "id_dict"):
00039             mfg = device.id_dict.get ('MFG', '')
00040             mdl = device.id_dict.get ('MDL', '')
00041 
00042             if mfg == '' or mdl.lower ().startswith (mfg.lower ()):
00043                 make_and_model = mdl
00044             else:
00045                 make_and_model = "%s %s" % (mfg, mdl)
00046         else:
00047              make_and_model = device.make_and_model
00048 
00049         return cupshelpers.ppds.ppdMakeModelSplit (make_and_model)

Here is the caller graph for this function:

def PhysicalDevice.PhysicalDevice._get_host_from_uri (   self,
  uri 
) [private]

Definition at line 50 of file PhysicalDevice.py.

00050 
00051     def _get_host_from_uri (self, uri):
00052         hostport = None
00053         host = None
00054         dnssdhost = None
00055         (scheme, rest) = urllib.splittype (uri)
00056         if scheme == 'hp' or scheme == 'hpfax':
00057             if rest.startswith ("/net/"):
00058                 (rest, ipparam) = urllib.splitquery (rest[5:])
00059                 if ipparam != None and ipparam.startswith("ip="):
00060                     hostport = ipparam[3:]
00061                 else:
00062                     if ipparam != None and ipparam.startswith("zc="):
00063                         dnssdhost = ipparam[3:]
00064                     else:
00065                         return None, None
00066             else:
00067                 return None, None
00068         elif scheme == 'dnssd' or scheme == 'mdns':
00069             # The URIs of the CUPS "dnssd" backend do not contain the host
00070             # name of the printer
00071             return None, None
00072         else:
00073             (hostport, rest) = urllib.splithost (rest)
00074             if hostport == None:
00075                 return None, None
00076 
00077         if hostport:
00078             (host, port) = urllib.splitport (hostport)
00079         return host, dnssdhost

Here is the caller graph for this function:

def PhysicalDevice.PhysicalDevice.add_device (   self,
  device 
)

Definition at line 80 of file PhysicalDevice.py.

00080 
00081     def add_device (self, device):
00082         if self._network_host or self.dnssd_hostname:
00083             host, dnssdhost = self._get_host_from_uri (device.uri)
00084             if (hasattr (device, 'address')):
00085                 host = device.address
00086             if (hasattr (device, 'hostname') and dnssdhost == None):
00087                 dnssdhost = device.hostname
00088             if (host == None and dnssdhost == None) or \
00089                (host and self._network_host and \
00090                 host != self._network_host) or \
00091                (dnssdhost and self.dnssd_hostname and \
00092                 dnssdhost != self.dnssd_hostname) or \
00093                (host == None and self.dnssd_hostname == None) or \
00094                (dnssdhost == None and self._network_host == None):
00095                 raise ValueError
00096         else:
00097             (mfg, mdl) = self._canonical_id (device)
00098             if self.devices == None:
00099                 self.mfg = mfg
00100                 self.mdl = mdl
00101                 self.mfg_lower = mfg.lower ()
00102                 self.mdl_lower = mdl.lower ()
00103                 self.sn = device.id_dict.get ('SN', '')
00104                 self.devices = []
00105             else:
00106                 def nicest (a, b):
00107                     def count_lower (s):
00108                         l = s.lower ()
00109                         n = 0
00110                         for i in xrange (len (s)):
00111                             if l[i] != s[i]:
00112                                 n += 1
00113                         return n
00114                     if count_lower (b) < count_lower (a):
00115                         return b
00116                     return a
00117 
00118                 self.mfg = nicest (self.mfg, mfg)
00119                 self.mdl = nicest (self.mdl, mdl)
00120 
00121                 sn = device.id_dict.get ('SN', '')
00122                 if sn != '' and self.sn != '' and sn != self.sn:
00123                     raise ValueError
00124 
00125         if device.type == "socket":
00126             # Remove default port to more easily find duplicate URIs
00127             device.uri = device.uri.replace (":9100", "")
00128         for d in self.devices:
00129             if d.uri == device.uri:
00130                 return
00131 
00132         self.devices.append (device)
00133         self.devices.sort ()
00134 
00135         if (not self._network_host or not self.dnssd_hostname) and \
00136            device.device_class == "network":
00137             # We just added a network device.
00138             self._network_host, dnssdhost = \
00139                 self._get_host_from_uri (device.uri)
00140             if dnssdhost:
00141                 self.dnssd_hostname = dnssdhost;
00142 
00143         if (hasattr (device, 'address') and self._network_host == None):
00144             if device.address:
00145                 self._network_host = device.address
00146         if (hasattr (device, 'hostname') and self.dnssd_hostname == None):
00147             if device.hostname:
00148                 self.dnssd_hostname = device.hostname

Here is the call graph for this function:

def PhysicalDevice.PhysicalDevice.get_data (   self,
  key 
)

Definition at line 198 of file PhysicalDevice.py.

00198 
00199     def get_data (self, key):
00200         return self._user_data.get (key)

Definition at line 149 of file PhysicalDevice.py.

00149 
00150     def get_devices (self):
00151         return self.devices

Definition at line 152 of file PhysicalDevice.py.

00152 
00153     def get_info (self):
00154         # If the manufacturer/model is not known, or useless (in the
00155         # case of the hpfax backend or a dnssd URI pointing to a remote
00156         # CUPS queue), show the device-info field instead.
00157         if (self.devices[0].uri.startswith('ipp:') and \
00158             self.devices[0].uri.find('/printers/') != -1) or \
00159            ((self.devices[0].uri.startswith('dnssd:') or \
00160              self.devices[0].uri.startswith('mdns:')) and \
00161             self.devices[0].uri.endswith('/cups')):
00162             if not self.dnssd_hostname:
00163                 info = "%s" % self._network_host
00164             elif not self._network_host or self._network_host.find(":") != -1:
00165                 info = "%s" % self.dnssd_hostname
00166             else:
00167                 if self._network_host != self.dnssd_hostname:
00168                     info = "%s (%s)" % (self.dnssd_hostname, self._network_host)
00169                 else:
00170                     info = "%s" % self._network_host
00171         elif self.mfg == '' or \
00172            (self.mfg == "HP" and self.mdl.startswith("Fax")):
00173             info = self._ppdippstr.get (self.devices[0].info)
00174         else:
00175             info = "%s %s" % (self.mfg, self.mdl)
00176         if ((self._network_host and len (self._network_host) > 0) or \
00177             (self.dnssd_hostname and len (self.dnssd_hostname) > 0)) and not \
00178             ((self.devices[0].uri.startswith('dnssd:') or \
00179               self.devices[0].uri.startswith('mdns:')) and \
00180               self.devices[0].uri.endswith('/cups')) and \
00181             (not self._network_host or \
00182              info.find(self._network_host) == -1) and \
00183             (not self.dnssd_hostname or \
00184              info.find(self.dnssd_hostname) == -1):
00185             if not self.dnssd_hostname:
00186                 info += " (%s)" % self._network_host
00187             elif not self._network_host:
00188                 info += " (%s)" % self.dnssd_hostname
00189             else:
00190                 info += " (%s, %s)" % (self.dnssd_hostname, self._network_host)
00191         elif len (self.sn) > 0:
00192             info += " (%s)" % self.sn
00193         return info

def PhysicalDevice.PhysicalDevice.set_data (   self,
  key,
  value 
)

Definition at line 195 of file PhysicalDevice.py.

00195 
00196     def set_data (self, key, value):
00197         self._user_data[key] = value


Member Data Documentation

Definition at line 30 of file PhysicalDevice.py.

Definition at line 34 of file PhysicalDevice.py.

Definition at line 33 of file PhysicalDevice.py.

Definition at line 29 of file PhysicalDevice.py.

Definition at line 31 of file PhysicalDevice.py.

Definition at line 99 of file PhysicalDevice.py.

Definition at line 101 of file PhysicalDevice.py.

Definition at line 98 of file PhysicalDevice.py.

Definition at line 100 of file PhysicalDevice.py.

Definition at line 102 of file PhysicalDevice.py.


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