Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1658)
+++ /pykota/trunk/setup.py (revision 1717)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.50  2004/09/14 22:29:12  jalet
+# First version of dumpykota. Works fine but only with PostgreSQL backend
+# for now.
+#
 # Revision 1.49  2004/07/28 13:00:02  jalet
 # Now takes care of .sxi and .sxc files if any
@@ -473,5 +477,5 @@
       url = "http://www.librelogiciel.com/software/",
       packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
-      scripts = [ "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
+      scripts = [ "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
       data_files = data_files)
 
Index: /pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/pgstorage.py (revision 1520)
+++ /pykota/trunk/pykota/storages/pgstorage.py (revision 1717)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.37  2004/09/14 22:29:12  jalet
+# First version of dumpykota. Works fine but only with PostgreSQL backend
+# for now.
+#
 # Revision 1.36  2004/06/03 23:14:11  jalet
 # Now stores the job's size in bytes in the database.
@@ -196,6 +200,6 @@
         self.tool.logdebug("Transaction aborted.")
         
-    def doSearch(self, query) :
-        """Does a search query."""
+    def doRawSearch(self, query) :
+        """Does a raw search query."""
         query = query.strip()    
         if not query.endswith(';') :    
@@ -207,7 +211,12 @@
             raise PyKotaStorageError, msg
         else :    
-            if (result is not None) and (result.ntuples() > 0) : 
-                return result.dictresult()
+            return result
             
+    def doSearch(self, query) :        
+        """Does a search query."""
+        result = self.doRawSearch(query)
+        if (result is not None) and (result.ntuples() > 0) : 
+            return result.dictresult()
+        
     def doModify(self, query) :
         """Does a (possibly multiple) modify query."""
Index: /pykota/trunk/pykota/storages/sql.py
===================================================================
--- /pykota/trunk/pykota/storages/sql.py (revision 1711)
+++ /pykota/trunk/pykota/storages/sql.py (revision 1717)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.45  2004/09/14 22:29:13  jalet
+# First version of dumpykota. Works fine but only with PostgreSQL backend
+# for now.
+#
 # Revision 1.44  2004/09/10 21:32:54  jalet
 # Small fixes for incomplete entry intialization
@@ -65,4 +69,46 @@
 
 class SQLStorage :
+    def prepareRawResult(self, result) :
+        """Prepares a raw result by including the headers."""
+        if result.ntuples() > 0 :
+            entries = [result.listfields()]
+            entries.extend(result.getresult())
+            return entries
+        
+    def extractPrinters(self) :
+        """Extracts all printer records."""
+        result = self.doRawSearch("SELECT * FROM printers")
+        return self.prepareRawResult(result)
+        
+    def extractUsers(self) :
+        """Extracts all user records."""
+        result = self.doRawSearch("SELECT * FROM users")
+        return self.prepareRawResult(result)
+        
+    def extractGroups(self) :
+        """Extracts all group records."""
+        result = self.doRawSearch("SELECT * FROM groups")
+        return self.prepareRawResult(result)
+        
+    def extractPayments(self) :
+        """Extracts all payment records."""
+        result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid")
+        return self.prepareRawResult(result)
+        
+    def extractUpquotas(self) :
+        """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")
+        return self.prepareRawResult(result)
+        
+    def extractGpquotas(self) :
+        """Extracts all grouppquota records."""
+        result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.* FROM groups,printers,grouppquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid")
+        return self.prepareRawResult(result)
+        
+    def extractHistory(self) :
+        """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")
+        return self.prepareRawResult(result)
+        
     def getAllUsersNames(self) :    
         """Extracts all user names."""
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1713)
+++ /pykota/trunk/pykota/version.py (revision 1717)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.20alpha10_unofficial"
+__version__ = "1.20alpha11_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/dumpykota
===================================================================
--- /pykota/trunk/bin/dumpykota (revision 1583)
+++ /pykota/trunk/bin/dumpykota (revision 1717)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.2  2004/09/14 22:29:12  jalet
+# First version of dumpykota. Works fine but only with PostgreSQL backend
+# for now.
+#
 # Revision 1.1  2004/07/01 19:22:37  jalet
 # First draft of dumpykota
@@ -52,7 +56,5 @@
   -h | --help          Prints this message then exits.
   
-  -d | --data type     Dumps 'type' datas. When not specified, the
-                       default is to dump the jobs history data.
-                       Allowed types are :
+  -d | --data type     Dumps 'type' datas. Allowed types are :
                        
                          - history : dumps the jobs history.
@@ -62,4 +64,8 @@
                          - uquotas : dump user quotas.
                          - gquotas : dump user groups quotas.
+                         - payments : dumps user payments.
+                         
+                       NB : the -d | --data command line option   
+                       is MANDATORY.
   
   -f | --format fmt    Dumps datas in the 'fmt' format. When not specified,
@@ -72,29 +78,4 @@
                          - tsv : separate datas with tabs
   
