Changeset 921 for pykota

Show
Ignore:
Timestamp:
04/15/03 23:58:33 (22 years ago)
Author:
jalet
Message:

edpykota now accepts a --delete option.
Preparation to allow edpykota to accept much more command line options
(WARNING : docstring is OK, but code isn't !)

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r917 r921  
    2323# 
    2424# $Log$ 
     25# Revision 1.37  2003/04/15 21:58:33  jalet 
     26# edpykota now accepts a --delete option. 
     27# Preparation to allow edpykota to accept much more command line options 
     28# (WARNING : docstring is OK, but code isn't !) 
     29# 
    2530# Revision 1.36  2003/04/15 13:55:28  jalet 
    2631# Options --limitby and --balance added to edpykota 
     
    160165                       exist on the Quota Storage Server. 
    161166                        
     167  -d | --delete        Deletes users/groups from the quota storage. 
     168                       Printers are never deleted. 
     169                        
     170  -c | --charge p[,j]  Sets the price per page and per job to charge 
     171                       for a particular printer. Job price is optional. 
     172                       If both are to be set, separate them with a comma. 
     173                       Floating point values are allowed. 
     174   
     175  -i | --ingroups g1[,g2...]  Puts the users into each of the groups 
     176                              listed, separated by commas. The groups 
     177                              must already exist in the Quota Storage. 
     178   
    162179  -u | --users         Edit users print quotas, this is the default. 
    163180   
     
    212229  printer lp doesn't exist on the Quota Storage Server then nothing is done. 
    213230 
    214   $ edpykota --add --printer lp -S 50 -H 60 jerome 
     231  $ edpykota --add --printer lp --ingroups coders,it -S 50 -H 60 jerome 
    215232   
    216233  Same as above, but if either user jerome or printer lp doesn't exist  
    217   on the Quota Storage Server they are automatically added.  
     234  on the Quota Storage Server they are automatically added. Also 
     235  user jerome is put into the groups "coders" and "it" which must 
     236  already exist in the Quota Storage. 
    218237  WARNING : the CUPS PPD file for this printer must still be modified 
    219238            manually, as well as pykota's configuration file for a 
     
    248267  own currency). You can decrease the account balance with a 
    249268  dash prefix, and set it to a fixed amount with no prefix. 
     269   
     270  $ edpykota --delete jerome rachel 
     271   
     272  This will completely delete jerome and rachel from the Quota Storage 
     273  database. All their quotas and jobs will be deleted too. 
    250274 
    251275This program is free software; you can redistribute it and/or modify 
     
    322346                if softlimit is not None : 
    323347                    self.logger.log_message(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer)) 
    324             if (not options["reset"] and not options["noquota"] and not options["prototype"] and not options["limitby"] and not options["balance"]) and ((hardlimit is None) or (softlimit is None)) : 
     348            if (not options["reset"] and not options["noquota"] and not options["prototype"] and not options["limitby"] and not options["balance"] and not options["delete"]) and ((hardlimit is None) or (softlimit is None)) : 
    325349                raise PyKotaToolError, _("Both hard and soft limits must be set ! Aborting.") 
    326350            if options["add"] :     
    327                 allidnames = [(self.storage.getUserId(n), n) for n in names] 
     351                if options["groups"] :     
     352                    allidnames = [(self.storage.getGroupId(n), n) for n in names] 
     353                else : 
     354                    allidnames = [(self.storage.getUserId(n), n) for n in names] 
    328355            else :    
    329356                if options["groups"] :     
     
    358385                    self.logger.log_message(_("Quota not found for object %s on printer %s.") % (name, printer)) 
    359386                else :     
    360                     limitby = options["limitby"] 
    361                     if limitby : 
    362                         limitby = limitby.lower() 
    363                     if limitby and (limitby not in ('quota', 'balance')) :     
    364                         limitby = 'quota' 
    365                     if options["groups"] : 
    366                         if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
    367                             self.storage.setGroupPQuota(ident, printerid, softlimit, hardlimit) 
    368                         if options["reset"] : 
    369                             self.storage.resetGroupPQuota(ident, printerid) 
     387                    if options["delete"] : 
     388                        if options["groups"] : 
     389                            self.storage.deleteGroup(ident) 
     390                        else : 
     391                            self.storage.deleteUser(ident) 
     392                    else : 
     393                        limitby = options["limitby"] 
    370394                        if limitby : 
    371                             self.storage.limitGroupBy(ident, limitby) 
    372                         self.warnGroupPQuota(name, printer)     
    373                     else : 
    374                         if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
    375                             self.storage.setUserPQuota(ident, printerid, softlimit, hardlimit) 
    376                         if options["reset"] : 
    377                             self.storage.resetUserPQuota(ident, printerid) 
    378                         if limitby : 
    379                             self.storage.limitUserBy(ident, limitby) 
    380                         balance = options["balance"]     
    381                         if balance : 
    382                             balance = balance.strip() 
    383                             try : 
    384                                 balancevalue = float(balance) 
    385                             except ValueError :     
    386                                 pass # TODO : log something when incorrect balance value 
    387                             else :     
    388                                 if balance.startswith("+") or balance.startswith("-") : 
    389                                     self.storage.increaseUserBalance(ident, balancevalue) 
    390                                 else : 
    391                                     self.storage.setUserBalance(ident, balancevalue) 
    392                         self.warnUserPQuota(name, printer)     
     395                            limitby = limitby.lower() 
     396                        if limitby and (limitby not in ('quota', 'balance')) :     
     397                            limitby = 'quota' 
     398                        if options["groups"] : 
     399                            if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
     400                                self.storage.setGroupPQuota(ident, printerid, softlimit, hardlimit) 
     401                            if options["reset"] : 
     402                                self.storage.resetGroupPQuota(ident, printerid) 
     403                            if limitby : 
     404                                self.storage.limitGroupBy(ident, limitby) 
     405                            self.warnGroupPQuota(name, printer)     
     406                        else : 
     407                            if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
     408                                self.storage.setUserPQuota(ident, printerid, softlimit, hardlimit) 
     409                            if options["reset"] : 
     410                                self.storage.resetUserPQuota(ident, printerid) 
     411                            if limitby : 
     412                                self.storage.limitUserBy(ident, limitby) 
     413                            balance = options["balance"]     
     414                            if balance : 
     415                                balance = balance.strip() 
     416                                try : 
     417                                    balancevalue = float(balance) 
     418                                except ValueError :     
     419                                    pass # TODO : log something when incorrect balance value 
     420                                else :     
     421                                    if balance.startswith("+") or balance.startswith("-") : 
     422                                        self.storage.increaseUserBalance(ident, balancevalue) 
     423                                    else : 
     424                                        self.storage.setUserBalance(ident, balancevalue) 
     425                            self.warnUserPQuota(name, printer)     
    393426                      
    394427if __name__ == "__main__" :  
     
    397430                     "printer" : "*", \ 
    398431                   } 
    399         short_options = "vhl:b:naugrp:P:S:H:" 
    400         long_options = ["help", "version", "limitby=", "balance=", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit="] 
     432        short_options = "vhdc:l:b:i:naugrp:P:S:H:" 
     433        long_options = ["help", "version", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit="] 
    401434         
    402435        # Initializes the command line tool 
     
    420453        options["limitby"] = options["l"] or options["limitby"] 
    421454        options["balance"] = options["b"] or options["balance"]  
     455        options["delete"] = options["d"] or options["delete"]  
     456        options["ingroups"] = options["i"] or options["ingroups"] 
     457        options["charge"] = options["c"] or options["charge"] 
    422458         
    423459        if options["help"] : 
     
    427463        elif options["users"] and options["groups"] :     
    428464            raise PyKotaToolError, _("incompatible options, see help.") 
     465        elif (options["add"] or options["prototype"]) and options["delete"] :     
     466            raise PyKotaToolError, _("incompatible options, see help.") 
    429467        elif (options["softlimit"] or options["hardlimit"]) and options["prototype"] :     
    430468            raise PyKotaToolError, _("incompatible options, see help.") 
    431469        elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) : 
    432470            raise PyKotaToolError, _("incompatible options, see help.") 
    433         elif options["groups"] and options["balance"] : 
     471        elif options["groups"] and (options["balance"] or options["ingroups"]) : 
    434472            raise PyKotaToolError, _("incompatible options, see help.") 
    435473        elif options["groups"] :     
  • pykota/trunk/pykota/storages/sql.py

    r917 r921  
    2121# 
    2222# $Log$ 
     23# Revision 1.25  2003/04/15 21:58:33  jalet 
     24# edpykota now accepts a --delete option. 
     25# Preparation to allow edpykota to accept much more command line options 
     26# (WARNING : docstring is OK, but code isn't !) 
     27# 
    2328# Revision 1.24  2003/04/15 13:55:28  jalet 
    2429# Options --limitby and --balance added to edpykota 
     
    288293            return 
    289294         
     295    def deleteUser(self, userid) :     
     296        """Completely deletes an user from the Quota Storage.""" 
     297        queries = [] 
     298        queries.append("DELETE FROM groupsmembers WHERE userid=%s" % self.doQuote(userid)) 
     299        queries.append("DELETE FROM jobhistory WHERE userid=%s" % self.doQuote(userid)) 
     300        queries.append("DELETE FROM userpquota WHERE userid=%s" % self.doQuote(userid)) 
     301        queries.append("DELETE FROM users WHERE id=%s" % self.doQuote(userid)) 
     302        # TODO : What should we do if we delete the last person who used a given printer ? 
     303        self.doQuery(queries) 
     304         
     305    def deleteGroup(self, groupid) :     
     306        """Completely deletes an user from the Quota Storage.""" 
     307        queries = [] 
     308        queries.append("DELETE FROM groupsmembers WHERE groupid=%s" % self.doQuote(groupid)) 
     309        queries.append("DELETE FROM grouppquota WHERE groupid=%s" % self.doQuote(groupid)) 
     310        queries.append("DELETE FROM groups WHERE id=%s" % self.doQuote(groupid)) 
     311        self.doQuery(queries) 
     312         
    290313    def computePrinterJobPrice(self, printerid, jobsize) :     
    291314        """Returns the price for a job on a given printer."""