Index: /pykota/trunk/bin/dumpykota
===================================================================
--- /pykota/trunk/bin/dumpykota (revision 1990)
+++ /pykota/trunk/bin/dumpykota (revision 1991)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.17  2004/12/21 15:50:00  jalet
+# The dumpykota command now supports extended filtering capabilities with
+# the PostgreSQL backend. LDAP doesn't yet support such possibilities.
+#
 # Revision 1.16  2004/12/21 14:45:31  jalet
 # Prepared dumpykota to accept the new --filter command line option. Some
@@ -106,5 +110,5 @@
 command line usage :
 
-  dumpykota [options] 
+  dumpykota [options] [filterexpr]
 
 options :
@@ -138,27 +142,26 @@
                          - 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
                        is the default value and means stdout.
                        WARNING : existing files are truncated !
+                       
+  Use the filter expressions 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.
   
 Examples :
@@ -173,7 +176,7 @@
   Dumps all users datas to the users.xml file.
   
-  $ dumpykota --data history --filter printername=HP2100
-  
-  Dumps the job history for printer HP2100 only.
+  $ dumpykota --data history printername=HP2100 username=jerome
+  
+  Dumps the job history for user jerome on printer HP2100 only.
   
 This program is free software; you can redistribute it and/or modify
@@ -201,18 +204,18 @@
             
         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 }
+        for filterexp in arguments :
+            if filterexp.strip() :
+                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.update({ filterkey : filtervalue })
             
         datatype = options["data"]
@@ -306,6 +309,6 @@
                      "output" : "-", \
                    }
-        short_options = "vhd:f:o:F:"
-        long_options = ["help", "version", "data=", "format=", "output=", "filter="]
+        short_options = "vhd:f:o:"
+        long_options = ["help", "version", "data=", "format=", "output="]
         
         # Initializes the command line tool
@@ -321,5 +324,4 @@
         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"] :
@@ -330,6 +332,4 @@
             raise PyKotaToolError, _("The -d | --data command line option is mandatory, see help.")
         else :
-            if args :
-                raise PyKotaToolError, _("Too many arguments, see help.")
             retcode = dumper.main(args, options)
     except SystemExit :        
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1980)
+++ /pykota/trunk/NEWS (revision 1991)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.21alpha14 :
+    
+        - dumpykota now supports extended filtering possibilities
+          with the PostgreSQL backend (LDAP support will come soon).
+          
     - 1.21alpha13 :
     
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 1990)
+++ /pykota/trunk/pykota/storages/sql.py (revision 1991)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.61  2004/12/21 15:49:59  jalet
+# The dumpykota command now supports extended filtering capabilities with
+# the PostgreSQL backend. LDAP doesn't yet support such possibilities.
+#
 # Revision 1.60  2004/12/21 14:45:31  jalet
 # Prepared dumpykota to accept the new --filter command line option. Some
@@ -136,47 +140,83 @@
             return entries
         
+    def createFilter(self, only) :    
+        """Returns the appropriate SQL filter."""
+        if only :
+            expressions = []
+            for (k, v) in only.items() :
+                expressions.append("%s=%s" % (k, self.doQuote(v)))
+            return " AND ".join(expressions)     
+        return ""        
+        
     def extractPrinters(self, extractonly={}) :
         """Extracts all printer records."""
-        result = self.doRawSearch("SELECT * FROM printers ORDER BY id ASC")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "WHERE %s" % thefilter
+        result = self.doRawSearch("SELECT * FROM printers %s ORDER BY id ASC" % thefilter)
         return self.prepareRawResult(result)
         
     def extractUsers(self, extractonly={}) :
         """Extracts all user records."""
-        result = self.doRawSearch("SELECT * FROM users ORDER BY id ASC")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "WHERE %s" % thefilter
+        result = self.doRawSearch("SELECT * FROM users %s ORDER BY id ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "WHERE %s" % thefilter
+        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) %s GROUP BY groups.id,groups.groupname,groups.limitby ORDER BY groups.id ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid %s ORDER BY payments.id ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        result = self.doRawSearch("SELECT users.username,printers.printername,userpquota.* FROM users,printers,userpquota WHERE users.id=userpquota.userid AND printers.id=userpquota.printerid %s ORDER BY userpquota.id ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        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) %s GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY grouppquota.id" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        result = self.doRawSearch("SELECT groups.groupname, users.username, groupsmembers.* FROM groups,users,groupsmembers WHERE users.id=groupsmembers.userid AND groups.id=groupsmembers.groupid %s ORDER BY groupsmembers.groupid, groupsmembers.userid ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        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 %s ORDER BY printergroupsmembers.groupid, printergroupsmembers.printerid ASC" % thefilter)
         return self.prepareRawResult(result)
         
     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")
+        thefilter = self.createFilter(extractonly)
+        if thefilter :
+            thefilter = "AND %s" % thefilter
+        result = self.doRawSearch("SELECT users.username,printers.printername,jobhistory.* FROM users,printers,jobhistory WHERE users.id=jobhistory.userid AND printers.id=jobhistory.printerid %s ORDER BY jobhistory.id ASC" % thefilter)
         return self.prepareRawResult(result)
         
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1980)
+++ /pykota/trunk/pykota/version.py (revision 1991)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.21alpha13_unofficial"
+__version__ = "1.21alpha14_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
