Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 1330)
+++ /pykota/trunk/pykota/storages/sql.py (revision 1332)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.36  2004/02/04 13:24:41  jalet
+# pkprinters can now remove printers from printers groups.
+#
 # Revision 1.35  2004/02/04 11:17:00  jalet
 # pkprinters command line tool added.
@@ -353,4 +356,8 @@
             self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
         
+    def removePrinterFromGroup(self, pgroup, printer) :
+        """Removes a printer from a printer group."""
+        self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
+        
     def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :    
         """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
Index: /pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/ldapstorage.py (revision 1330)
+++ /pykota/trunk/pykota/storages/ldapstorage.py (revision 1332)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.51  2004/02/04 13:24:41  jalet
+# pkprinters can now remove printers from printers groups.
+#
 # Revision 1.50  2004/02/04 11:17:00  jalet
 # pkprinters command line tool added.
@@ -871,4 +874,16 @@
             self.doModify(pgroup.ident, fields)         
             
+    def removePrinterFromGroup(self, pgroup, printer) :
+        """Removes a printer from a printer group."""
+        try :
+            pgroup.uniqueMember.remove(printer.ident)
+        except ValueError :    
+            pass
+        else :    
+            fields = {
+                       "uniqueMember" : pgroup.uniqueMember,
+                     }  
+            self.doModify(pgroup.ident, fields)         
+            
     def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :    
         """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
@@ -993,8 +1008,12 @@
             self.doDelete(ident)
         for parent in self.getParentPrinters(printer) :  
-            parent.uniqueMember.remove(printer.ident)
-            fields = {
-                       "uniqueMember" : parent.uniqueMember,
-                     }  
-            self.doModify(parent.ident, fields)         
+            try :
+                parent.uniqueMember.remove(printer.ident)
+            except ValueError :    
+                pass
+            else :    
+                fields = {
+                           "uniqueMember" : parent.uniqueMember,
+                         }  
+                self.doModify(parent.ident, fields)         
         self.doDelete(printer.ident)    
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 1330)
+++ /pykota/trunk/pykota/storage.py (revision 1332)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.40  2004/02/04 13:24:41  jalet
+# pkprinters can now remove printers from printers groups.
+#
 # Revision 1.39  2004/02/04 11:16:59  jalet
 # pkprinters command line tool added.
@@ -262,4 +265,10 @@
         if (printer not in self.parent.getParentPrinters(self)) and (printer.ident != self.ident) :
             self.parent.writePrinterToGroup(self, printer)
+            # TODO : reset cached value for printer parents, or add new parent to cached value
+            
+    def delPrinterFromGroup(self, printer) :    
+        """Deletes a printer from a printer group."""
+        if (printer in self.parent.getParentPrinters(self)) and (printer.ident != self.ident) :
+            self.parent.removePrinterFromGroup(self, printer)
             # TODO : reset cached value for printer parents, or add new parent to cached value
         
Index: /pykota/trunk/bin/pkprinters
===================================================================
--- /pykota/trunk/bin/pkprinters (revision 1331)
+++ /pykota/trunk/bin/pkprinters (revision 1332)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.3  2004/02/04 13:24:41  jalet
+# pkprinters can now remove printers from printers groups.
+#
 # Revision 1.2  2004/02/04 12:52:37  jalet
 # pkprinters' help
@@ -62,6 +65,6 @@
                        Floating point and negative values are allowed.
   
-  -g | --groups pg1[,pg2...] Adds the printer(s) to the printer groups
-                       pg1, pg2, etc... which must already exist.
+  -g | --groups pg1[,pg2...] Adds or Remove the printer(s) to the printer 
+                       groups pg1, pg2, etc... which must already exist.
                        A printer group is just like a normal printer,
                        only that it is usually unknown from the printing
@@ -73,4 +76,10 @@
                        is done on a printer and on all the printer groups
                        it belongs to.
+                       If the --remove option below is not used, the 
+                       default action is to add printers to the specified
+                       printer groups.
+                       
+  -r | --remove        In combination with the --groups option above,                       
+                       remove printers from the specified printers groups.
   
   printer1 through printerN can contain wildcards if the --add option 
@@ -96,4 +105,8 @@
   This will put all printers which name matches "hp*" into printers groups 
   Laser and HP, which MUST already exist.
+  
+  $ pkprinters --groups LexMark --remove hp2200
+  
+  This will remove the hp2200 printer from the LexMark printer group.
   
 This program is free software; you can redistribute it and/or modify
@@ -159,11 +172,14 @@
                 if options["groups"] :    
                     for pgroup in printersgroups :
-                        pgroup.addPrinterToGroup(printer)    
+                        if options["remove"] :
+                            pgroup.delPrinterFromGroup(printer)
+                        else :
+                            pgroup.addPrinterToGroup(printer)    
                      
 if __name__ == "__main__" : 
     retcode = 0
     try :
-        short_options = "hvac:dg:"
-        long_options = ["help", "version", "add", "charge=", "delete", "groups="]
+        short_options = "hvac:dg:r"
+        long_options = ["help", "version", "add", "charge=", "delete", "groups=", "remove"]
         
         # Initializes the command line tool
@@ -180,4 +196,5 @@
         options["delete"] = options["d"] or options["delete"] 
         options["groups"] = options["g"] or options["groups"]
+        options["remove"] = options["r"] or options["remove"]
         
         if options["help"] :
@@ -185,6 +202,8 @@
         elif options["version"] :
             manager.display_version_and_quit()
-        elif options["delete"] and (options["add"] or options["groups"] or options["charge"]) :    
+        elif options["delete"] and (options["add"] or options["groups"] or options["charge"] or options["remove"]) :    
             raise PyKotaToolError, _("incompatible options, see help.")
+        elif options["remove"] and not options["groups"] :    
+            raise PyKotaToolError, _("You have to pass printer groups names on the command line")
         elif not args :    
             raise PyKotaToolError, _("You have to pass printer names on the command line")
Index: /pykota/trunk/man/pkprinters.1
===================================================================
--- /pykota/trunk/man/pkprinters.1 (revision 1331)
+++ /pykota/trunk/man/pkprinters.1 (revision 1332)
@@ -32,6 +32,6 @@
 Floating point and negative values are allowed.
 .TP
-\fB\-g\fR | \fB\-\-groups\fR pg1[,pg2...] Adds the printer(s) to the printer groups
-pg1, pg2, etc... which must already exist.
+\fB\-g\fR | \fB\-\-groups\fR pg1[,pg2...] Adds or Remove the printer(s) to the printer
+groups pg1, pg2, etc... which must already exist.
 A printer group is just like a normal printer,
 only that it is usually unknown from the printing
@@ -43,4 +43,11 @@
 is done on a printer and on all the printer groups
 it belongs to.
+If the \fB\-\-remove\fR option below is not used, the
+default action is to add printers to the specified
+printer groups.
+.TP
+\fB\-r\fR | \fB\-\-remove\fR
+In combination with the \fB\-\-groups\fR option above,
+remove printers from the specified printers groups.
 .IP
 printer1 through printerN can contain wildcards if the \fB\-\-add\fR option
@@ -66,4 +73,8 @@
 This will put all printers which name matches "hp*" into printers groups
 Laser and HP, which MUST already exist.
+.IP
+\f(CW$ pkprinters --groups LexMark --remove hp2200\fR
+.IP
+This will remove the hp2200 printer from the LexMark printer group.
 .PP
 This program is free software; you can redistribute it and/or modify
