Index: pykota/trunk/bin/pksetup
===================================================================
--- pykota/trunk/bin/pksetup (revision 3411)
+++ pykota/trunk/bin/pksetup (revision 3413)
@@ -9,10 +9,10 @@
 # the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
@@ -60,5 +60,5 @@
 # IMPORTANT : many more directives can be used, and some of the directives
 # below accept different and/or more complex parameters. Please read
-# /usr/share/pykota/conf/pykota.conf.sample for more details about the 
+# /usr/share/pykota/conf/pykota.conf.sample for more details about the
 # numerous possibilities allowed.
 #
@@ -122,5 +122,5 @@
 onaccountererror : stop
 
-# Who will receive warning messages ? 
+# Who will receive warning messages ?
 # both means admin and user.
 mailto : both
@@ -136,11 +136,11 @@
 poorman : 1.0
 
-# Warning messages to use 
-poorwarn : Your Print Quota account balance is low. 
+# Warning messages to use
+poorwarn : Your Print Quota account balance is low.
  Soon you'll not be allowed to print anymore.
 
 softwarn : Your Print Quota Soft Limit is reached.
  This means that you may still be allowed to print for some
- time, but you must contact your administrator to purchase 
+ time, but you must contact your administrator to purchase
  more print quota.
 
@@ -150,5 +150,5 @@
  as soon as possible to solve the problem.
 
-# Number of banners allowed to be printed by users 
+# Number of banners allowed to be printed by users
 # who are over quota
 maxdenybanners : 0
@@ -181,8 +181,8 @@
     cupsrestart = "/etc/init.d/cupsys restart"  # overload it if needed
     adduser = "adduser --system --group --home /etc/pykota --gecos PyKota pykota" # overload it if needed
-    packages = [ "wget", 
-                 "bzip2", 
-                 "subversion", 
-                 "postgresql", 
+    packages = [ "wget",
+                 "bzip2",
+                 "subversion",
+                 "postgresql",
                  "postgresql-client",
                  "cupsys",
@@ -200,5 +200,5 @@
                  "python-pam",
                  "pkpgcounter" ]
-        
+
     otherpackages = [
                       { "name" : "pkipplib",
@@ -219,18 +219,18 @@
                                      ],
                       },
-                   ]  
-                   
-    def __init__(self) :               
+                   ]
+
+    def __init__(self) :
         """Initializes instance specific datas."""
         self.launched = []
-        
-    def yesno(self, message) :        
+
+    def yesno(self, message) :
         """Asks the end user some question and returns the answer."""
         try :
             return raw_input("\n%s ? " % message).strip().upper()[0] == 'Y'
-        except IndexError :    
+        except IndexError :
             return False
-        
-    def confirmCommand(self, message, command, record=True) :    
+
+    def confirmCommand(self, message, command, record=True) :
         """Asks for confirmation before a command is launched, and launches it if needed."""
         if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) :
@@ -241,6 +241,6 @@
         else :
             return False
-            
-    def confirmPipe(self, message, command) :    
+
+    def confirmPipe(self, message, command) :
         """Asks for confirmation before a command is launched in a pipe, launches it if needed, and returns the result."""
         if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) :
@@ -251,5 +251,5 @@
         else :
             return False
-            
+
     def listPrinters(self) :
         """Returns a list of tuples (queuename, deviceuri) for all existing print queues."""
@@ -263,7 +263,7 @@
             queuename = begin.split()[-1]
             printers.append((queuename, deviceuri))
-        return printers    
-        
-    def downloadOtherPackages(self) :    
+        return printers
+
+    def downloadOtherPackages(self) :
         """Downloads and install additional packages from http://www.pykota.com or other websites"""
         olddirectory = os.getcwd()
@@ -278,23 +278,23 @@
             if url.startswith("svn://") :
                 download = 'svn export "%(url)s" %(name)s' % locals()
-            else :    
+            else :
                 download = 'wget --user-agent=pksetup "%(url)s"' % locals()
             if self.confirmCommand("to download %(name)s" % locals(), download) :
                 self.confirmCommand("to install %(name)s" % locals(), commands)
-        self.confirmCommand("to remove the temporary directory %(directory)s" % locals(),     
+        self.confirmCommand("to remove the temporary directory %(directory)s" % locals(),
                             "rm -fr %(directory)s" % locals(),
                             record=False)
-        os.chdir(olddirectory)    
-        
+        os.chdir(olddirectory)
+
     def waitPrintersOnline(self) :
         """Asks the admin to switch all printers ON."""
         while not self.yesno("First you MUST switch ALL your printers ON. Are ALL your printers ON") :
             pass
-            
+
     def setupDatabase(self) :
         """Creates the database."""
         pykotadirectory = self.pykotadirectory
         self.confirmCommand("to create PyKota's database in PostgreSQL", 'su - postgres -c "psql -f %(pykotadirectory)s/postgresql/pykota-postgresql.sql template1"' % locals())
-        
+
     def configurePostgreSQL(self) :
         """Configures PostgreSQL for PyKota to work."""
@@ -314,7 +314,7 @@
                         if tcpip is False :
                             tcpip = answer.startswith("listen_addresses")
-                    else :    
+                    else :
                         tcpip = False
-                    if tcpip :    
+                    if tcpip :
                         conflines.insert(2, "host\tpykota\tpykotaadmin,pykotauser\t127.0.0.1\t255.255.255.255\tmd5")
                     else :
@@ -333,10 +333,10 @@
                     return (tcpip, port)
         return (None, None)
-        
+
     def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip, port) :
         """Generates minimal configuration files for PyKota."""
         if tcpip :
             storageserver = "localhost:%i" % port
