Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pksetup

    r3411 r3413  
    99# the Free Software Foundation, either version 3 of the License, or 
    1010# (at your option) any later version. 
    11 #  
     11# 
    1212# This program is distributed in the hope that it will be useful, 
    1313# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1414# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1515# GNU General Public License for more details. 
    16 #  
     16# 
    1717# You should have received a copy of the GNU General Public License 
    1818# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    6060# IMPORTANT : many more directives can be used, and some of the directives 
    6161# below accept different and/or more complex parameters. Please read 
    62 # /usr/share/pykota/conf/pykota.conf.sample for more details about the  
     62# /usr/share/pykota/conf/pykota.conf.sample for more details about the 
    6363# numerous possibilities allowed. 
    6464# 
     
    122122onaccountererror : stop 
    123123 
    124 # Who will receive warning messages ?  
     124# Who will receive warning messages ? 
    125125# both means admin and user. 
    126126mailto : both 
     
    136136poorman : 1.0 
    137137 
    138 # Warning messages to use  
    139 poorwarn : Your Print Quota account balance is low.  
     138# Warning messages to use 
     139poorwarn : Your Print Quota account balance is low. 
    140140 Soon you'll not be allowed to print anymore. 
    141141 
    142142softwarn : Your Print Quota Soft Limit is reached. 
    143143 This means that you may still be allowed to print for some 
    144  time, but you must contact your administrator to purchase  
     144 time, but you must contact your administrator to purchase 
    145145 more print quota. 
    146146 
     
    150150 as soon as possible to solve the problem. 
    151151 
    152 # Number of banners allowed to be printed by users  
     152# Number of banners allowed to be printed by users 
    153153# who are over quota 
    154154maxdenybanners : 0 
     
    181181    cupsrestart = "/etc/init.d/cupsys restart"  # overload it if needed 
    182182    adduser = "adduser --system --group --home /etc/pykota --gecos PyKota pykota" # overload it if needed 
    183     packages = [ "wget",  
    184                  "bzip2",  
    185                  "subversion",  
    186                  "postgresql",  
     183    packages = [ "wget", 
     184                 "bzip2", 
     185                 "subversion", 
     186                 "postgresql", 
    187187                 "postgresql-client", 
    188188                 "cupsys", 
     
    200200                 "python-pam", 
    201201                 "pkpgcounter" ] 
    202          
     202 
    203203    otherpackages = [ 
    204204                      { "name" : "pkipplib", 
     
    219219                                     ], 
    220220                      }, 
    221                    ]   
    222                     
    223     def __init__(self) :                
     221                   ] 
     222 
     223    def __init__(self) : 
    224224        """Initializes instance specific datas.""" 
    225225        self.launched = [] 
    226          
    227     def yesno(self, message) :         
     226 
     227    def yesno(self, message) : 
    228228        """Asks the end user some question and returns the answer.""" 
    229229        try : 
    230230            return raw_input("\n%s ? " % message).strip().upper()[0] == 'Y' 
    231         except IndexError :     
     231        except IndexError : 
    232232            return False 
    233          
    234     def confirmCommand(self, message, command, record=True) :     
     233 
     234    def confirmCommand(self, message, command, record=True) : 
    235235        """Asks for confirmation before a command is launched, and launches it if needed.""" 
    236236        if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : 
     
    241241        else : 
    242242            return False 
    243              
    244     def confirmPipe(self, message, command) :     
     243 
     244    def confirmPipe(self, message, command) : 
    245245        """Asks for confirmation before a command is launched in a pipe, launches it if needed, and returns the result.""" 
    246246        if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : 
     
    251251        else : 
    252252            return False 
    253              
     253 
    254254    def listPrinters(self) : 
    255255        """Returns a list of tuples (queuename, deviceuri) for all existing print queues.""" 
     
    263263            queuename = begin.split()[-1] 
    264264            printers.append((queuename, deviceuri)) 
    265         return printers     
    266          
    267     def downloadOtherPackages(self) :     
     265        return printers 
     266 
     267    def downloadOtherPackages(self) : 
    268268        """Downloads and install additional packages from http://www.pykota.com or other websites""" 
    269269        olddirectory = os.getcwd() 
     
    278278            if url.startswith("svn://") : 
    279279                download = 'svn export "%(url)s" %(name)s' % locals() 
    280             else :     
     280            else : 
    281281                download = 'wget --user-agent=pksetup "%(url)s"' % locals() 
    282282            if self.confirmCommand("to download %(name)s" % locals(), download) : 
    283283                self.confirmCommand("to install %(name)s" % locals(), commands) 
    284         self.confirmCommand("to remove the temporary directory %(directory)s" % locals(),      
     284        self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 
    285285                            "rm -fr %(directory)s" % locals(), 
    286286                            record=False) 
    287         os.chdir(olddirectory)     
    288          
     287        os.chdir(olddirectory) 
     288 
    289289    def waitPrintersOnline(self) : 
    290290        """Asks the admin to switch all printers ON.""" 
    291291        while not self.yesno("First you MUST switch ALL your printers ON. Are ALL your printers ON") : 
    292292            pass 
    293              
     293 
    294294    def setupDatabase(self) : 
    295295        """Creates the database.""" 
    296296        pykotadirectory = self.pykotadirectory 
    297297        self.confirmCommand("to create PyKota's database in PostgreSQL", 'su - postgres -c "psql -f %(pykotadirectory)s/postgresql/pykota-postgresql.sql template1"' % locals()) 
    298          
     298 
    299299    def configurePostgreSQL(self) : 
    300300        """Configures PostgreSQL for PyKota to work.""" 
     
    314314                        if tcpip is False : 
    315315                            tcpip = answer.startswith("listen_addresses") 
    316                     else :     
     316                    else : 
    317317                        tcpip = False 
    318                     if tcpip :     
     318                    if tcpip : 
    319319                        conflines.insert(2, "host\tpykota\tpykotaadmin,pykotauser\t127.0.0.1\t255.255.255.255\tmd5") 
    320320                    else : 
     
    333333                    return (tcpip, port) 
    334334        return (None, None) 
    335          
     335 
    336336    def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip, port) : 
    337337        """Generates minimal configuration files for PyKota.""" 
    338338        if tcpip : 
    339339            storageserver = "localhost:%i" % port 
    340         else :     
     340        else : 
    341341            storageserver = "" 
    342342        conf = pykotaconf % locals() 
     
    356356                    if begin is None : 
    357357                        begin = i 
    358                     else :     
     358                    else : 
    359359                        end = i 
    360                          
     360 
    361361            if (begin is not None) and (end is not None) : 
    362362                suffix = "\n".join(lines[begin+1:end]) 
    363363                self.confirmCommand("to improve PyKota's configuration wrt your existing printers", 'echo "%(suffix)s" >>%(home)s/pykota.conf' % locals()) 
    364          
     364 
    365365    def addPyKotaUser(self) : 
    366366        """Adds a system user named pykota, returns its home directory or None""" 
    367367        try : 
    368368            user = pwd.getpwnam("pykota") 
    369         except KeyError :     
     369        except KeyError : 
    370370            if self.confirmCommand("to create a system user named 'pykota'", self.adduser) : 
    371                 try :     
     371                try : 
    372372                    return pwd.getpwnam("pykota")[5] 
    373                 except KeyError :     
     373                except KeyError : 
    374374                    return None 
    375             else :         
     375            else : 
    376376                return None 
    377         else :     
     377        else : 
    378378            return user[5] 
    379      
     379 
    380380    def setupBackend(self) : 
    381381        """Installs the cupspykota backend.""" 
     
    385385            self.confirmCommand("to make PyKota known to CUPS", "ln -s %(realbackend)s %(backend)s" % locals()) 
    386386            self.confirmCommand("to restart CUPS for the changes to take effect", self.cupsrestart) 
    387          
    388     def managePrinters(self, printers) :     
     387 
     388    def managePrinters(self, printers) : 
    389389        """For each printer, asks if it should be managed with PyKota or not.""" 
    390390        for (queuename, deviceuri) in printers : 
    391391            command = 'pkprinters --add --cups --description "Printer created with pksetup" "%(queuename)s"' % locals() 
    392392            self.confirmCommand("to import the %(queuename)s print queue into PyKota's database and reroute it through PyKota" % locals(), command) 
    393      
     393 
    394394    def installPyKotaFiles(self) : 
    395395        """Installs PyKota files through Python's Distutils mechanism.""" 
     
    399399        if os.path.exists(setuppy) : 
    400400            self.confirmCommand("to install PyKota files on your system", "python %(setuppy)s install" % locals()) 
    401          
     401 
    402402    def setup(self) : 
    403403        """Installation procedure.""" 
     
    411411        if homedirectory is None : 
    412412            logerr("Installation can't proceed. You MUST create a system user named 'pykota'.\n") 
    413         else :     
     413        else : 
    414414            self.upgradeSystem() 
    415415            self.setupPackages() 
     
    422422            print nowready 
    423423            print "The script %s can be used to reinstall in unattended mode.\n" % self.genInstaller() 
    424              
    425     def genInstaller(self) :         
     424 
     425    def genInstaller(self) : 
    426426        """Generates an installer script.""" 
    427427        scriptname = "/tmp/pykota-installer.sh" 
    428         commands = [ "#! /bin/sh",  
     428        commands = [ "#! /bin/sh", 
    429429                     "#", 
    430                      "# PyKota installer script.",  
    431                      "#",  
     430                     "# PyKota installer script.", 
     431                     "#", 
    432432                     "# This script was automatically generated.", 
    433433                     "#", 
    434434                   ] + self.launched 
    435         script = open(scriptname, "w")            
     435        script = open(scriptname, "w") 
    436436        script.write("\n".join(commands)) 
    437437        script.close() 
    438438        os.chmod(scriptname, \ 
    439439                 stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) 
    440         return scriptname     
    441          
    442          
    443 class Debian(PyKotaSetup) :         
     440        return scriptname 
     441 
     442 
     443class Debian(PyKotaSetup) : 
    444444    """Class for Debian installer.""" 
    445     def setupPackages(self) :     
     445    def setupPackages(self) : 
    446446        """Installs missing Debian packages.""" 
    447447        self.confirmCommand("to install missing dependencies", "apt-get install %s" % " ".join(self.packages)) 
    448              
     448 
    449449    def upgradeSystem(self) : 
    450450        """Upgrades the Debian setup.""" 
    451451        if self.confirmCommand("to grab an up-to-date list of available packages", "apt-get update") : 
    452452            self.confirmCommand("to put your system up-to-date", "apt-get -y dist-upgrade") 
    453      
    454 class Ubuntu(Debian) :     
     453 
     454class Ubuntu(Debian) : 
    455455    """Class for Ubuntu installer.""" 
    456456    pass 
    457      
    458 if __name__ == "__main__" :         
     457 
     458if __name__ == "__main__" : 
    459459    retcode = 0 
    460460    if (len(sys.argv) != 2) or (sys.argv[1] == "-h") or (sys.argv[1] == "--help") : 
    461461        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." 
    462     elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") :     
     462    elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 
    463463        print "0.1" # pksetup's own version number 
    464     else :     
     464    else : 
    465465        classname = sys.argv[1].strip().title() 
    466466        try : 
    467467            installer = globals()[classname]() 
    468         except KeyError :     
     468        except KeyError : 
    469469            logerr("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1]) 
    470470            retcode = -1 
    471         else :     
     471        else : 
    472472            try : 
    473473                retcode = installer.setup() 
    474             except KeyboardInterrupt :              
     474            except KeyboardInterrupt : 
    475475                logerr("\n\n\nWARNING : Setup was aborted at user's request !\n\n") 
    476476                retcode = -1