Index: pykota/trunk/bin/dumpykota
===================================================================
--- pykota/trunk/bin/dumpykota (revision 1809)
+++ pykota/trunk/bin/dumpykota (revision 1990)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.16  2004/12/21 14:45:31  jalet
+# Prepared dumpykota to accept the new --filter command line option. Some
+# additionnal work needs to be done in the backends though.
+#
 # Revision 1.15  2004/10/12 15:37:00  jalet
 # Now outputs the name of the offending user if a mere mortal tries to use
@@ -134,4 +138,23 @@
                          - xml : dump data as XML
                          
+  -F - | --filter exp  Uses the filter to extract only parts of the                          
+                       datas. Allowed filters are of the form :
+                       
+                         key=value
+                         
+                       Allowed keys for now are :  
+                       
+                         username       User's name
+                         groupname      Users group's name
+                         printername    Printer's name
+                         pgroupname     Printers group's name
+                         
+                       Contrary to other PyKota management tools, wildcard
+                       characters are not expanded, so you can't use them.
+                         
+                       NB : not all keys are allowed for each data type,
+                       so the result may be empty if you use a key not
+                       available for a particular data type.
+                         
   -o | --output fname  All datas will be dumped to the file instead of
                        to the standard output. The special '-' filename
@@ -149,4 +172,8 @@
   
   Dumps all users datas to the users.xml file.
+  
+  $ dumpykota --data history --filter printername=HP2100
+  
+  Dumps the job history for printer HP2100 only.
   
 This program is free software; you can redistribute it and/or modify
@@ -172,4 +199,20 @@
         if not self.config.isAdmin :
             raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command."))
+            
+        extractonly = {}
+        filterexp = options["filter"]    
+        if filterexp :
+            try :
+                (filterkey, filtervalue) = [part.strip() for part in filterexp.split("=")]
+                if filterkey not in [ "username",
+                                      "groupname",
+                                      "printername",
+                                      "pgroupname",
+                                    ] :
+                    raise ValueError                
+            except ValueError :    
+                raise PyKotaToolError, _("Invalid value [%s] for --filter command line option, see help.") % filterexp
+            else :    
+                extractonly = { filterkey : filtervalue }
             
         datatype = options["data"]
@@ -197,5 +240,5 @@
             raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.")
             
-        entries = getattr(self.storage, "extract%s" % datatype.title())()    
+        entries = getattr(self.storage, "extract%s" % datatype.title())(extractonly)    
         if entries :
             mustclose = 0    
@@ -263,6 +306,6 @@
                      "output" : "-", \
                    }
-        short_options = "vhd:f:o:"
-        long_options = ["help", "version", "data=", "format=", "output="]
+        short_options = "vhd:f:o:F:"
+        long_options = ["help", "version", "data=", "format=", "output=", "filter="]
         
         # Initializes the command line tool
@@ -278,4 +321,5 @@
         options["format"] = options["f"] or options["format"] or defaults["format"]
         options["output"] = options["o"] or options["output"] or defaults["output"]
+        options["filter"] = options["F"] or options["filter"]
         
         if options["help"] :
Index: pykota/trunk/pykota/storages/sql.py
===================================================================
--- pykota/trunk/pykota/storages/sql.py (revision 1875)
+++ pykota/trunk/pykota/storages/sql.py (revision 1990)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.60  2004/12/21 14:45:31  jalet
+# Prepared dumpykota to accept the new --filter command line option. Some
+# additionnal work needs to be done in the backends though.
+#
 # Revision 1.59  2004/10/25 14:12:25  jalet
 # For URGENT legal reasons (Italy), a new "privacy" directive was added to pykota.conf
@@ -132,45 +136,45 @@
             return entries
         
-    def extractPrinters(self) :
+    def extractPrinters(self, extractonly={}) :
         """Extracts all printer records."""
         result = self.doRawSearch("SELECT * FROM printers ORDER BY id ASC")
         return self.prepareRawResult(result)
         
-    def extractUsers(self) :
+    def extractUsers(self, extractonly={}) :
         """Extracts all user records."""
         result = self.doRawSearch("SELECT * FROM users ORDER BY id ASC")
         return self.prepareRawResult(result)
         
-    def extractGroups(self) :
+    def extractGroups(self, extractonly={}) :
         """Extracts all group records."""
         result = self.doRawSearch("SELECT groups.*,COALESCE(SUM(balance), 0) AS balance, COALESCE(SUM(lifetimepaid), 0) as lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) GROUP BY groups.id,groups.groupname,groups.limitby ORDER BY groups.id ASC")
         return self.prepareRawResult(result)
         
