Changeset 3494 for pykota/branches

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

Backported the fix to #38.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/branches/1.26_fixes/bin/pksetup

    r3412 r3494  
    1616# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1717# GNU General Public License for more details. 
    18 #  
     18# 
    1919# You should have received a copy of the GNU General Public License 
    2020# along with this program; if not, write to the Free Software 
     
    6363# IMPORTANT : many more directives can be used, and some of the directives 
    6464# below accept different and/or more complex parameters. Please read 
    65 # /usr/share/pykota/conf/pykota.conf.sample for more details about the  
     65# /usr/share/pykota/conf/pykota.conf.sample for more details about the 
    6666# numerous possibilities allowed. 
    6767# 
     
    116116onaccountererror : stop 
    117117 
    118 # Who will receive warning messages ?  
     118# Who will receive warning messages ? 
    119119# both means admin and user. 
    120120mailto : both 
     
    130130poorman : 1.0 
    131131 
    132 # Warning messages to use  
    133 poorwarn : Your Print Quota account balance is low.  
     132# Warning messages to use 
     133poorwarn : Your Print Quota account balance is low. 
    134134 Soon you'll not be allowed to print anymore. 
    135135 
    136136softwarn : Your Print Quota Soft Limit is reached. 
    137137 This means that you may still be allowed to print for some 
    138  time, but you must contact your administrator to purchase  
     138 time, but you must contact your administrator to purchase 
    139139 more print quota. 
    140140 
     
    144144 as soon as possible to solve the problem. 
    145145 
    146 # Number of banners allowed to be printed by users  
     146# Number of banners allowed to be printed by users 
    147147# who are over quota 
    148148maxdenybanners : 0 
     
    175175    cupsrestart = "/etc/init.d/cupsys restart"  # overload it if needed 
    176176    adduser = "adduser --system --group --home /etc/pykota --gecos PyKota pykota" # overload it if needed 
    177     packages = [ "wget",  
    178                  "bzip2",  
    179                  "subversion",  
    180                  "postgresql",  
     177    packages = [ "wget", 
     178                 "bzip2", 
     179                 "subversion", 
     180                 "postgresql", 
    181181                 "postgresql-client", 
    182182                 "pkpgcounter", 
     
    195195                 "python-chardet", 
    196196                 "python-pam" ] 
    197          
     197 
    198198    otherpackages = [ { "name" : "pkipplib", 
    199199                        "version" : "0.07", 
     
    204204                                     ], 
    205205                      }, 
    206                       { "name" : "ghostpcl", 
    207                         "version" : "1.41p1", 
    208                         "url" : "ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/GhostPCL/%(name)s_%(version)s.tar.bz2",  
    209                         "commands" : [ "bunzip2 <%(name)s_%(version)s.tar.bz2 | tar -xf -", 
    210                                        "cd %(name)s_%(version)s", 
     206                      { "name" : "ghostpdl", 
     207                        "version" : "1.54", 
     208                        "url" : "http://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/%(name)s/%(name)s-%(version)s.tar.bz2", 
     209                        "commands" : [ "bunzip2 <%(name)s-%(version)s.tar.bz2 | tar -xf -", 
     210                                       "cd %(name)s-%(version)s", 
     211                                       "wget http://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/GhostPCL/urwfonts-1.41.tar.bz2", 
     212                                       "bunzip2 <urwfonts-1.41.tar.bz2 | tar -xf -", 
     213                                       "mv urwfonts-1.41 urwfonts", 
    211214                                       "make fonts", 
    212                                        "make product", 
     215                                       "make pcl", 
    213216                                       "make install", 
    214217                                     ], 
    215218                      }, 
    216                    ]   
    217                     
    218     def __init__(self) :                
     219                   ] 
     220 
     221    def __init__(self) : 
    219222        """Initializes instance specific datas.""" 
    220223        self.launched = [] 
    221          
    222     def yesno(self, message) :         
     224 
     225    def yesno(self, message) : 
    223226        """Asks the end user some question and returns the answer.""" 
    224227        try : 
    225228            return raw_input("\n%s ? " % message).strip().upper()[0] == 'Y' 
    226         except IndexError :     
     229        except IndexError : 
    227230            return False 
    228          
    229     def confirmCommand(self, message, command, record=True) :     
     231 
     232    def confirmCommand(self, message, command, record=True) : 
    230233        """Asks for confirmation before a command is launched, and launches it if needed.""" 
    231234        if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : 
     
    236239        else : 
    237240            return False 
    238              
    239     def confirmPipe(self, message, command) :     
     241 
     242    def confirmPipe(self, message, command) : 
    240243        """Asks for confirmation before a command is launched in a pipe, launches it if needed, and returns the result.""" 
    241244        if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : 
     
    246249        else : 
    247250            return False 
    248              
     251 
    249252    def listPrinters(self) : 
    250253        """Returns a list of tuples (queuename, deviceuri) for all existing print queues.""" 
     
    258261            queuename = begin.split()[-1] 
    259262            printers.append((queuename, deviceuri)) 
    260         return printers     
    261          
    262     def downloadOtherPackages(self) :     
     263        return printers 
     264 
     265    def downloadOtherPackages(self) : 
    263266        """Downloads and install additional packages from http://www.pykota.com or other websites""" 
    264267        olddirectory = os.getcwd() 
     
    273276            if url.startswith("svn://") : 
    274277                download = 'svn export "%(url)s" %(name)s' % locals() 
    275             else :     
     278            else : 
    276279                download = 'wget "%(url)s"' % locals() 
    277280            if self.confirmCommand("to download %(name)s" % locals(), download) : 
    278281                self.confirmCommand("to install %(name)s" % locals(), commands) 
    279         self.confirmCommand("to remove the temporary directory %(directory)s" % locals(),      
     282        self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 
    280283                            "rm -fr %(directory)s" % locals(), 
    281284                            record=False) 
    282         os.chdir(olddirectory)     
    283          
     285        os.chdir(olddirectory) 
     286 
    284287    def waitPrintersOnline(self) : 
    285288        """Asks the admin to switch all printers ON.""" 
    286289        while not self.yesno("First you MUST switch ALL your printers ON. Are ALL your printers ON") : 
    287290            pass 
    288              
     291 
    289292    def setupDatabase(self) : 
    290293        """Creates the database.""" 
    291294        pykotadirectory = self.pykotadirectory 
    292295        self.confirmCommand("to create PyKota's database in PostgreSQL", 'su - postgres -c "psql -f %(pykotadirectory)s/postgresql/pykota-postgresql.sql template1"' % locals()) 
    293          
     296 
    294297    def configurePostgreSQL(self) : 
    295298        """Configures PostgreSQL for PyKota to work.""" 
     
    306309                    if answer is not False : 
    307310                        tcpip = answer.strip().lower().endswith("true") 
    308                     else :     
     311                    else : 
    309312                        tcpip = False 
    310                     if tcpip :     
     313                    if tcpip : 
    311314                        conflines.insert(2, "host\tpykota\tpykotaadmin,pykotauser\t127.0.0.1\t255.255.255.255\tmd5") 
    312315                    else : 
     
    316319                    self.confirmCommand("to make PostgreSQL take the changes into account", self.pgrestart) 
    317320                    return tcpip 
    318         return None     
    319          
    320     def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip) :         
     321        return None 
     322 
     323    def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip) : 
    321324        """Generates minimal configuration files for PyKota.""" 
    322325        if tcpip : 
    323326            storageserver = "localhost" 
    324         else :     
     327        else : 
    325328            storageserver = "" 
    326329        conf = pykotaconf % locals() 
     
    340343                    if begin is None : 
    341344                        begin = i 
    342                     else :     
     345                    else : 
    343346                        end = i 
    344                          
     347 
    345348            if (begin is not None) and (end is not None) : 
    346349                suffix = "\n".join(lines[begin+1:end]) 
    347350                self.confirmCommand("to improve PyKota's configuration wrt your existing printers", 'echo "%(suffix)s" >>%(home)s/pykota.conf' % locals()) 
    348          
     351 
    349352    def addPyKotaUser(self) : 
    350353        """Adds a system user named pykota, returns its home directory or None""" 
    351354        try : 
    352355            user = pwd.getpwnam("pykota") 
    353         except KeyError :     
     356        except KeyError : 
    354357            if self.confirmCommand("to create a system user named 'pykota'", self.adduser) : 
    355                 try :     
     358                try : 
    356359                    return pwd.getpwnam("pykota")[5] 
    357                 except KeyError :     
     360                except KeyError : 
    358361                    return None 
    359             else :         
     362            else : 
    360363                return None 
    361         else :     
     364        else : 
    362365            return user[5] 
    363      
     366 
    364367    def setupBackend(self) : 
    365368        """Installs the cupspykota backend.""" 
     
    369372            self.confirmCommand("to make PyKota known to CUPS", "ln -s %(realbackend)s %(backend)s" % locals()) 
    370373            self.confirmCommand("to restart CUPS for the changes to take effect", self.cupsrestart) 
    371          
    372     def managePrinters(self, printers) :     
     374 
     375    def managePrinters(self, printers) : 
    373376        """For each printer, asks if it should be managed with PyKota or not.""" 
    374377        for (queuename, deviceuri) in printers : 
    375378            command = 'pkprinters --add --cups --description "Printer created with pksetup" "%(queuename)s"' % locals() 
    376379            self.confirmCommand("to import the %(queuename)s print queue into PyKota's database and reroute it through PyKota" % locals(), command) 
    377      
     380 
    378381    def installPyKotaFiles(self) : 
    379382        """Installs PyKota files through Python's Distutils mechanism.""" 
     
    383386        if os.path.exists(setuppy) : 
    384387            self.confirmCommand("to install PyKota files on your system", "python %(setuppy)s install" % locals()) 
    385          
     388 
    386389    def setup(self) : 
    387390        """Installation procedure.""" 
     
    395398        if homedirectory is None : 
    396399            sys.stderr.write("Installation can't proceed. You MUST create a system user named 'pykota'.\n") 
    397         else :     
     400        else : 
    398401            self.upgradeSystem() 
    399402            self.setupPackages() 
     
    406409            print nowready 
    407410            print "The script %s can be used to reinstall in unattended mode.\n" % self.genInstaller() 
    408              
    409     def genInstaller(self) :         
     411 
     412    def genInstaller(self) : 
    410413        """Generates an installer script.""" 
    411414        scriptname = "/tmp/pykota-installer.sh" 
    412         commands = [ "#! /bin/sh",  
     415        commands = [ "#! /bin/sh", 
    413416                     "#", 
    414                      "# PyKota installer script.",  
    415                      "#",  
     417                     "# PyKota installer script.", 
     418                     "#", 
    416419                     "# This script was automatically generated.", 
    417420                     "#", 
    418421                   ] + self.launched 
    419         script = open(scriptname, "w")            
     422        script = open(scriptname, "w") 
    420423        script.write("\n".join(commands)) 
    421424        script.close() 
    422425        os.chmod(scriptname, \ 
    423426                 stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) 
    424         return scriptname     
    425          
    426          
    427 class Debian(PyKotaSetup) :         
     427        return scriptname 
     428 
     429 
     430class Debian(PyKotaSetup) : 
    428431    """Class for Debian installer.""" 
    429     def setupPackages(self) :     
     432    def setupPackages(self) : 
    430433        """Installs missing Debian packages.""" 
    431434        self.confirmCommand("to install missing dependencies", "apt-get install %s" % " ".join(self.packages)) 
    432              
     435 
    433436    def upgradeSystem(self) : 
    434437        """Upgrades the Debian setup.""" 
    435438        if self.confirmCommand("to grab an up-to-date list of available packages", "apt-get update") : 
    436439            self.confirmCommand("to put your system up-to-date", "apt-get -y dist-upgrade") 
    437      
    438 class Ubuntu(Debian) :     
     440 
     441class Ubuntu(Debian) : 
    439442    """Class for Ubuntu installer.""" 
    440443    pass 
    441      
    442 if __name__ == "__main__" :         
     444 
     445if __name__ == "__main__" : 
    443446    retcode = 0 
    444447    if (len(sys.argv) != 2) or (sys.argv[1] == "-h") or (sys.argv[1] == "--help") : 
    445448        print "pksetup v0.1 (c) 2003-2007 Jerome Alet - alet@librelogiciel.com\n\nusage : pksetup distribution\n\ne.g. : pksetup debian\n\nIMPORTANT : only Debian and Ubuntu are currently supported." 
    446     elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") :     
     449    elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 
    447450        print "0.1" # pksetup's own version number 
    448     else :     
     451    else : 
    449452        classname = sys.argv[1].strip().title() 
    450453        try : 
    451454            installer = globals()[classname]() 
    452         except KeyError :     
     455        except KeyError : 
    453456            sys.stderr.write("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1]) 
    454457            retcode = -1 
    455         else :     
     458        else : 
    456459            try : 
    457460                retcode = installer.setup() 
    458             except KeyboardInterrupt :              
     461            except KeyboardInterrupt : 
    459462                sys.stderr.write("\n\n\nWARNING : Setup was aborted at user's request !\n\n") 
    460463                retcode = -1