Back to index

system-config-printer  1.3.9+20120706
Classes | Functions
cupshelpers.xmldriverprefs Namespace Reference

Classes

class  DeviceIDMatch
class  DriverType
class  DriverTypes
class  PrinterType
class  PreferenceOrder

Functions

def PreferredDrivers
def test

Function Documentation

Definition at line 29 of file xmldriverprefs.py.

00029 
00030 def PreferredDrivers (filename):
00031     preferreddrivers = xml.etree.ElementTree.XML (file (filename).read ())
00032     return preferreddrivers.getchildren()

def cupshelpers.xmldriverprefs.test (   xml_path = None,
  attached = False,
  deviceid = None,
  debug = False 
)

Definition at line 510 of file xmldriverprefs.py.

00510 
00511 def test (xml_path=None, attached=False, deviceid=None, debug=False):
00512     import cups
00513     import locale
00514     import ppds
00515     from pprint import pprint
00516     from time import time
00517     import os.path
00518 
00519     if debug:
00520         def debugprint (x):
00521             print x
00522 
00523         ppds.set_debugprint_fn (debugprint)
00524             
00525     locale.setlocale (locale.LC_ALL, "")
00526     encoding = locale.getlocale (locale.LC_CTYPE)[1]
00527     if xml_path == None:
00528         xml_path = os.path.join (os.path.join (os.path.dirname (__file__),
00529                                                ".."),
00530                                  "xml")
00531 
00532     os.environ["CUPSHELPERS_XMLDIR"] = xml_path
00533     xml_path = os.path.join (xml_path, "preferreddrivers.xml")
00534     loadstart = time ()
00535     (xmldrivertypes, xmlpreferenceorder) = PreferredDrivers (xml_path)
00536     drivertypes = DriverTypes ()
00537     drivertypes.load (xmldrivertypes)
00538 
00539     preforder = PreferenceOrder ()
00540     preforder.load (xmlpreferenceorder)
00541     loadtime = time () - loadstart
00542     if debug:
00543         print "Time to load %s: %.3fs" % (xml_path, loadtime)
00544 
00545     c = cups.Connection ()
00546     try:
00547         cupsppds = c.getPPDs2 ()
00548     except AttributeError:
00549         # getPPDs2 requires pycups >= 1.9.52 
00550         cupsppds = c.getPPDs ()
00551 
00552     ppdfinder = ppds.PPDs (cupsppds)
00553 
00554     if attached or deviceid:
00555         if attached:
00556             cups.setUser ("root")
00557             devices = c.getDevices ()
00558         else:
00559             devid = parseDeviceID (deviceid)
00560             devices = { "xxx://yyy":
00561                             { "device-id": deviceid,
00562                               "device-make-and-model": "%s %s" % (devid["MFG"],
00563                                                                   devid["MDL"])
00564                               }
00565                         }
00566 
00567         for uri, device in devices.iteritems ():
00568             if uri.find (":") == -1:
00569                 continue
00570 
00571             devid = device.get ("device-id", "")
00572             if isinstance (devid, list):
00573                 devid = devid[0]
00574 
00575             if not devid:
00576                 continue
00577 
00578             if not uri.startswith ("xxx:"):
00579                 print uri
00580 
00581             id_dict = parseDeviceID (devid)
00582             fit = ppdfinder.getPPDNamesFromDeviceID (id_dict["MFG"],
00583                                                      id_dict["MDL"],
00584                                                      id_dict["DES"],
00585                                                      id_dict["CMD"],
00586                                                      uri)
00587 
00588             mm = device.get ("device-make-and-model", "")
00589             orderedtypes = preforder.get_ordered_types (drivertypes,
00590                                                         mm, id_dict)
00591 
00592             ppds = {}
00593             for ppdname in fit.keys ():
00594                 ppds[ppdname] = ppdfinder.getInfoFromPPDName (ppdname)
00595 
00596             orderedppds = drivertypes.get_ordered_ppdnames (orderedtypes,
00597                                                             ppds,
00598                                                             fit)
00599             i = 1
00600             for t, ppd in orderedppds:
00601                 print "%d  %s\n    (%s, %s)" % (i, ppd, t, fit[ppd])
00602                 i += 1
00603     else:
00604         for make in ppdfinder.getMakes ():
00605             for model in ppdfinder.getModels (make):
00606                 ppdsdict = ppdfinder.getInfoFromModel (make, model)
00607                 mm = make + " " + model
00608                 orderedtypes = preforder.get_ordered_types (drivertypes,
00609                                                             mm, None)
00610 
00611                 fit = {}
00612                 for ppdname in ppdsdict.keys ():
00613                     fit[ppdname] = DriverType.FIT_CLOSE
00614 
00615                 orderedppds = drivertypes.get_ordered_ppdnames (orderedtypes,
00616                                                                 ppdsdict, fit)
00617                 print mm.encode (encoding) + ":"
00618                 i = 1
00619                 for t, ppd in orderedppds:
00620                     print "%d  %s\n    (%s)" % (i, ppd, t)
00621                     i += 1
00622 
00623                 print

Here is the call graph for this function: