Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1733)
+++ /pykota/trunk/setup.py (revision 1758)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.52  2004/09/30 09:52:45  jalet
+# Initial release of autopykota. Reading help or manpage is greatly
+# encouraged !
+#
 # Revision 1.51  2004/09/21 21:31:35  jalet
 # Installation script now checks for availability of Python-SNMP (http://pysnmp.sf.net)
@@ -481,5 +485,5 @@
       url = "http://www.librelogiciel.com/software/",
       packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
-      scripts = [ "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
+      scripts = [ "bin/autopykota", "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/bin/autopykota
===================================================================
--- /pykota/trunk/bin/autopykota (revision 1758)
+++ /pykota/trunk/bin/autopykota (revision 1758)
@@ -0,0 +1,149 @@
+#! /usr/bin/env python
+# -*- coding: ISO-8859-15 -*-
+
+# autopykota : script to automate user creation in PyKota
+#
+# PyKota - Print Quotas for CUPS and LPRng
+#
+# (c) 2003-2004 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  2004/09/30 09:52:45  jalet
+# Initial release of autopykota. Reading help or manpage is greatly
+# encouraged !
+#
+#
+#
+
+import sys
+import os
+
+from pykota import version
+from pykota.tool import PyKotaTool, PyKotaToolError, crashed
+
+__doc__ = """autopykota v%s (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+A tool to automate user account creation and initial balance setting.
+
+THIS TOOL MUST NOT BE USED IF YOU WANT TO LIMIT YOUR USERS BY PAGE QUOTA !
+
+command line usage :
+
+  THIS TOOL MUST NOT BE USED FROM THE COMMAND LINE BUT ONLY AS PART
+  OF AN external policy IN pykota.conf
+  
+  THIS TOOL IS STILL EXPERIMENTAL. USE AT YOUR OWN RISK !!!
+  
+  autopykota { -i | --initbalance value } 
+
+options :
+
+  -v | --version       Prints edpykota's version number then exits.
+  -h | --help          Prints this message then exits.
+  
+  -i | --initbalance b Sets the user's account initial balance value to b.
+                       If the user already exists, actual balance is left
+                       unmodified.
+                       
+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 AutoPyKota(PyKotaTool) :
+    """A class for the automat."""
+    def main(self, arguments, options) :
+        """Main entry point."""
+        username = os.environ.get("PYKOTAUSERNAME")
+        printername = os.environ.get("PYKOTAPRINTERNAME")
+        if (username is None) or (printername is None) :
+            raise PyKotaToolError, "Either the username or the printername is undefined. Fatal Error."
+        else :
+            user = self.storage.getUser(username)
+            if user.Exists :
+                printer = self.storage.getPrinter(printername)
+                if printer.Exists :
+                    userpquota = self.storage.getUserPQuota(user, printer)
+                    if userpquota.Exists :
+                        self.logdebug("User %s's quota entry on printer %s already exists. Nothing to do." % (username, printername))
+                        return 0
+                    else :    
+                        self.logdebug("User %s already exists. Creating a quota entry for user %s on printer %s." % (username, username, printername))
+                        return os.system('/usr/bin/edpykota --add --printer "%s" "%s"' % (printername, username))
+                else :
+                    self.logdebug("User %s already exists. Printer %s doesn't exist. Creating printer %s and a quota entry for user %s on printer %s." % (username, printername, printername, username, printername))
+                    return os.system('/usr/bin/edpykota --add --printer "%s" "%s"' % (printername, username))
+            else :
+                if options["initbalance"] is None :
+                    raise PyKotaToolError, "User %s doesn't exist yet, but no initial balance value is given. Fatal Error." % username
+                else :
+                    self.logdebug("User %s doesn't exist yet. Creating user %s's account and quota entries on all existing printers." % (username, username))
+                    return os.system('/usr/bin/edpykota --add --limitby balance --balance "%s" "%s"' % (options["initbalance"], username))
+    
+if __name__ == "__main__" :    
+    retcode = 0
+    try :
+        defaults = { \
+                   }
+        short_options = "vhi:"
+        long_options = ["help", "version", "initbalance="]
+        
+        # Initializes the command line tool
+        automat = AutoPyKota(doc=__doc__)
+        
+        # parse and checks the command line
+        (options, args) = automat.parseCommandline(sys.argv[1:], short_options, long_options)
+        
+        # sets long options
+        options["help"] = options["h"] or options["help"]
+        options["version"] = options["v"] or options["version"]
+        options["initbalance"] = options["i"] or options["initbalance"] 
+        
+        if options["help"] :
+            automat.display_usage_and_quit()
+        elif options["version"] :
+            automat.display_version_and_quit()
+        elif args :    
+            raise PyKotaToolError, "autopykota doesn't accept non option arguments !"
+        else :
+            retcode = automat.main(args, options)
+    except SystemExit :        
+        pass
+    except :
+        try :
+            automat.crashed("autopykota failed")
+        except :    
+            crashed("autopykota failed")
+        retcode = -1
+
+    try :
+        automat.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: /pykota/trunk/MANIFEST.in
===================================================================
--- /pykota/trunk/MANIFEST.in (revision 1717)
+++ /pykota/trunk/MANIFEST.in (revision 1758)
@@ -1,3 +1,3 @@
-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
+include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh bin/autopykota 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/man/autopykota.1
===================================================================
--- /pykota/trunk/man/autopykota.1 (revision 1758)
+++ /pykota/trunk/man/autopykota.1 (revision 1758)
@@ -0,0 +1,46 @@
+.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.33.
+.TH AUTOPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
+.SH NAME
+autopykota \- manual page for autopykota 1.20alpha18_unofficial
+.SH DESCRIPTION
+autopykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+A tool to automate user account creation and initial balance setting.
+.PP
+THIS TOOL MUST NOT BE USED IF YOU WANT TO LIMIT YOUR USERS BY PAGE QUOTA !
+.PP
+command line usage :
+.IP
+THIS TOOL MUST NOT BE USED FROM THE COMMAND LINE BUT ONLY AS PART
+OF AN external policy IN pykota.conf
+.IP
+THIS TOOL IS STILL EXPERIMENTAL. USE AT YOUR OWN RISK !!!
+.IP
+autopykota { \fB\-i\fR | \fB\-\-initbalance\fR value }
+.PP
+options :
+.TP
+\fB\-v\fR | \fB\-\-version\fR
+Prints edpykota's version number then exits.
+.TP
+\fB\-h\fR | \fB\-\-help\fR
+Prints this message then exits.
+.TP
+\fB\-i\fR | \fB\-\-initbalance\fR b Sets the user's account initial balance value to b.
+If the user already exists, actual balance is left
+unmodified.
+.PP
+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.
+.PP
+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.
+.PP
+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.
+.PP
+Please e-mail bugs to: Jerome Alet - alet@librelogiciel.com
Index: /pykota/trunk/man/edpykota.1
===================================================================
--- /pykota/trunk/man/edpykota.1 (revision 1755)
+++ /pykota/trunk/man/edpykota.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH EDPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-edpykota \- manual page for edpykota 1.20alpha17_unofficial
+edpykota \- manual page for edpykota 1.20alpha18_unofficial
 .SH DESCRIPTION
-edpykota v1.20alpha17_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+edpykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 A Print Quota editor for PyKota.
 .PP
Index: /pykota/trunk/man/pkprinters.1
===================================================================
--- /pykota/trunk/man/pkprinters.1 (revision 1724)
+++ /pykota/trunk/man/pkprinters.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH PKPRINTERS "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-pkprinters \- manual page for pkprinters 1.20alpha12_unofficial
+pkprinters \- manual page for pkprinters 1.20alpha18_unofficial
 .SH DESCRIPTION
-pkprinters v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+pkprinters v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 A Printers Manager for PyKota.
 .PP
Index: /pykota/trunk/man/pykotme.1
===================================================================
--- /pykota/trunk/man/pykotme.1 (revision 1724)
+++ /pykota/trunk/man/pykotme.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH PYKOTME "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-pykotme \- manual page for pykotme 1.20alpha12_unofficial
+pykotme \- manual page for pykotme 1.20alpha18_unofficial
 .SH DESCRIPTION
-pykotme v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+pykotme v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 .PP
 Gives print quotes to users.
Index: /pykota/trunk/man/pykosd.1
===================================================================
--- /pykota/trunk/man/pykosd.1 (revision 1724)
+++ /pykota/trunk/man/pykosd.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH PYKOSD "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-pykosd \- manual page for pykosd 1.20alpha12_unofficial
+pykosd \- manual page for pykosd 1.20alpha18_unofficial
 .SH DESCRIPTION
-pykosd v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+pykosd v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 An OSD quota monitor for PyKota.
 .PP
Index: /pykota/trunk/man/dumpykota.1
===================================================================
--- /pykota/trunk/man/dumpykota.1 (revision 1724)
+++ /pykota/trunk/man/dumpykota.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH DUMPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-dumpykota \- manual page for dumpykota 1.20alpha12_unofficial
+dumpykota \- manual page for dumpykota 1.20alpha18_unofficial
 .SH DESCRIPTION
-dumpykota v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+dumpykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 .PP
 Dumps PyKota database's content.
Index: /pykota/trunk/man/pkhint.1
===================================================================
--- /pykota/trunk/man/pkhint.1 (revision 1724)
+++ /pykota/trunk/man/pkhint.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH PKHINT "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-pkhint \- manual page for pkhint 1.20alpha12_unofficial
+pkhint \- manual page for pkhint 1.20alpha18_unofficial
 .SH DESCRIPTION
-pkhint v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+pkhint v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 A tool to give hints on what accounting method is best for each printer.
 .PP
Index: /pykota/trunk/man/repykota.1
===================================================================
--- /pykota/trunk/man/repykota.1 (revision 1724)
+++ /pykota/trunk/man/repykota.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH REPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-repykota \- manual page for repykota 1.20alpha12_unofficial
+repykota \- manual page for repykota 1.20alpha18_unofficial
 .SH DESCRIPTION
-repykota v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+repykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 .PP
 Generates print quota reports.
Index: /pykota/trunk/man/genman.sh
===================================================================
--- /pykota/trunk/man/genman.sh (revision 1721)
+++ /pykota/trunk/man/genman.sh (revision 1758)
@@ -14,5 +14,5 @@
 # $Id$
 #
-for prog in dumpykota edpykota pykotme repykota warnpykota pkprinters pkhint pykosd ; do 
+for prog in autopykota dumpykota edpykota pykotme repykota warnpykota pkprinters pkhint pykosd ; do 
     help2man --section=1 --manual "User Commands" --source="C@LL - Conseil Internet & Logiciels Libres" --output=$prog.1 --no-info $prog ; 
 done
Index: /pykota/trunk/man/warnpykota.1
===================================================================
--- /pykota/trunk/man/warnpykota.1 (revision 1724)
+++ /pykota/trunk/man/warnpykota.1 (revision 1758)
@@ -2,7 +2,7 @@
 .TH WARNPYKOTA "1" "September 2004" "C@LL - Conseil Internet & Logiciels Libres" "User Commands"
 .SH NAME
-warnpykota \- manual page for warnpykota 1.20alpha12_unofficial
+warnpykota \- manual page for warnpykota 1.20alpha18_unofficial
 .SH DESCRIPTION
-warnpykota v1.20alpha12_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
+warnpykota v1.20alpha18_unofficial (c) 2003-2004 C@LL - Conseil Internet & Logiciels Libres
 .PP
 Sends mail to users over print quota.
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1757)
+++ /pykota/trunk/NEWS (revision 1758)
@@ -24,4 +24,8 @@
     - 1.20alpha18 :
     
+        - Experimental autopykota command to initialize user
+          account and quota entries on first print while not 
+          resetting the balance value if not needed.
+          
         - Added the new "winbind_separator" directive to strip
           out the Samba/Winbind domain name while printing if
