Show
Ignore:
Timestamp:
04/15/03 15:55:28 (21 years ago)
Author:
jalet
Message:

Options --limitby and --balance added to edpykota

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r916 r917  
    2323# 
    2424# $Log$ 
     25# Revision 1.36  2003/04/15 13:55:28  jalet 
     26# Options --limitby and --balance added to edpykota 
     27# 
    2528# Revision 1.35  2003/04/15 13:06:39  jalet 
    2629# Allow to add a printer without any user 
     
    174177                       or group to zero. The life time page counter  
    175178                       is kept unchanged. 
     179                        
     180  -l | --limitby l     Choose if the user/group is limited in printing                      
     181                       by its account balance or by its page quota. 
     182                       The default value is 'quota'. Allowed values 
     183                       are 'quota' and 'balance'. 
     184                        
     185  -b | --balance b     Sets the user's account balance to b.                      
     186                       Account balance may be increase or decreased 
     187                       if b is prefixed with + or -. 
     188                       WARNING : when decreasing account balance, 
     189                       the total paid so far by the user is decreased 
     190                       too. 
     191                       Groups don't have a real balance, but the 
     192                       sum of their users' account balance. 
    176193                        
    177194  -S | --softlimit sl  Sets the quota soft limit to sl pages.                        
     
    220237  accounting of the pages he prints will still be kept. 
    221238  Print Quotas for jerome on other printers are unchanged. 
     239   
     240  $ edpykota --limitby balance jerome 
     241   
     242  This will tell PyKota to limit jerome by his account's balance 
     243  when printing. 
     244   
     245  $ edpykota --balance +10.0 jerome 
     246   
     247  This will increase jerome's account balance by 10.0 (in your 
     248  own currency). You can decrease the account balance with a 
     249  dash prefix, and set it to a fixed amount with no prefix. 
    222250 
    223251This program is free software; you can redistribute it and/or modify 
     
    294322                if softlimit is not None : 
    295323                    self.logger.log_message(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer)) 
    296             if (not options["reset"] and not options["noquota"] and not options["prototype"]) and ((hardlimit is None) or (softlimit is None)) : 
     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)) : 
    297325                raise PyKotaToolError, _("Both hard and soft limits must be set ! Aborting.") 
    298326            if options["add"] :     
     
    330358                    self.logger.log_message(_("Quota not found for object %s on printer %s.") % (name, printer)) 
    331359                else :     
     360                    limitby = options["limitby"] 
     361                    if limitby : 
     362                        limitby = limitby.lower() 
     363                    if limitby and (limitby not in ('quota', 'balance')) :     
     364                        limitby = 'quota' 
    332365                    if options["groups"] : 
    333366                        if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
     
    335368                        if options["reset"] : 
    336369                            self.storage.resetGroupPQuota(ident, printerid) 
     370                        if limitby : 
     371                            self.storage.limitGroupBy(ident, limitby) 
    337372                        self.warnGroupPQuota(name, printer)     
    338373                    else : 
     
    341376                        if options["reset"] : 
    342377                            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) 
    343392                        self.warnUserPQuota(name, printer)     
    344393                      
     
    348397                     "printer" : "*", \ 
    349398                   } 
    350         short_options = "vhnaugrp:P:S:H:" 
    351         long_options = ["help", "version", "noquota", "add", "users", "groups", "reset", "prototype=", "printer=", "softlimit=", "hardlimit="] 
     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="] 
    352401         
    353402        # Initializes the command line tool 
     
    369418        options["reset"] = options["r"] or options["reset"]  
    370419        options["noquota"] = options["n"] or options["noquota"] 
     420        options["limitby"] = options["l"] or options["limitby"] 
     421        options["balance"] = options["b"] or options["balance"]  
    371422         
    372423        if options["help"] : 
     
    380431        elif options["noquota"] and (options["prototype"] or options["hardlimit"] or options["softlimit"]) : 
    381432            raise PyKotaToolError, _("incompatible options, see help.") 
     433        elif options["groups"] and options["balance"] : 
     434            raise PyKotaToolError, _("incompatible options, see help.") 
    382435        elif options["groups"] :     
    383436            raise PyKotaToolError, _("option --groups is currently not implemented.")