Changeset 2452 for pykota/trunk/bin

Show
Ignore:
Timestamp:
09/17/05 16:29:43 (19 years ago)
Author:
jerome
Message:

Upgraded database schema.
Added -i | --ingroups command line option to repykota.
Added -C | --comment command line option to edpykota.
Added 'noquota', 'noprint', and 'nochange' as switches for edpykota's
-l | --limitby command line option.
Severity : entirely new features, in need of testers :-)

Location:
pykota/trunk/bin
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2449 r2452  
    823823         
    824824        if self.Action != "DENY" : 
     825            if self.User.LimitBy == "noprint" : 
     826                self.printInfo(_("User %s is not allowed to print at this time.") % self.UserName, "warn") 
     827                self.Action = "DENY" 
     828                 
     829        if self.Action != "DENY" : 
    825830            # If printing is still allowed at this time, we 
    826831            # need to extract the billing code information from the database. 
     
    841846            # No need to do this if the job is denied, this way we 
    842847            # save some database queries. 
    843             self.logdebug("Checking user %s print quota entry on printer %s" \ 
     848            if self.User.LimitBy in ('noquota', 'nochange') : 
     849                self.logdebug("User %s is allowed to print with no limit, no need to check quota." % self.UserName) 
     850            else : 
     851                self.logdebug("Checking user %s print quota entry on printer %s" \ 
    844852                                    % (self.UserName, self.PrinterName)) 
    845             self.Action = self.warnUserPQuota(self.UserPQuota) 
     853                self.Action = self.warnUserPQuota(self.UserPQuota) 
    846854             
    847855        # exports some new environment variables 
     
    912920            self.printInfo(_("Job size : %i") % self.JobSize) 
    913921             
    914             # update the quota for the current user on this printer  
    915             self.printInfo(_("Updating user %s's quota on printer %s") % (self.UserName, self.PrinterName)) 
    916             self.JobPrice = self.UserPQuota.increasePagesUsage(self.JobSize) 
     922            if self.User.LimitBy == "nochange" : 
     923                # no need to update the quota for the current user on this printer 
     924                self.printInfo(_("User %s's quota on printer %s won't be modified") % (self.UserName, self.PrinterName)) 
     925                self.JobPrice = self.UserPQuota.computeJobPrice(self.JobSize) 
     926            else : 
     927                # update the quota for the current user on this printer  
     928                self.printInfo(_("Updating user %s's quota on printer %s") % (self.UserName, self.PrinterName)) 
     929                self.JobPrice = self.UserPQuota.increasePagesUsage(self.JobSize) 
    917930             
    918931            # adds the current job to history     
  • pykota/trunk/bin/edpykota

    r2344 r2452  
    100100                        
    101101  -n | --noquota       Doesn't set a quota but only does accounting. 
     102                       This is the same as --limitby noquota. 
    102103   
    103104  -r | --reset         Resets the actual page counter for the user 
     
    112113                       by its account balance or by its page quota. 
    113114                       The default value is 'quota'. Allowed values 
    114                        are 'quota' 'balance' 'quota-then-balance' and 
    115                        'balance-then-quota'. 
    116                        WARNING : quota-then-balance and balance-then-quota 
    117                        are not yet implemented. 
     115                       are 'quota' 'balance' 'noquota' 'noprint'  
     116                       and 'nochange' : 
     117                        
     118                         - quota : limit by number of pages per printer. 
     119                         - balance : limit by number of credits in account. 
     120                         - noquota : no limit, accounting still done. 
     121                         - nochange : no limit, accounting not done.  
     122                         - noprint : printing is denied.  
     123                       NB : nochange and noprint are not supported for groups. 
    118124                        
    119125  -b | --balance b     Sets the user's account balance to b.                      
     
    125131                       Groups don't have a real balance, but the 
    126132                       sum of their users' account balance. 
     133                        
     134  -C | --comment txt   Defines some informational text to be associated 
     135                       with a change to an user's account balance. 
     136                       Only meaningful if -b | --balance is also used. 
    127137                        
    128138  -S | --softlimit sl  Sets the quota soft limit to sl pages.                        
     
    237247         
    238248        softlimit = hardlimit = None 
     249         
     250        if options["noquota"] : 
     251            options["limitby"] = "noquota" 
     252             
     253        limitby = options["limitby"] 
     254        if limitby : 
     255            limitby = limitby.strip().lower() 
     256        if limitby : 
     257            if limitby not in ('quota', 'balance', 'noquota', \ 
     258                                        'noprint', 'nochange') : 
     259                raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"] 
     260            if limitby in ('noquota', 'nochange') :     
     261                options["noquota"] = 1 
     262            if (limitby in ('nochange', 'noprint')) and options["groups"] :     
     263                raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"] 
    239264 
    240265        used = options["used"] 
     
    288313                    charges = [charges[0], None] 
    289314                     
    290         limitby = options["limitby"] 
    291         if limitby : 
    292             limitby = limitby.strip().lower() 
    293         if limitby and (limitby not in ('quota', 'balance', 'quota-then-balance', 'balance-then-quota')) :     
    294             raise PyKotaToolError, _("Invalid limitby value %s") % options["limitby"] 
    295              
    296315        if options["ingroups"] :     
    297316            groupnames = [gname.strip() for gname in options["ingroups"].split(',')] 
     
    474493                                    newbalance = float(entry.AccountBalance or 0.0) + balancevalue 
    475494                                    newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue 
    476                                     entry.setAccountBalance(newbalance, newlifetimepaid) 
     495                                    entry.setAccountBalance(newbalance, newlifetimepaid, options["comment"]) 
    477496                                else : 
    478497                                    diff = balancevalue - float(entry.AccountBalance or 0.0) 
    479498                                    newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff 
    480                                     entry.setAccountBalance(balancevalue, newlifetimepaid) 
     499                                    entry.setAccountBalance(balancevalue, newlifetimepaid, options["comment"]) 
    481500                                changed[entry.Name]["balance"] = balance 
    482501                                 
     
    506525        defaults = { \ 
    507526                     "printer" : "*", \ 
     527                     "comment" : "", \ 
    508528                   } 
    509         short_options = "vhdo:c:l:b:i:naugrp:P:S:H:G:RU:" 
    510         long_options = ["help", "version", "overcharge=", "charge=", "delete", "limitby=", "balance=", "ingroups=", "noquota", "add", "users", "groups", "reset", "hardreset", "prototype=", "printer=", "softlimit=", "hardlimit=", "pgroups=", "used="] 
     529        short_options = "vhdo:c:C:l:b:i:naugrp:P:S:H:G:RU:" 
     530        long_options = ["help", "version", "comment=", \ 
     531                        "overcharge=", "charge=", "delete", "limitby=", \ 
     532                        "balance=", "ingroups=", "noquota", "add", "users", \ 
     533                        "groups", "reset", "hardreset", "prototype=", \ 
     534                        "printer=", "softlimit=", "hardlimit=", "pgroups=", \ 
     535                        "used="] 
    511536         
    512537        # Initializes the command line tool 
     
    538563        options["used"] = options["U"] or options["used"] 
    539564        options["overcharge"] = options["o"] or options["overcharge"] 
     565        options["comment"] = options["C"] or options["comment"] or defaults["comment"] 
    540566         
    541567        if options["help"] : 
     
    553579        elif options["groups"] and (options["balance"] or options["ingroups"] or options["used"] or options["overcharge"]) : 
    554580            raise PyKotaToolError, _("incompatible options, see help.") 
     581        elif options["comment"] and not options["balance"] :     
     582            raise PyKotaToolError, _("incompatible options, see help.") 
    555583        else : 
    556584            retcode = editor.main(args, options) 
  • pykota/trunk/bin/repykota

    r2344 r2452  
    5555  -g | --groups        Generates a report on group quota instead of users. 
    5656   
     57  -i | --ingroups g1[,g2...]  Only lists users who are members of these 
     58                              groups. Reserved to PyKota Administrators. 
     59   
    5760  -P | --printer p     Report quotas on this printer only. Actually p can 
    5861                       use wildcards characters to select only 
     
    9295                # no username, means all usernames 
    9396                ugnames = [ "*" ] 
     97                 
     98            if options["ingroups"] : 
     99                groupsnames = options["ingroups"].split(",") 
     100                groups = [self.storage.getGroup(gname) for gname in groupsnames] 
     101                members = {} 
     102                for group in groups : 
     103                    if not group.Exists : 
     104                        self.printInfo("Group %s doesn't exist." % group.Name, "warn") 
     105                    else :     
     106                        for user in self.storage.getGroupMembers(group) : 
     107                            members[user.Name] = user 
     108                ugnames = [ m for m in members.keys() if self.matchString(m, ugnames) ] 
    94109        else :         
    95             # not the root user 
    96110            # reports only the current user 
     111            if options["ingroups"] : 
     112                raise PyKotaToolError, _("Option --ingroups is reserved to PyKota Administrators.") 
     113                 
    97114            username = pwd.getpwuid(os.geteuid())[0] 
    98115            if options["groups"] : 
     
    118135                     "printer" : "*", \ 
    119136                   } 
    120         short_options = "vhugP:" 
    121         long_options = ["help", "version", "users", "groups", "printer="] 
     137        short_options = "vhugi:P:" 
     138        long_options = ["help", "version", "users", "groups", "ingroups=", "printer="] 
    122139         
    123140        # Initializes the command line tool 
     
    134151        options["groups"] = options["g"] or options["groups"] 
    135152        options["printer"] = options["P"] or options["printer"] or defaults["printer"] 
     153        options["ingroups"] = options["i"] or options["ingroups"] 
    136154         
    137155        if options["help"] :