Show
Ignore:
Timestamp:
01/12/04 00:22:42 (20 years ago)
Author:
jalet
Message:

Major code refactoring, it's way cleaner, and now allows automated addition
of printers on first print.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r1257 r1271  
    2222# 
    2323# $Log$ 
     24# Revision 1.71  2004/01/11 23:22:42  jalet 
     25# Major code refactoring, it's way cleaner, and now allows automated addition 
     26# of printers on first print. 
     27# 
    2428# Revision 1.70  2004/01/08 14:10:32  jalet 
    2529# Copyright year changed. 
     
    775779                    self.logger.log_message(_("User %s doesn't have quota on printer %s in the PyKota system, applying external policy (%s) for printer %s") % (self.username, self.printername, commandline, self.printername), "info") 
    776780                if os.system(commandline) : 
    777                     # if an error occured, we die without error, 
    778                     # so that the job doesn't stop the print queue. 
    779781                    self.logger.log_message(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, self.printername), "error") 
    780782                    policy = "EXTERNALERROR" 
    781783                    break 
    782784            else :         
     785                if not printer.Exists : 
     786                    self.logger.log_message(_("Printer %s not registered in the PyKota system, applying default policy (%s)") % (self.printername, policy), "info") 
     787                if not user.Exists : 
     788                    self.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (self.username, policy, self.printername), "info") 
     789                if not userpquota.Exists : 
     790                    self.logger.log_message(_("User %s doesn't have quota on printer %s in the PyKota system, applying default policy (%s)") % (self.username, self.printername, policy), "info") 
    783791                break 
     792        if policy == "EXTERNAL" :     
     793            if not printer.Exists : 
     794                self.logger.log_message(_("Printer %s still not registered in the PyKota system, job will be rejected") % self.printername, "info") 
     795            if not user.Exists : 
     796                self.logger.log_message(_("User %s still not registered in the PyKota system, job will be rejected on printer %s") % (self.username, self.printername), "info") 
     797            if not userpquota.Exists : 
     798                self.logger.log_message(_("User %s still doesn't have quota on printer %s in the PyKota system, job will be rejected") % (self.username, self.printername), "info") 
    784799        return (policy, printer, user, userpquota) 
    785800         
    786     def main(self) :     
     801    def mainWork(self) :     
    787802        """Main work is done here.""" 
    788803        (policy, printer, user, userpquota) = self.getPrinterUserAndUserPQuota() 
     804        # TODO : check for last user's quota in case pykota filter is used with querying 
    789805        if policy == "EXTERNALERROR" : 
    790806            # Policy was 'EXTERNAL' and the external command returned an error code 
    791             pass # TODO : reject job 
     807            return self.removeJob() 
    792808        elif policy == "EXTERNAL" : 
    793809            # Policy was 'EXTERNAL' and the external command wasn't able 
    794810            # to add either the printer, user or user print quota 
    795             pass # TODO : reject job 
    796         elif policy == "ALLOW": 
    797             # Either printer, user or user print quota doesn't exist, 
    798             # but the job should be allowed anyway. 
    799             pass # TODO : accept job 
    800         elif policy == "OK" : 
    801             # Both printer, user and user print quota exist, job should 
    802             # be allowed if current user is allowed to print on this 
    803             # printer 
    804             pass # TODO : decide what to do based on user quota. 
    805         else : # DENY 
     811            return self.removeJob() 
     812        elif policy == "DENY" :     
    806813            # Either printer, user or user print quota doesn't exist, 
    807814            # and the job should be rejected. 
    808             pass # TODO : reject job 
     815            return self.removeJob() 
     816        else : 
     817            if policy not in ("OK", "ALLOW") : 
     818                self.logger.log_message(_("Invalid policy %s for printer %s") % (policy, self.printername)) 
     819                return self.removeJob() 
     820            else : 
     821                return self.doWork(policy, printer, user, userpquota)