Show
Ignore:
Timestamp:
04/10/03 23:47:20 (21 years ago)
Author:
jalet
Message:

Job history added. Upgrade script neutralized for now !

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pykota

    r887 r900  
    2323# 
    2424# $Log$ 
     25# Revision 1.17  2003/04/10 21:47:20  jalet 
     26# Job history added. Upgrade script neutralized for now ! 
     27# 
    2528# Revision 1.16  2003/04/08 20:38:08  jalet 
    2629# The last job Id is saved now for each printer, this will probably 
     
    151154        # can't get actual page counter, assume printer is off, but warns in log 
    152155        kotafilter.logger.log_message("%s" % msg, "warn") 
     156        counterbeforejob = None 
    153157        printerIsOff = 1 
    154158    else :     
     
    156160         
    157161    # Get the last page counter and last username from the Quota Storage backend 
    158     pgc = kotafilter.storage.getPrinterPageCounter(kotafilter.printername)     
    159     if pgc is None : 
     162    printerid = kotafilter.storage.getPrinterId(kotafilter.printername) 
     163    if printerid is None : 
    160164        # The printer is unknown from the Quota Storage perspective 
    161165        # we let the job pass through, but log a warning message 
    162166        kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 
    163167    else :     
    164         # get last values from Quota Storage 
    165         (lastpagecounter, lastjobid, lastusername) = (pgc["pagecounter"], pgc["lastjobid"], pgc["lastusername"]) 
    166          
    167         # if printer is off then we assume the correct counter value is the last one 
    168         if printerIsOff : 
    169             counterbeforejob = lastpagecounter 
     168        userid = kotafilter.storage.getUserId(username) 
     169        if userid is None : 
     170            # The user is unknown from the Quota Storage perspective 
     171            # we let the job pass through, but log a warning message 
     172            kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn") 
     173        else : 
     174            pgc = kotafilter.storage.getPrinterPageCounter(printerid)     
     175            if pgc is None : 
     176                # The printer hasn't been used yet, from PyKota's point of view 
     177                lasthistoryid = None 
     178                lastjobid = jobid 
     179                lastuserid = userid 
     180                lastusername = username 
     181                lastpagecounter = counterbeforejob 
     182            else :     
     183                # get last values from Quota Storage 
     184                (lasthistoryid, lastjobid, lastuserid, lastusername, lastpagecounter) = (pgc["id"], pgc["jobid"], pgc["userid"], pgc["username"], pgc["pagecounter"]) 
     185                 
     186            # if printer is off then we assume the correct counter value is the last one 
     187            if printerIsOff : 
     188                counterbeforejob = lastpagecounter 
     189                 
     190            # Update the quota for the previous user on this printer according  
     191            # to the job size (difference between actual counter and latest one from storage) 
     192            jobsize = (counterbeforejob - lastpagecounter)     
     193            if jobsize >= 0 : 
     194                kotafilter.storage.updateUserPQuota(lastuserid, printerid, jobsize) 
     195                kotafilter.storage.updateJobSizeInHistory(lasthistoryid, jobsize) 
     196                kotafilter.warnUserPQuota(lastusername) 
     197            else :     
     198                kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastusername, kotafilter.printername), "error") 
     199                 
     200            # Is the current user allowed to print at all ? 
     201            action = kotafilter.warnUserPQuota(username) 
    170202             
    171         # Update the last page counter and last username in the Quota Storage backend 
    172         # set them to current user and  
    173         kotafilter.storage.updatePrinterPageCounter(kotafilter.printername, username, counterbeforejob, jobid) 
    174          
    175         # Was the printer ever used ? 
    176         if (lastpagecounter is None) or (lastusername is None) : 
    177             lastusername = username 
    178             lastpagecounter = counterbeforejob 
     203            # adds the current job to history     
     204            kotafilter.storage.addJobToHistory(jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action) 
    179205             
    180         # Update the quota for the previous user on this printer according  
    181         # to the job size (difference between actual counter and latest one from storage) 
    182         jobsize = (counterbeforejob - lastpagecounter)     
    183         if jobsize >= 0 : 
    184             kotafilter.storage.updateUserPQuota(lastusername, kotafilter.printername, jobsize) 
    185             kotafilter.warnUserPQuota(lastusername) 
    186         else :     
    187             kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, kotafilter.printername, lastusername), "error") 
    188              
    189         # Is the current user allowed to print at all ? 
    190         # if no then die, else proceed. 
    191         action = kotafilter.warnUserPQuota(username) 
    192         if action == "DENY" : 
    193             # No, just die cleanly 
    194             return 1 
     206            # if not allowed to print then die, else proceed. 
     207            if action == "DENY" : 
     208                # No, just die cleanly 
     209                return 1 
    195210         
    196211    # pass the job untouched to the underlying layer