Show
Ignore:
Timestamp:
11/08/06 23:44:53 (18 years ago)
Author:
jerome
Message:

Now pkprinters reroutes CUPS print queues through PyKota or
through CUPS only when adding or deleting printers in the
database.
Fixed some display uglyness in case no entry was found.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkprinters

    r3051 r3052  
    149149    def getPrinterDeviceURI(self, printername) :             
    150150        """Returns the Device URI attribute for a particular printer.""" 
     151        if not printername : 
     152            return "" 
    151153        cups = pkipplib.CUPS() 
    152154        req = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES) 
     
    157159            return "" 
    158160         
    159     def isPrinterCaptured(self, printername) :             
     161    def isPrinterCaptured(self, printername=None, deviceuri=None) : 
    160162        """Returns True if the printer is already redirected through PyKota's backend, else False.""" 
    161         if self.getPrinterDeviceURI(printername).find("cupspykota:") != -1 : 
     163        if (deviceuri or self.getPrinterDeviceURI(printername)).find("cupspykota:") != -1 : 
    162164            return True 
    163165        else :     
     
    179181            printers = self.storage.getMatchingPrinters(",".join(names)) 
    180182            if not printers : 
     183                if not options["list"] : 
     184                    percent.display("\n") 
    181185                raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names) 
    182186            if not options["list"] :     
     
    198202            percent.display("\n%s..." % _("Deletion")) 
    199203            self.storage.deleteManyPrinters(printers) 
     204            percent.display("\n%s...\n" % _("Rerouting printers to CUPS")) 
     205            for printer in printers : 
     206                uri = self.getPrinterDeviceURI(printer.Name) 
     207                if self.isPrinterCaptured(deviceuri=uri) : 
     208                     newuri = uri.replace("cupspykota:", "") 
     209                     if newuri.startswith("//") : 
     210                         newuri = newuri[2:] 
     211                     self.regainPriv() # to avoid having to enter password. 
     212                     os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri)) 
     213                     self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri)) 
     214                     self.dropPriv()     
     215                percent.oneMore() 
    200216            percent.display("\n") 
    201217        else : 
     
    251267                                           nopassthrough, maxjobsize) 
    252268                            oldprinter = self.storage.addPrinter(printer)                
     269                             
     270                            uri = self.getPrinterDeviceURI(printer.Name) 
     271                            if not self.isPrinterCaptured(deviceuri=uri) : 
     272                                 newuri = "cupspykota://%s" % uri 
     273                                 self.regainPriv() # to avoid having to enter password. 
     274                                 os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri)) 
     275                                 self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri)) 
     276                                 self.dropPriv() 
     277                                      
    253278                            if oldprinter is not None : 
    254279                                if skipexisting :