-        else :    
+        else :
             storageserver = ""
         conf = pykotaconf % locals()
@@ -356,26 +356,26 @@
                     if begin is None :
                         begin = i
-                    else :    
+                    else :
                         end = i
-                        
+
             if (begin is not None) and (end is not None) :
                 suffix = "\n".join(lines[begin+1:end])
                 self.confirmCommand("to improve PyKota's configuration wrt your existing printers", 'echo "%(suffix)s" >>%(home)s/pykota.conf' % locals())
-        
+
     def addPyKotaUser(self) :
         """Adds a system user named pykota, returns its home directory or None"""
         try :
             user = pwd.getpwnam("pykota")
-        except KeyError :    
+        except KeyError :
             if self.confirmCommand("to create a system user named 'pykota'", self.adduser) :
-                try :    
+                try :
                     return pwd.getpwnam("pykota")[5]
-                except KeyError :    
+                except KeyError :
                     return None
-            else :        
+            else :
                 return None
-        else :    
+        else :
             return user[5]
-    
+
     def setupBackend(self) :
         """Installs the cupspykota backend."""
@@ -385,11 +385,11 @@
             self.confirmCommand("to make PyKota known to CUPS", "ln -s %(realbackend)s %(backend)s" % locals())
             self.confirmCommand("to restart CUPS for the changes to take effect", self.cupsrestart)
-        
-    def managePrinters(self, printers) :    
+
+    def managePrinters(self, printers) :
         """For each printer, asks if it should be managed with PyKota or not."""
         for (queuename, deviceuri) in printers :
             command = 'pkprinters --add --cups --description "Printer created with pksetup" "%(queuename)s"' % locals()
             self.confirmCommand("to import the %(queuename)s print queue into PyKota's database and reroute it through PyKota" % locals(), command)
-    
+
     def installPyKotaFiles(self) :
         """Installs PyKota files through Python's Distutils mechanism."""
@@ -399,5 +399,5 @@
         if os.path.exists(setuppy) :
             self.confirmCommand("to install PyKota files on your system", "python %(setuppy)s install" % locals())
-        
+
     def setup(self) :
         """Installation procedure."""
@@ -411,5 +411,5 @@
         if homedirectory is None :
             logerr("Installation can't proceed. You MUST create a system user named 'pykota'.\n")
-        else :    
+        else :
             self.upgradeSystem()
             self.setupPackages()
@@ -422,55 +422,55 @@
             print nowready
             print "The script %s can be used to reinstall in unattended mode.\n" % self.genInstaller()
-            
-    def genInstaller(self) :        
+
+    def genInstaller(self) :
         """Generates an installer script."""
         scriptname = "/tmp/pykota-installer.sh"
-        commands = [ "#! /bin/sh", 
+        commands = [ "#! /bin/sh",
                      "#",
-                     "# PyKota installer script.", 
-                     "#", 
+                     "# PyKota installer script.",
+                     "#",
                      "# This script was automatically generated.",
                      "#",
                    ] + self.launched
-        script = open(scriptname, "w")           
+        script = open(scriptname, "w")
         script.write("\n".join(commands))
         script.close()
         os.chmod(scriptname, \
                  stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
-        return scriptname    
-        
-        
-class Debian(PyKotaSetup) :        
+        return scriptname
+
+
+class Debian(PyKotaSetup) :
     """Class for Debian installer."""
-    def setupPackages(self) :    
+    def setupPackages(self) :
         """Installs missing Debian packages."""
         self.confirmCommand("to install missing dependencies", "apt-get install %s" % " ".join(self.packages))
-            
+
     def upgradeSystem(self) :
         """Upgrades the Debian setup."""
         if self.confirmCommand("to grab an up-to-date list of available packages", "apt-get update") :
             self.confirmCommand("to put your system up-to-date", "apt-get -y dist-upgrade")
-    
-class Ubuntu(Debian) :    
+
+class Ubuntu(Debian) :
     """Class for Ubuntu installer."""
     pass
-    
-if __name__ == "__main__" :        
+
+if __name__ == "__main__" :
     retcode = 0
     if (len(sys.argv) != 2) or (sys.argv[1] == "-h") or (sys.argv[1] == "--help") :
         print "pksetup v0.1 (c) 2003-2008 Jerome Alet - alet@librelogiciel.com\n\nusage : pksetup distribution\n\ne.g. : pksetup debian\n\nIMPORTANT : only Debian and Ubuntu are currently supported."
-    elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") :    
+    elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") :
         print "0.1" # pksetup's own version number
-    else :    
+    else :
         classname = sys.argv[1].strip().title()
         try :
             installer = globals()[classname]()
-        except KeyError :    
+        except KeyError :
             logerr("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1])
             retcode = -1
-        else :    
+        else :
             try :
                 retcode = installer.setup()
-            except KeyboardInterrupt :             
+            except KeyboardInterrupt :
                 logerr("\n\n\nWARNING : Setup was aborted at user's request !\n\n")
                 retcode = -1
