Changeset 3051

Show
Ignore:
Timestamp:
11/08/06 22:59:55 (18 years ago)
Author:
jerome
Message:

Now pkprinters --list indicates if a particular printer is routed through PyKota or not.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r2829 r3051  
    3131from pykota.tool import Percent, PyKotaTool, PyKotaCommandLineError, crashed, N_ 
    3232from pykota.storage import StoragePrinter 
     33 
     34from pkipplib import pkipplib 
    3335 
    3436__doc__ = N_("""pkprinters v%(__version__)s (c) %(__years__)s %(__author__)s 
     
    145147                pgroup.addPrinterToGroup(printer)     
    146148                 
     149    def getPrinterDeviceURI(self, printername) :             
     150        """Returns the Device URI attribute for a particular printer.""" 
     151        cups = pkipplib.CUPS() 
     152        req = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES) 
     153        req.operation["printer-uri"] = ("uri", cups.identifierToURI("printers", printername)) 
     154        try : 
     155            return cups.doRequest(req).printer["device-uri"][0][1] 
     156        except :     
     157            return "" 
     158         
     159    def isPrinterCaptured(self, printername) :             
     160        """Returns True if the printer is already redirected through PyKota's backend, else False.""" 
     161        if self.getPrinterDeviceURI(printername).find("cupspykota:") != -1 : 
     162            return True 
     163        else :     
     164            return False 
     165         
    147166    def main(self, names, options) : 
    148167        """Manage printers.""" 
     
    172191                print "    %s" % (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF"))) 
    173192                print "    %s" % (_("Maximum job size : %s") % ((printer.MaxJobSize and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))) 
     193                print "    %s" % (_("Routed through PyKota : %s") % ((self.isPrinterCaptured(printer.Name) and _("YES")) or _("NO"))) 
    174194                if parents :  
    175195                    print "    %s %s" % (_("in"), parents)