Show
Ignore:
Timestamp:
07/29/03 22:55:17 (21 years ago)
Author:
jalet
Message:

1.14 is out !

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pykota

    r1080 r1113  
    2323# 
    2424# $Log$ 
     25# Revision 1.37  2003/07/29 20:55:17  jalet 
     26# 1.14 is out ! 
     27# 
    2528# Revision 1.36  2003/07/10 06:09:52  jalet 
    2629# Incorrect documentation string 
     
    232235            return -1 
    233236             
    234 def main() :     
     237def main(thefilter) :     
    235238    """Do it, and do it right !""" 
    236     # Initializes the current tool 
    237     kotafilter = PyKotaFilter()     
    238      
    239239    # 
    240240    # If this is a CUPS filter, we should act and die like a CUPS filter when needed 
    241     if kotafilter.printingsystem == "CUPS" : 
     241    if thefilter.printingsystem == "CUPS" : 
    242242        if len(sys.argv) not in (6, 7) :     
    243243            sys.stderr.write("ERROR: %s job-id user title copies options [file]\n" % sys.argv[0]) 
    244             return kotafilter.removeJob() 
     244            return thefilter.removeJob() 
    245245     
    246246    # Get the last page counter and last username from the Quota Storage backend 
    247     printer = kotafilter.storage.getPrinter(kotafilter.printername) 
     247    printer = thefilter.storage.getPrinter(thefilter.printername) 
    248248    if not printer.Exists : 
    249249        # The printer is unknown from the Quota Storage perspective 
    250250        # we let the job pass through, but log a warning message 
    251         kotafilter.logger.log_message(_("Printer %s not registered in the PyKota system") % kotafilter.printername, "warn") 
     251        thefilter.logger.log_message(_("Printer %s not registered in the PyKota system") % thefilter.printername, "warn") 
    252252    else :     
    253         user = kotafilter.storage.getUser(kotafilter.username) 
     253        user = thefilter.storage.getUser(thefilter.username) 
    254254        if not user.Exists : 
    255255            # The user is unknown from the Quota Storage perspective 
     
    257257            # either let the job pass through or reject it, but we 
    258258            # log a message in any case. 
    259             policy = kotafilter.config.getPrinterPolicy(kotafilter.printername) 
     259            policy = thefilter.config.getPrinterPolicy(thefilter.printername) 
    260260            if policy == "ALLOW" : 
    261261                action = "POLICY_ALLOW" 
    262262            else :     
    263263                action = "POLICY_DENY" 
    264             kotafilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (kotafilter.username, action, kotafilter.printername), "warn") 
     264            thefilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (thefilter.username, action, thefilter.printername), "warn") 
    265265            if action == "POLICY_DENY" : 
    266                 return kotafilter.removeJob() 
     266                return thefilter.removeJob() 
    267267        else : 
    268268            # Now does the accounting and act depending on the result 
    269             action = kotafilter.accounter.doAccounting(printer, user) 
     269            action = thefilter.accounter.doAccounting(printer, user) 
    270270             
    271271            # if not allowed to print then die, else proceed. 
    272272            if action == "DENY" : 
    273273                # No, just die cleanly 
    274                 return kotafilter.removeJob() 
     274                return thefilter.removeJob() 
    275275         
    276276    # pass the job untouched to the underlying layer 
    277     kotafilter.accounter.filterInput(kotafilter.inputfile)       
     277    thefilter.accounter.filterInput(thefilter.inputfile)       
    278278     
    279     return kotafilter.acceptJob() 
     279    return thefilter.acceptJob() 
    280280 
    281281if __name__ == "__main__" :     
    282282    retcode = -1 
    283283    try : 
    284         retcode = main() 
     284        # Initializes the current tool 
     285        kotafilter = PyKotaFilter()     
     286        retcode = main(kotafilter) 
    285287    except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, AttributeError, KeyError, IndexError, ValueError, IOError), msg : 
    286288        sys.stderr.write("ERROR : PyKota filter failed (%s)\n" % msg) 
    287289        sys.stderr.flush() 
     290        retcode = -1 
     291 
     292    try : 
     293        kotafilter.storage.close() 
     294    except (TypeError, NameError, AttributeError) :     
     295        pass 
     296         
    288297    sys.exit(retcode)     
    289