Index: /pykota/trunk/bin/pkbcodes
===================================================================
--- /pykota/trunk/bin/pkbcodes (revision 2829)
+++ /pykota/trunk/bin/pkbcodes (revision 3052)
@@ -107,4 +107,6 @@
             billingcodes = self.storage.getMatchingBillingCodes(",".join(names))
             if not billingcodes :
+                if not options["list"] :
+                    percent.display("\n")
                 raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names)
             if not options["list"] :    
Index: /pykota/trunk/bin/pkusers
===================================================================
--- /pykota/trunk/bin/pkusers (revision 2937)
+++ /pykota/trunk/bin/pkusers (revision 3052)
@@ -215,4 +215,6 @@
             entries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names))
             if not entries :
+                if not options["list"] :
+                    percent.display("\n")
                 raise PyKotaCommandLineError, _("There's no %s matching %s") % (_(suffix.lower()), " ".join(names))
             if not options["list"] :    
Index: /pykota/trunk/bin/pkprinters
===================================================================
--- /pykota/trunk/bin/pkprinters (revision 3051)
+++ /pykota/trunk/bin/pkprinters (revision 3052)
@@ -149,4 +149,6 @@
     def getPrinterDeviceURI(self, printername) :            
         """Returns the Device URI attribute for a particular printer."""
+        if not printername :
+            return ""
         cups = pkipplib.CUPS()
         req = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES)
@@ -157,7 +159,7 @@
             return ""
         
-    def isPrinterCaptured(self, printername) :            
+    def isPrinterCaptured(self, printername=None, deviceuri=None) :
         """Returns True if the printer is already redirected through PyKota's backend, else False."""
-        if self.getPrinterDeviceURI(printername).find("cupspykota:") != -1 :
+        if (deviceuri or self.getPrinterDeviceURI(printername)).find("cupspykota:") != -1 :
             return True
         else :    
@@ -179,4 +181,6 @@
             printers = self.storage.getMatchingPrinters(",".join(names))
             if not printers :
+                if not options["list"] :
+                    percent.display("\n")
                 raise PyKotaCommandLineError, _("There's no printer matching %s") % " ".join(names)
             if not options["list"] :    
@@ -198,4 +202,16 @@
             percent.display("\n%s..." % _("Deletion"))
             self.storage.deleteManyPrinters(printers)
+            percent.display("\n%s...\n" % _("Rerouting printers to CUPS"))
+            for printer in printers :
+                uri = self.getPrinterDeviceURI(printer.Name)
+                if self.isPrinterCaptured(deviceuri=uri) :
+                     newuri = uri.replace("cupspykota:", "")
+                     if newuri.startswith("//") :
+                         newuri = newuri[2:]
+                     self.regainPriv() # to avoid having to enter password.
+                     os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri))
+                     self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri))
+                     self.dropPriv()    
+                percent.oneMore()
             percent.display("\n")
         else :
@@ -251,4 +267,13 @@
                                            nopassthrough, maxjobsize)
                             oldprinter = self.storage.addPrinter(printer)               
+                            
+                            uri = self.getPrinterDeviceURI(printer.Name)
+                            if not self.isPrinterCaptured(deviceuri=uri) :
+                                 newuri = "cupspykota://%s" % uri
+                                 self.regainPriv() # to avoid having to enter password.
+                                 os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri))
+                                 self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri))
+                                 self.dropPriv()
+                                     
                             if oldprinter is not None :
                                 if skipexisting :
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 3050)
+++ /pykota/trunk/NEWS (revision 3052)
@@ -24,4 +24,7 @@
     - 1.25alpha15 (2006-11-06) :   
     
+        - pkprinters --add and --delete now automatically reroutes CUPS
+          print queues through PyKota or through CUPS only.
+          
         - Fixed date and time parsing problems.
         