-  -p | --printer p     Only dumps datas concerning printer 'p'.
-                       Actually 'p' can use wildcards characters to select
-                       only some printers. The default value is *, meaning
-                       all printers.
-                       You can specify several names or wildcards, 
-                       by separating them with commas.
-                       
-  -u | --user u        Only dumps datas concerning user 'u'.
-                       Actually 'u' can use wildcards characters to select
-                       only some users. The default value is *, meaning
-                       all users.
-                       You can specify several names or wildcards, 
-                       by separating them with commas.
-                       
-  -g | --group g       Only dumps datas concerning group 'g'.
-                       Actually 'g' can use wildcards characters to select
-                       only some groups. The default value is *, meaning
-                       all groups.
-                       You can specify several names or wildcards, 
-                       by separating them with commas.
-  
-  If launched by a non-root user, additionnal arguments representing
-  users or groups names are ignored, and only the current user/group
-  is reported.
-
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -115,39 +96,53 @@
 class DumPyKota(PyKotaTool) :        
     """A class for dumpykota."""
-    def main(self, ugnames, options) :
+    def main(self, arguments, options) :
         """Print Quota Data Dumper."""
-        uid = os.geteuid()
-        if not uid :
-            # root user
-            if not ugnames :
-                # no username, means all usernames
-                ugnames = [ "*" ]
-        else :        
-            # not the root user
-            # reports only the current user
-            username = pwd.getpwuid(uid)[0]
-            if options["data"] == "groups" :
-                user = self.storage.getUser(username)
-                if user.Exists :
-                    ugnames = [ g.Name for g in self.storage.getUserGroups(user) ]
-                else :    
-                    ugnames = [ ]
-            else :
-                ugnames = [ username ]
+        datatype = options["data"]
+        if datatype not in [ "history",
+                             "users",
+                             "groups",
+                             "printers",
+                             "upquotas",
+                             "gpquotas",
+                             "payments",
+                           ] :
+            raise PyKotaToolError, _("Invalid modifier [%s] for --data command line option, see help.") % datatype
+                    
+        format = options["format"]
+        if format not in [ "csv",
+                           "ssv",
+                           "tsv",
+                         ] :
+            raise PyKotaToolError, _("Invalid modifier [%s] for --format command line option, see help.") % datatype
+            
+        entries = getattr(self.storage, "extract%s" % datatype.title())()    
+        getattr(self, "dump%s" % format.title())(entries)
+        return 0
         
-        printers = self.storage.getMatchingPrinters(options["printer"])
-        if not printers :
-            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"]
-            
-        # TODO : insert code here !    
-        raise PyKotaToolError, "Not implemented"
-                    
+    def dumpWithSeparator(self, separator, entries) :    
+        """Dumps datas with a separator."""
+        for entry in entries :
+            line = separator.join([ '"%s"' % field for field in entry ])
+            print line
+        
+    def dumpCsv(self, entries) :    
+        """Dumps datas with a comma as the separator."""
+        self.dumpWithSeparator(",", entries)
+                           
+    def dumpSsv(self, entries) :    
+        """Dumps datas with a comma as the separator."""
+        self.dumpWithSeparator(";", entries)
+                           
+    def dumpTsv(self, entries) :    
+        """Dumps datas with a comma as the separator."""
+        self.dumpWithSeparator("\t", entries)
+                           
 if __name__ == "__main__" : 
     try :
         defaults = { \
-                     "printer" : "*", \
+                     "format" : "csv", \
                    }
-        short_options = "vhd:f:p:u:g:"
-        long_options = ["help", "version", "data=", "format=", "printer=", "user=", "group="]
+        short_options = "vhd:f:"
+        long_options = ["help", "version", "data=", "format="]
         
         # Initializes the command line tool
@@ -160,7 +155,6 @@
         options["help"] = options["h"] or options["help"]
         options["version"] = options["v"] or options["version"]
-        options["users"] = options["u"] or options["users"]
-        options["groups"] = options["g"] or options["groups"]
-        options["printer"] = options["P"] or options["printer"] or defaults["printer"]
+        options["data"] = options["d"] or options["data"]
+        options["format"] = options["f"] or options["format"] or defaults["format"]
         
         if options["help"] :
@@ -168,7 +162,9 @@
         elif options["version"] :
             dumper.display_version_and_quit()
-        elif options["users"] and options["groups"] :    
-            raise PyKotaToolError, _("incompatible options, see help.")
+        elif options["data"] is None :    
+            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 :        
@@ -176,5 +172,5 @@
     except :
         try :
-            dumper.crashed("repykota failed")
+            dumper.crashed("dumpykota failed")
         except :    
             pass
Index: /pykota/trunk/MANIFEST.in
===================================================================
--- /pykota/trunk/MANIFEST.in (revision 1668)
+++ /pykota/trunk/MANIFEST.in (revision 1717)
@@ -1,3 +1,3 @@
-include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README
+include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README
 recursive-include po README *.sh *.po *.mo *.pot
 recursive-include man README *.sh *.1
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1713)
+++ /pykota/trunk/NEWS (revision 1717)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.20alpha11 : 
+    
+        - Generic data dumper 'dumpykota' introduced.
+          Works only with PostgreSQL backend for now.
+          
     - 1.20alpha10 :
     
