Changeset 925

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

Printing can now be limited either by user's account balance or by
page quota (the default). Quota report doesn't include account balance
yet, though.

Location:
pykota/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r919 r925  
    6868          See http://web.mit.edu/source/third/lprng/doc/LPRng-HOWTO-15.html 
    6969          For a more accurate accounting, never switch your HP printers 
    70           off. 
     70          off. This is untested, please report any problem. 
    7171           
    7272        - A bug was fixed when edpykota --add was used with users who already 
     
    8080        - Support for AppleTalk printers was added, see sample configuration 
    8181          file for details. 
     82           
     83        - Users and group printing can now be controlled (limited) either by   
     84          print quota or by account balance. 
    8285         
    8386    - 1.02 : 
  • pykota/trunk/po/en/pykota.po

    r924 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.17  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.16  2003/04/16 08:22:09  jalet 
    2429# More strict error detection. 
     
    271276msgid "Invalid limitby value %s" 
    272277msgstr "" 
     278 
     279msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s" 
     280msgstr "" 
  • pykota/trunk/po/fr/pykota.po

    r924 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.15  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.14  2003/04/16 08:22:10  jalet 
    2429# More strict error detection. 
     
    279284msgid "Invalid limitby value %s" 
    280285msgstr "Valeur de l'option limitby %s invalide" 
     286 
     287msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s" 
     288msgstr "Impossible de trouver le solde du compte de l'utilisateur %s, action par d�ut (%s) appliqu�sur l'imprimante %s" 
  • pykota/trunk/po/pykota.pot

    r924 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.17  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.16  2003/04/16 08:22:09  jalet 
    2429# More strict error detection. 
     
    271276msgid "Invalid limitby value %s" 
    272277msgstr "" 
     278 
     279msgid "Unable to find user %s's account balance, applying default policy (%s) for printer %s" 
     280msgstr "" 
  • pykota/trunk/pykota/storages/sql.py

    r921 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.26  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.25  2003/04/15 21:58:33  jalet 
    2429# edpykota now accepts a --delete option. 
     
    234239            return 
    235240         
     241    def getUserLimitBy(self, userid) :     
     242        """Returns the way in which user printing is limited.""" 
     243        result = self.doQuery("SELECT limitby FROM users WHERE id=%s" % self.doQuote(userid)) 
     244        try : 
     245            return self.doParseResult(result)[0]["limitby"] 
     246        except TypeError :      # Not found     
     247            return 
     248         
     249    def getGroupLimitBy(self, groupid) :     
     250        """Returns the way in which group printing is limited.""" 
     251        result = self.doQuery("SELECT limitby FROM groups WHERE id=%s" % self.doQuote(groupid)) 
     252        try : 
     253            return self.doParseResult(result)[0]["limitby"] 
     254        except TypeError :      # Not found     
     255            return 
     256         
    236257    def setUserBalance(self, userid, balance) :     
    237258        """Sets the account balance for a given user to a fixed value.""" 
  • pykota/trunk/pykota/tool.py

    r915 r925  
    2121# 
    2222# $Log$ 
     23# Revision 1.32  2003/04/16 08:53:14  jalet 
     24# Printing can now be limited either by user's account balance or by 
     25# page quota (the default). Quota report doesn't include account balance 
     26# yet, though. 
     27# 
    2328# Revision 1.31  2003/04/15 11:30:57  jalet 
    2429# More work done on money print charging. 
     
    286291        printerid = self.storage.getPrinterId(printername) 
    287292        userid = self.storage.getUserId(username) 
    288         quota = self.storage.getUserPQuota(userid, printerid) 
    289         if quota is None : 
    290             # Unknown user or printer or combination 
    291             policy = self.config.getPrinterPolicy(printername) 
    292             if policy in [None, "ALLOW"] : 
    293                 action = "POLICY_ALLOW" 
     293        limitby = self.storage.getUserLimitBy(userid) 
     294        if limitby == "balance" :  
     295            balance = self.storage.getUserBalance(userid) 
     296            if balance is None : 
     297                policy = self.config.getPrinterPolicy(printername) 
     298                if policy in [None, "ALLOW"] : 
     299                    action = "POLICY_ALLOW" 
     300                else :     
     301                    action = "POLICY_DENY" 
     302                self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (username, action, printername)) 
    294303            else :     
    295                 action = "POLICY_DENY" 
    296             self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) 
    297         else :     
    298             pagecounter = quota["pagecounter"] 
    299             softlimit = quota["softlimit"] 
    300             hardlimit = quota["hardlimit"] 
    301             datelimit = quota["datelimit"] 
    302             if softlimit is not None : 
    303                 if pagecounter < softlimit : 
     304                # TODO : there's no warning (no account balance soft limit) 
     305                if balance <= 0.0 : 
     306                    action = "DENY" 
     307                else :     
    304308                    action = "ALLOW" 
     309        else : 
     310            quota = self.storage.getUserPQuota(userid, printerid) 
     311            if quota is None : 
     312                # Unknown user or printer or combination 
     313                policy = self.config.getPrinterPolicy(printername) 
     314                if policy in [None, "ALLOW"] : 
     315                    action = "POLICY_ALLOW" 
    305316                else :     
    306                     if hardlimit is None : 
    307                         # only a soft limit, this is equivalent to having only a hard limit 
    308                         action = "DENY" 
     317                    action = "POLICY_DENY" 
     318                self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) 
     319            else :     
     320                pagecounter = quota["pagecounter"] 
     321                softlimit = quota["softlimit"] 
     322                hardlimit = quota["hardlimit"] 
     323                datelimit = quota["datelimit"] 
     324                if softlimit is not None : 
     325                    if pagecounter < softlimit : 
     326                        action = "ALLOW" 
    309327                    else :     
    310                         if softlimit <= pagecounter < hardlimit :     
    311                             now = DateTime.now() 
    312                             if datelimit is not None : 
    313                                 datelimit = DateTime.ISO.ParseDateTime(datelimit) 
    314                             else : 
    315                                 datelimit = now + self.config.getGraceDelay(printername) 
    316                                 self.storage.setUserDateLimit(userid, printerid, datelimit) 
    317                             if now < datelimit : 
    318                                 action = "WARN" 
    319                             else :     
     328                        if hardlimit is None : 
     329                            # only a soft limit, this is equivalent to having only a hard limit 
     330                            action = "DENY" 
     331                        else :     
     332                            if softlimit <= pagecounter < hardlimit :     
     333                                now = DateTime.now() 
     334                                if datelimit is not None : 
     335                                    datelimit = DateTime.ISO.ParseDateTime(datelimit) 
     336                                else : 
     337                                    datelimit = now + self.config.getGraceDelay(printername) 
     338                                    self.storage.setUserDateLimit(userid, printerid, datelimit) 
     339                                if now < datelimit : 
     340                                    action = "WARN" 
     341                                else :     
     342                                    action = "DENY" 
     343                            else :          
    320344                                action = "DENY" 
    321                         else :          
     345                else :         
     346                    if hardlimit is not None : 
     347                        # no soft limit, only a hard one. 
     348                        if pagecounter < hardlimit : 
     349                            action = "ALLOW" 
     350                        else :       
    322351                            action = "DENY" 
    323             else :         
    324                 if hardlimit is not None : 
    325                     # no soft limit, only a hard one. 
    326                     if pagecounter < hardlimit : 
     352                    else : 
     353                        # Both are unset, no quota, i.e. accounting only 
    327354                        action = "ALLOW" 
    328                     else :       
    329                         action = "DENY" 
    330                 else : 
    331                     # Both are unset, no quota, i.e. accounting only 
    332                     action = "ALLOW" 
    333355        return action 
    334356     
  • pykota/trunk/README

    r920 r925  
    6868        - Complete job history is saved. This will allow more 
    6969          complex reports in the future. 
     70           
     71        - Price per page and price per job can be defined for   
     72          every printers. A job's price is the sum of the 
     73          price per job for this printer plus the number of 
     74          pages multiplied by the price per page for this 
     75          printer. 
     76           
     77        - User's account balance and lifetime paid money are now 
     78          stored in the Quota Storage, and account balance can be 
     79          used to limit the user printing instead of a print quota. 
     80          Actually you can limit either by account balance OR by 
     81          print quota, but maybe both should be checked at the  
     82          same time. Tell me what you prefer. 
    7083           
    7184All the command line tools accept the -h | --help command line option