Changeset 3052

Show
Ignore:
Timestamp:
11/08/06 23:44:53 (17 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.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkbcodes

    r2829 r3052  
    107107            billingcodes = self.storage.getMatchingBillingCodes(",".join(names)) 
    108108            if not billingcodes : 
     109                if not options["list"] : 
     110                    percent.display("\n") 
    109111                raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) 
    110112            if not options["list"] :     
  • 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 : 
  • pykota/trunk/bin/pkusers

    r2937 r3052  
    215215            entries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names)) 
    216216            if not entries : 
     217                if not options["list"] : 
     218                    percent.display("\n") 
    217219                raise PyKotaCommandLineError, _("There's no %s matching %s") % (_(suffix.lower()), " ".join(names)) 
    218220            if not options["list"] :     
  • pykota/trunk/NEWS

    r3050 r3052  
    2424    - 1.25alpha15 (2006-11-06) :    
    2525     
     26        - pkprinters --add and --delete now automatically reroutes CUPS 
     27          print queues through PyKota or through CUPS only. 
     28           
    2629        - Fixed date and time parsing problems. 
    2730