Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1048)
+++ /pykota/trunk/setup.py (revision 1057)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.18  2003/07/03 09:44:00  jalet
+# Now includes the pykotme utility
+#
 # Revision 1.17  2003/06/30 12:46:15  jalet
 # Extracted reporting code.
@@ -232,5 +235,5 @@
       url = "http://www.librelogiciel.com/software/",
       packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
-      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ],
+      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme" ],
       data_files = data_files)
 
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1056)
+++ /pykota/trunk/pykota/version.py (revision 1057)
@@ -21,5 +21,5 @@
 #
 
-__version__ = "1.10_unofficial"
+__version__ = "1.11_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/pykotme
===================================================================
--- /pykota/trunk/bin/pykotme (revision 1057)
+++ /pykota/trunk/bin/pykotme (revision 1057)
@@ -0,0 +1,168 @@
+#! /usr/bin/env python
+
+# PyKota Print Quota Quote sender
+#
+# PyKota - Print Quotas for CUPS and LPRng
+#
+# (c) 2003 Jerome Alet <alet@librelogiciel.com>
+# 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.
+#
+# $Id$
+#
+# $Log$
+# Revision 1.1  2003/07/03 09:44:01  jalet
+# Now includes the pykotme utility
+#
+#
+#
+
+import sys
+import os
+import pwd
+import grp
+
+from pykota import version
+from pykota.tool import PyKotaTool, PyKotaToolError
+from pykota.config import PyKotaConfigError
+from pykota.storage import PyKotaStorageError
+
+__doc__ = """pykotme v%s (C) 2003 C@LL - Conseil Internet & Logiciels Libres
+
+Gives print quotes to users.
+
+command line usage :
+
+  pykotme  [options]  [files]
+
+options :
+
+  -v | --version       Prints pykotme's version number then exits.
+  -h | --help          Prints this message then exits.
+  
+  -P | --printer p     Gives a quote for this printer only. Actually p can
+                       use wildcards characters to select only
+                       some printers. The default value is *, meaning
+                       all printers.
+  
+examples :                              
+
+  $ pykotme --printer apple file1.ps file2.ps
+  
+  This will give a print quote to the current user. The quote will show
+  the price and size of a job consisting in file1.ps and file2.ps 
+  which would be sent to the apple printer.
+
+  $ pykotme 
+  
+  This will give a quote for a job consisting of what is on standard 
+  input. The quote will list the job size, and the price the job
+  would cost on each printer.
+
+
+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 PyKotMe(PyKotaTool) :        
+    """A class for pykotme."""
+    def main(self, files, options) :
+        """Gives print quotes."""
+        if not files :
+            files = [ sys.stdin ]
+            
+        nbpages = 0    
+        for filename in files :
+            if filename is sys.stdin :
+                stream = filename
+            else :
+                if filename == "-" :
+                    stream = sys.stdin
+                else :    
+                    try :
+                        stream = open(filename, "rb")
+                    except IOError, msg :    
+                        sys.stderr.write("%s\n" % msg)
+                        continue
+            nb = self.getNbPages(stream)
+            if nb is None :
+                sys.stderr.write(_("Unable to compute size of %s in number of pages.\n") % filename)
+            else :
+                nbpages += nb
+            if not (filename is sys.stdin) :        
+                stream.close()
+                
+        printers = self.storage.getMatchingPrinters(options["printer"])
+        if not printers :
+            raise PyKotaToolError, _("There's no printer matching %s") % options["printer"]
+        print _("Job size : %i pages") % nbpages    
+        for printer in printers :
+            cost = (nbpages * float(printer.PricePerPage or 0)) + float(printer.PricePerJob or 0)
+            print _("Cost on printer %s : %.2f") % (printer.Name, cost)
+            
+    def getNbPages(self, stream) :        
+        """Tries to compute the file's size in number of pages, the best we can."""
+        nbpages = [] # in case some user wants to put several %%Pages: entries in the file
+        for line in stream.xreadlines() :
+            line = line.strip()
+            if line.startswith("%%Pages: ") :
+                try :
+                    nbpages.append(int(line[9:]))
+                except ValueError :    
+                    pass
+        if nbpages :            
+            return max(nbpages)
+        
+if __name__ == "__main__" : 
+    try :
+        defaults = { \
+                     "printer" : "*", \
+                   }
+        short_options = "vhP:"
+        long_options = ["help", "version", "printer="]
+        
+        # Initializes the command line tool
+        sender = PyKotMe(doc=__doc__)
+        
+        # parse and checks the command line
+        (options, args) = sender.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["printer"] = options["P"] or options["printer"] or defaults["printer"]
+        
+        if options["help"] :
+            sender.display_usage_and_quit()
+        elif options["version"] :
+            sender.display_version_and_quit()
+        else :
+            sys.exit(sender.main(args, options))
+    except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError), msg :            
+        sys.stderr.write("%s\n" % msg)
+        sys.stderr.flush()
+        sys.exit(-1)
+
Index: /pykota/trunk/MANIFEST.in
===================================================================
--- /pykota/trunk/MANIFEST.in (revision 1015)
+++ /pykota/trunk/MANIFEST.in (revision 1057)
@@ -1,3 +1,3 @@
-include COPYING TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/pykota bin/edpykota bin/warnpykota bin/repykota bin/README
+include COPYING TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/pykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/README
 recursive-include po README *.po *.mo *.pot
 recursive-include man README *.1
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1056)
+++ /pykota/trunk/NEWS (revision 1057)
@@ -22,4 +22,9 @@
 PyKota NEWS :
 
+    - 1.11 :
+    
+        - Now includes the pykotme command line tool, to produce
+          printing quotes for users.
+          
     - 1.10 :
     
