Show
Ignore:
Timestamp:
12/27/03 17:49:25 (20 years ago)
Author:
uid67467
Message:

Should be ok now.

Files:
1 modified

Legend:

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

    r1229 r1240  
    2222# 
    2323# $Log$ 
     24# Revision 1.65  2003/12/27 16:49:25  uid67467 
     25# Should be ok now. 
     26# 
     27# Revision 1.65  2003/12/06 08:14:38  jalet 
     28# Added support for CUPS device uris which contain authentication information. 
     29# 
    2430# Revision 1.64  2003/11/29 22:03:17  jalet 
    2531# Some code refactoring work. New code is not used at this time. 
     
    288294        self.documentation = doc 
    289295        self.config = config.PyKotaConfig("/etc/pykota") 
    290         self.logger = logger.openLogger(self, self.config.getLoggingBackend()) 
     296        self.logger = logger.openLogger(self.config.getLoggingBackend()) 
    291297        self.debug = self.config.getDebug() 
    292298        self.storage = storage.openConnection(self) 
     
    574580                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    575581            if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
     582                message = self.config.getHardWarn(printer.Name) 
    576583                for user in self.storage.getGroupMembers(group) : 
    577584                    if mailto != "EXTERNAL" : 
    578                         self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 
     585                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
    579586                    else :     
    580587                        self.externalMailTo(arguments, action, user, printer, message) 
     
    599606        """Checks a user quota and send him a message if quota is exceeded on current printer.""" 
    600607        user = userpquota.User 
    601         printer = userpquota.Printer 
    602         admin = self.config.getAdmin(printer.Name) 
    603         adminmail = self.config.getAdminMail(printer.Name) 
    604         (mailto, arguments) = self.config.getMailTo(printer.Name) 
    605         action = self.checkUserPQuota(userpquota) 
    606         if action.startswith("POLICY_") : 
    607             action = action[7:] 
    608         if action == "DENY" : 
    609             adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) 
    610             self.logger.log_message(adminmessage) 
    611             if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    612                 message = self.config.getHardWarn(printer.Name) 
    613                 if mailto != "EXTERNAL" : 
    614                     self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
    615                 else :     
    616                     self.externalMailTo(arguments, action, user, printer, message) 
    617             if mailto in [ "BOTH", "ADMIN" ] : 
    618                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    619         elif action == "WARN" :     
    620             adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name) 
    621             self.logger.log_message(adminmessage) 
    622             if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    623                 if user.LimitBy and (user.LimitBy.lower() == "balance") :  
    624                     message = self.config.getPoorWarn() 
    625                 else :      
    626                     message = self.config.getSoftWarn(printer.Name) 
    627                 if mailto != "EXTERNAL" :     
    628                     self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 
    629                 else :     
    630                     self.externalMailTo(arguments, action, user, printer, message) 
    631             if mailto in [ "BOTH", "ADMIN" ] : 
    632                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    633         return action         
     608        actions = [] 
     609        for upq in [userpquota] + userpquota.ParentPrintersUserPQuota : 
     610            printer = upq.Printer 
     611            admin = self.config.getAdmin(printer.Name) 
     612            adminmail = self.config.getAdminMail(printer.Name) 
     613            (mailto, arguments) = self.config.getMailTo(printer.Name) 
     614            self.logdebug("Checking quota for user %s on printer %s" % (upq.User.Name, printer.Name)) 
     615            action = self.checkUserPQuota(upq) 
     616            self.logdebug("Result is %s" % action) 
     617            if action.startswith("POLICY_") : 
     618                action = action[7:] 
     619            if action == "DENY" : 
     620                adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) 
     621                self.logger.log_message(adminmessage) 
     622                if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
     623                    message = self.config.getHardWarn(printer.Name) 
     624                    if mailto != "EXTERNAL" : 
     625                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
     626                    else :     
     627                        self.externalMailTo(arguments, action, user, printer, message) 
     628                if mailto in [ "BOTH", "ADMIN" ] : 
     629                    self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
     630            elif action == "WARN" :     
     631                adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name) 
     632                self.logger.log_message(adminmessage) 
     633                if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
     634                    if user.LimitBy and (user.LimitBy.lower() == "balance") :  
     635                        message = self.config.getPoorWarn() 
     636                    else :      
     637                        message = self.config.getSoftWarn(printer.Name) 
     638                    if mailto != "EXTERNAL" :     
     639                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 
     640                    else :     
     641                        self.externalMailTo(arguments, action, user, printer, message) 
     642                if mailto in [ "BOTH", "ADMIN" ] : 
     643                    self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
     644            actions.append(action)         
     645        if "DENY" in actions :     
     646            self.logdebug("Final result is %s" % action) 
     647            return "DENY" 
     648        elif "WARN" in actions :     
     649            self.logdebug("Final result is %s" % action) 
     650            return "WARN" 
     651        else :     
     652            self.logdebug("Final result is %s" % action) 
     653            return "ALLOW" 
    634654         
    635655class PyKotaFilterOrBackend(PyKotaTool) :     
     
    651671            self.username = self.username.lower() 
    652672        self.preserveinputfile = self.inputfile  
     673        # 
     674        # Export internal data to the environment 
     675        os.environ["PYKOTAUSERNAME"] = str(self.username) 
     676        os.environ["PYKOTAPRINTERNAME"] = str(self.printername) 
     677        os.environ["PYKOTACOPIES"] = str(self.copies) 
     678        os.environ["PYKOTATITLE"] = str(self.title) 
     679        os.environ["PYKOTAOPTIONS"] = str(self.options) 
     680        os.environ["PYKOTAFILENAME"] = str(self.inputfile) 
     681        # 
     682        # And opens the correct accounter  
    653683        self.accounter = accounter.openAccounter(self) 
    654684     
     
    683713            while destination.startswith("/") : 
    684714                destination = destination[1:] 
     715            checkauth = destination.split("@", 1)     
     716            if len(checkauth) == 2 : 
     717                destination = checkauth[1] 
    685718            printerhostname = destination.split("/")[0].split(":")[0] 
    686719            return ("CUPS", \ 
     
    737770           was returned by the external command. 
    738771        """ 
    739         for passnumber in range(1, 3) : 
     772        for dummy in range(1, 3) : 
    740773            printer = self.storage.getPrinter(self.printername) 
    741774            user = self.storage.getUser(self.username)