Index: /pykota/trunk/pykota/config.py
===================================================================
--- /pykota/trunk/pykota/config.py (revision 713)
+++ /pykota/trunk/pykota/config.py (revision 731)
@@ -15,4 +15,7 @@
 #
 # $Log$
+# Revision 1.5  2003/02/06 23:58:05  jalet
+# repykota should be ok
+#
 # Revision 1.4  2003/02/06 09:19:02  jalet
 # More robust behavior (hopefully) when the user or printer is not managed
@@ -140,3 +143,7 @@
     def getGraceDelay(self) :    
         """Returns the grace delay in days."""
-        return int(self.config.get("global", "gracedelay"))
+        gd = self.config.get("global", "gracedelay")
+        try :
+            return int(gd)
+        except ValueError :    
+            raise PyKotaConfigError, "Invalid grace delay %s" % gd
Index: /pykota/trunk/bin/repykota
===================================================================
--- /pykota/trunk/bin/repykota (revision 696)
+++ /pykota/trunk/bin/repykota (revision 731)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
 
-# PyKota Print Quota Reporter
+# PyKota Print Quota Reports generator
 #
 # PyKota - Print Quotas for CUPS
@@ -17,8 +17,145 @@
 #
 # $Log$
-# Revision 1.1  2003/02/05 21:41:09  jalet
-# Skeletons added for all command line tools
+# Revision 1.2  2003/02/06 23:58:05  jalet
+# repykota should be ok
 #
 #
 #
 
+import sys
+
+from mx import DateTime
+
+from pykota import version
+from pykota.tool import PyKotaTool, PyKotaToolError
+
+__doc__ = """repykota v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres
+
+Generates print quota reports.
+
+command line usage :
+
+  repykota [options] 
+
+options :
+
+  -v | --version       Prints repykota's version number then exits.
+  -h | --help          Prints this message then exits.
+  
+  -u | --users         Generates a report on users quota, this is 
+                       the default.
+  
+  -g | --groups        Generates a report on group quota instead of users.
+  
+  -P | --printer p     Report quotas on this printer only. Actually p can
+                       use wildcards characters to select only
+                       some printers. The default value is *, meaning
+                       all printers.
+  
+examples :                              
+
+  $ repykota --printer lp
+  
+  This will print the quota status for all users who user the lp printer.
+
+  $ repykota 
+  
+  This will print the quota status for all users on all printers.
+
+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
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+Please e-mail bugs to: %s""" % (version.__version__, version.__author__)
+        
+class RePyKota(PyKotaTool) :        
+    """A class for repykota."""
+    def main(self, options) :
+        """Print Quota reports generator."""
+        printernames = self.storage.getMatchingPrinters(options["printer"])
+        if not printernames :
+            raise PyKotaToolError, "There's no printer matching %s" % options["printer"]
+        for printer in printernames :
+            print "*** Report for %s quota on printer %s" % ((options["users"] and "user") or "group", printer)
+            print "Page grace time: %idays" % self.config.getGraceDelay()
+            if options["users"] :
+                print "User            used    soft    hard  grace"
+                print "-------------------------------------------"
+                for name in self.storage.getPrinterUsers(printer) :
+                    quota = self.storage.getUserPQuota(name, printer)
+                    self.printQuota(name, quota)
+            else :
+                print "Group           used    soft    hard  grace"
+                print "-------------------------------------------"
+                for name in self.storage.getPrinterGroups(printer) :
+                    quota = self.storage.getGroupPQuota(name, printer) 
+                    self.printQuota(name, quota)
+                        
+    def printQuota(self, name, quota) :
+        """Prints the quota information."""
+        if quota is not None :
+            pagecounter = quota["pagecounter"]
+            softlimit = quota["softlimit"] or 0
+            hardlimit = quota["hardlimit"] or 0
+            datelimit = quota["datelimit"]
+            if datelimit is not None :
+                now = DateTime.now()
+                datelimit = DateTime.ISO.ParseDateTime(datelimit)
+                if datelimit <= now :
+                    datelimit = "DENY"
+            else :    
+                datelimit = ""
+            reached = ((pagecounter >= softlimit) and "+") or "-"
+            print "%-10.10s %c %7i %7i %7i %s" % (name, reached, pagecounter, softlimit, hardlimit, datelimit)
+        
+                    
+if __name__ == "__main__" : 
+    try :
+        defaults = { \
+                     "users"  : 1, \
+                     "groups" : 0, \
+                     "printer" : "*", \
+                   }
+        short_options = "vhugP:"
+        long_options = ["help", "version", "users", "groups", "printer="]
+        
+        # Initializes the command line tool
+        reporter = RePyKota(doc=__doc__)
+        
+        # parse and checks the command line
+        (options, args) = reporter.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1)
+        
+        # sets long options
+        options["help"] = options["h"] or options["help"]
+        options["version"] = options["v"] or options["version"]
+        options["users"] = options["u"] or options["users"] or defaults["users"]
+        options["groups"] = options["g"] or options["groups"] or defaults["groups"]
+        options["printer"] = options["P"] or options["printer"] or defaults["printer"]
+        
+        if options["help"] :
+            reporter.display_usage_and_quit()
+        elif options["version"] :
+            reporter.display_version_and_quit()
+        elif options["users"] and options["groups"] :    
+            raise PyKotaToolError, "repykota: options --users and --groups are incompatible."
+        elif options["groups"] :    
+            raise PyKotaToolError, "repykota: options --groups is currently not implemented."
+        elif args :    
+            raise PyKotaToolError, "repykota: unused arguments [%s]. Aborting." % ", ".join(args)
+        else :
+            sys.exit(reporter.main(options))
+    except PyKotaToolError, msg :            
+        sys.stderr.write("%s\n" % msg)
+        sys.stderr.flush()
+        sys.exit(-1)
+
