Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 2383)
+++ /pykota/trunk/setup.py (revision 2413)
@@ -110,4 +110,4 @@
       url = "http://www.librelogiciel.com/software/",
       packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
-      scripts = [ "bin/pkbcodes", "bin/pkmail", "bin/pkbanner", "bin/autopykota", "bin/dumpykota", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
+      scripts = [ "bin/pkturnkey", "bin/pkbcodes", "bin/pkmail", "bin/pkbanner", "bin/autopykota", "bin/dumpykota", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
       data_files = data_files)
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 2407)
+++ /pykota/trunk/pykota/version.py (revision 2413)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.23alpha22_unofficial"
+__version__ = "1.23alpha23_unofficial"
 
 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng."
Index: /pykota/trunk/bin/pkturnkey
===================================================================
--- /pykota/trunk/bin/pkturnkey (revision 2413)
+++ /pykota/trunk/bin/pkturnkey (revision 2413)
@@ -0,0 +1,191 @@
+#! /usr/bin/env python
+# -*- coding: ISO-8859-15 -*-
+
+# PyKota Turn Key tool
+#
+# PyKota - Print Quotas for CUPS and LPRng
+#
+# (c) 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# $Id$
+#
+#
+
+import sys
+import os
+import pwd
+
+from pykota.tool import PyKotaTool, PyKotaToolError, crashed, N_
+
+__doc__ = N_("""pkturnkey v%(__version__)s (c) %(__years__)s %(__author__)s
+
+A turn key tool for PyKota. When launched, this command will initialize
+PyKota's database with all existing print queues and some or all users.
+For now, no prices or limits are set, so printing is fully accounted
+for, but not limited.
+
+command line usage :
+
+  pkturnkey [options]
+
+options :
+
+  -v | --version       Prints pkturnkey version number then exits.
+  -h | --help          Prints this message then exits.
+  
+  -u | --uidmin uid    Only adds users whose uid is greater than or equal to
+                       uid. You can pass an username there as well, and its
+                       uid will be used automatically.
+                       If not set, 0 will be used automatically.
+                       
+  -U | --uidmax uid    Only adds users whose uid is lesser than or equal to
+                       uid. You can pass an username there as well, and its
+                       uid will be used automatically.
+                       If not set, a large value will be used automatically.
+
+examples :                              
+
+  $ pkturnkey --uidmin jerome
+
+  Will initialize PyKota's database will all existing printers and
+  create print accounts for all users whose uid is greater than or
+  equal to jerome's one.
+""")
+        
+class PKTurnKey(PyKotaTool) :
+    """A class for an initialization tool."""
+    def listPrinters(self) :
+        """Returns a list of tuples (queuename, deviceuri) for all existing print queues."""
+        self.logdebug("Extracting all print queues.")
+        result = os.popen("lpstat -v", "r")
+        lines = result.readlines()
+        result.close()
+        printers = []
+        for line in lines :
+            (begin, end) = line.split(':', 1)
+            deviceuri = end.strip()
+            queuename = begin.split()[-1]
+            printers.append((queuename, deviceuri))
+        return printers    
+        
+    def listUsers(self, uidmin, uidmax) :    
+        """Returns a list of usernames whose uids are between uidmin and uidmax."""
+        self.logdebug("Extracting all users whose uid is between %s and %s." % (uidmin, uidmax))
+        return [entry[0] for entry in pwd.getpwall() if uidmin <= entry[2] <= uidmax]
+        
+    def createPrinters(self, printers) :    
+        """Creates all printers in PyKota's database."""
+        needswarning = [p[0] for p in printers if p[1].find("cupspykota") == -1]
+        command = "pkprinters --add %s" % " ".join(['"%s"' % p[0] for p in printers])
+        self.logdebug("Launching : %s" % command)
+        os.system(command)
+        
+    def createUsers(self, users) :    
+        """Creates all users in PyKota's database."""
+        command = "edpykota --add --noquota %s" % " ".join(['"%s"' % u for u in users])
+        self.logdebug("Launching : %s" % command)
+        os.system(command)
+        
+    def main(self, names, options) :
+        """Intializes PyKota's database."""
+        if not self.config.isAdmin :
+            raise PyKotaToolError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command."))
+            
+        # TODO : names not used for now    
+        if not names :
+            names = ["*"]
+            
+        if not options["uidmin"] :    
+            self.printInfo(_("System users will have a print account as well !"), "warn")
+            uidmin = 0
+        else :    
+            try :
+                uidmin = int(options["uidmin"])
+            except :    
+                try :
+                    uidmin = pwd.getpwnam(options["uidmin"])[2]
+                except KeyError, msg :    
+                    raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmin"], msg)
+                    
+        if not options["uidmax"] :    
+            uidmax = sys.maxint
+        else :    
+            try :
+                uidmax = int(options["uidmax"])
+            except :    
+                try :
+                    uidmax = pwd.getpwnam(options["uidmax"])[2]
+                except KeyError, msg :    
+                    raise PyKotaToolError, _("Unknown username %s : %s") % (options["uidmax"], msg)
+                    
+        if uidmin > uidmax :            
+            (uidmin, uidmax) = (uidmax, uidmin)
+        users = self.listUsers(uidmin, uidmax)
+        printers = self.listPrinters()                    
+        
+        print "Please be patient...",
+        sys.stdout.flush()
+        self.createPrinters(printers)
+        self.createUsers(users)
+        print
+        print "Database initialized."
+                    
+                     
+if __name__ == "__main__" : 
+    retcode = 0
+    try :
+        short_options = "hvu:U:"
+        long_options = ["help", "version", "uidmin=", "uidmax="]
+        
+        # Initializes the command line tool
+        manager = PKTurnKey(doc=__doc__)
+        manager.deferredInit()
+        
+        # parse and checks the command line
+        (options, args) = manager.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["uidmin"] = options["u"] or options["uidmin"]
+        options["uidmax"] = options["U"] or options["uidmax"]
+        
+        if options["help"] :
+            manager.display_usage_and_quit()
+        elif options["version"] :
+            manager.display_version_and_quit()
+        else :
+            retcode = manager.main(args, options)
+    except KeyboardInterrupt :        
+        sys.stderr.write("\nInterrupted with Ctrl+C !\n")
+    except SystemExit :        
+        pass
+    except :
+        try :
+            manager.crashed("pkturnkey failed")
+        except :    
+            crashed("pkturnkey failed")
+        retcode = -1
+
+    try :
+        manager.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(retcode)    
Index: /pykota/trunk/MANIFEST.in
===================================================================
--- /pykota/trunk/MANIFEST.in (revision 2403)
+++ /pykota/trunk/MANIFEST.in (revision 2413)
@@ -1,3 +1,3 @@
-include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh checkdeps.py bin/pkmail bin/pkbanner bin/autopykota bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkbcodes bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README
+include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh checkdeps.py bin/pkturnkey bin/pkmail bin/pkbanner bin/autopykota bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkbcodes 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 2409)
+++ /pykota/trunk/NEWS (revision 2413)
@@ -22,4 +22,8 @@
 PyKota NEWS :
        
+    - 1.23alpha23 :
+    
+        - Introduction of the new 'pkturnkey' command line tool.
+        
     - 1.23alpha22 :
     
