Show
Ignore:
Timestamp:
04/16/03 10:22:10 (21 years ago)
Author:
jalet
Message:

More strict error detection.
Minor code rewrite to avoid some repetitive tests.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r923 r924  
    2323# 
    2424# $Log$ 
     25# Revision 1.40  2003/04/16 08:22:09  jalet 
     26# More strict error detection. 
     27# Minor code rewrite to avoid some repetitive tests. 
     28# 
    2529# Revision 1.39  2003/04/16 08:01:53  jalet 
    2630# edpykota --charge command line option works now. 
     
    317321            else : 
    318322                raise PyKotaToolError, _("There's no printer matching %s") % pname 
     323                 
    319324        softlimit = hardlimit = None     
    320325        if options["softlimit"] : 
     
    332337            self.logger.log_message(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) 
    333338            (softlimit, hardlimit) = (hardlimit, softlimit) 
     339             
    334340        if not names :     
    335341            if options["add"] and not printeradded : 
     
    337343            else :     
    338344                names = [ "*" ] # all users 
     345                 
     346        balance = options["balance"] 
     347        if balance : 
     348            balance = balance.strip() 
     349            try : 
     350                balancevalue = float(balance) 
     351            except ValueError :     
     352                raise PyKotaToolError, _("Invalid balance value %s" % options["balance"]) 
     353             
    339354        if options["charge"] : 
    340355            try : 
     
    345360                if len(charges) < 2 : 
    346361                    charges.append(None) 
     362                     
     363        limitby = options["limitby"] 
     364        if limitby : 
     365            limitby = limitby.strip().lower() 
     366        if limitby and (limitby not in ('quota', 'balance')) :     
     367            raise PyKotaToolError, _("Invalid limitby value %s" % options["limitby"]) 
     368             
    347369        for (printerid, printer) in printers : 
    348370            if options["charge"] : 
     
    416438                            self.storage.deleteUser(ident) 
    417439                    else : 
    418                         limitby = options["limitby"] 
    419                         if limitby : 
    420                             limitby = limitby.lower() 
    421                         if limitby and (limitby not in ('quota', 'balance')) :     
    422                             limitby = 'quota' 
    423440                        if options["groups"] : 
    424441                            if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : 
     
    436453                            if limitby : 
    437454                                self.storage.limitUserBy(ident, limitby) 
    438                             balance = options["balance"]     
    439455                            if balance : 
    440                                 balance = balance.strip() 
    441                                 try : 
    442                                     balancevalue = float(balance) 
    443                                 except ValueError :     
    444                                     pass # TODO : log something when incorrect balance value 
    445                                 else :     
    446                                     if balance.startswith("+") or balance.startswith("-") : 
    447                                         self.storage.increaseUserBalance(ident, balancevalue) 
    448                                     else : 
    449                                         self.storage.setUserBalance(ident, balancevalue) 
     456                                if balance.startswith("+") or balance.startswith("-") : 
     457                                    self.storage.increaseUserBalance(ident, balancevalue) 
     458                                else : 
     459                                    self.storage.setUserBalance(ident, balancevalue) 
    450460                            self.warnUserPQuota(name, printer)     
    451461