-    def extractPayments(self) :
+    def extractPayments(self, extractonly={}) :
         """Extracts all payment records."""
         result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid ORDER BY payments.id ASC")
         return self.prepareRawResult(result)
         
-    def extractUpquotas(self) :
+    def extractUpquotas(self, extractonly={}) :
         """Extracts all userpquota records."""
         result = self.doRawSearch("SELECT users.username,printers.printername,userpquota.* FROM users,printers,userpquota WHERE users.id=userpquota.userid AND printers.id=userpquota.printerid ORDER BY userpquota.id ASC")
         return self.prepareRawResult(result)
         
-    def extractGpquotas(self) :
+    def extractGpquotas(self, extractonly={}) :
         """Extracts all grouppquota records."""
         result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY grouppquota.id")
         return self.prepareRawResult(result)
         
-    def extractUmembers(self) :
+    def extractUmembers(self, extractonly={}) :
         """Extracts all user groups members."""
         result = self.doRawSearch("SELECT groups.groupname, users.username, groupsmembers.* FROM groups,users,groupsmembers WHERE users.id=groupsmembers.userid AND groups.id=groupsmembers.groupid ORDER BY groupsmembers.groupid, groupsmembers.userid ASC")
         return self.prepareRawResult(result)
         
-    def extractPmembers(self) :
+    def extractPmembers(self, extractonly={}) :
         """Extracts all printer groups members."""
         result = self.doRawSearch("SELECT p1.printername as pgroupname, p2.printername as printername, printergroupsmembers.* FROM printers p1, printers p2, printergroupsmembers WHERE p1.id=printergroupsmembers.groupid AND p2.id=printergroupsmembers.printerid ORDER BY printergroupsmembers.groupid, printergroupsmembers.printerid ASC")
         return self.prepareRawResult(result)
         
-    def extractHistory(self) :
+    def extractHistory(self, extractonly={}) :
         """Extracts all jobhistory records."""
         result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid ORDER BY jobhistory.id ASC")
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1969)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1990)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.90  2004/12/21 14:45:31  jalet
+# Prepared dumpykota to accept the new --filter command line option. Some
+# additionnal work needs to be done in the backends though.
+#
 # Revision 1.89  2004/12/02 22:27:11  jalet
 # Integrated and extended Stefan Wold's patch to store print quota entries
@@ -1396,5 +1400,5 @@
         self.doDelete(printer.ident)    
         
-    def extractPrinters(self) :
+    def extractPrinters(self, extractonly={}) :
         """Extracts all printer records."""
         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists]
@@ -1405,5 +1409,5 @@
             return result 
         
-    def extractUsers(self) :
+    def extractUsers(self, extractonly={}) :
         """Extracts all user records."""
         entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists]
@@ -1414,5 +1418,5 @@
             return result 
         
-    def extractGroups(self) :
+    def extractGroups(self, extractonly={}) :
         """Extracts all group records."""
         entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists]
@@ -1423,5 +1427,5 @@
             return result 
         
-    def extractPayments(self) :
+    def extractPayments(self, extractonly={}) :
         """Extracts all payment records."""
         entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames()] if u.Exists]
@@ -1433,5 +1437,5 @@
             return result        
         
-    def extractUpquotas(self) :
+    def extractUpquotas(self, extractonly={}) :
         """Extracts all userpquota records."""
         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists]
@@ -1443,5 +1447,5 @@
             return result
         
-    def extractGpquotas(self) :
+    def extractGpquotas(self, extractonly={}) :
         """Extracts all grouppquota records."""
         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists]
@@ -1453,5 +1457,5 @@
             return result
         
-    def extractUmembers(self) :
+    def extractUmembers(self, extractonly={}) :
         """Extracts all user groups members."""
         entries = [g for g in [self.getGroup(name) for name in self.getAllGroupsNames()] if g.Exists]
@@ -1463,5 +1467,5 @@
             return result        
                 
-    def extractPmembers(self) :
+    def extractPmembers(self, extractonly={}) :
         """Extracts all printer groups members."""
         entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames()] if p.Exists]
@@ -1473,5 +1477,5 @@
             return result        
         
-    def extractHistory(self) :
+    def extractHistory(self, extractonly={}) :
         """Extracts all jobhistory records."""
         entries = self.retrieveHistory(limit=None)
