Changeset 1192 for pykota

Show
Ignore:
Timestamp:
11/19/03 00:43:12 (21 years ago)
Author:
jalet
Message:

Mailto can be any external command now, as usual.

Location:
pykota/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r1188 r1192  
    185185# 
    186186# Who should we send an email to in case a quota is reached ? 
    187 # possible values are : DevNull, User, Admin, Both 
     187# possible values are : DevNull, User, Admin, Both, External(some command) 
    188188# The Both value means that the User and the Admin will receive  
    189189# an email message. 
     
    192192# If both are defined, the printer option has priority. 
    193193# If the value is not set, then the default BOTH applies. 
     194# 
     195#   For mailto: external(/usr/bin/mycommand) 
     196# 
     197#   You can use : 
     198# 
     199#       '%(action)s'            will contain either WARN or DENY 
     200#       '%(username)s'          will contain the user's name 
     201#       '%(printername)s'       will contain the printer's name 
     202#       '%(email)s'             will contain the user's email address 
     203#       '%(message)s'           will contain the message if you want  
     204#                               use it. 
     205# 
     206#   On your command line, to pass arguments to your command. 
     207#   Example : 
     208# 
     209#       mailto: external(/usr/bin/callpager %(username)s "Quota problem on %(printername)s") 
     210# 
    194211mailto: both 
    195212 
  • pykota/trunk/NEWS

    r1191 r1192  
    2222PyKota NEWS : 
    2323 
     24    - 1.16alpha9 : 
     25     
     26        - mailto can be set to external(...) to warn users above 
     27          quota with any command of your choice (e.g. linpopup). 
     28          Several parameters are available, see sample configuration 
     29          file for details. 
     30           
    2431    - 1.16alpha8 : 
    2532     
  • pykota/trunk/po/en/pykota.po

    r1152 r1192  
    2121# 
    2222# $Log$ 
     23# Revision 1.36  2003/11/18 23:43:11  jalet 
     24# Mailto can be any external command now, as usual. 
     25# 
    2326# Revision 1.35  2003/10/08 21:41:38  jalet 
    2427# External policies for printers works ! 
     
    443446msgstr "" 
    444447 
     448msgid "Invalid option mailto %s for printer %s" 
     449msgstr "" 
     450 
  • pykota/trunk/po/fr/pykota.po

    r1152 r1192  
    2121# 
    2222# $Log$ 
     23# Revision 1.35  2003/11/18 23:43:12  jalet 
     24# Mailto can be any external command now, as usual. 
     25# 
    2326# Revision 1.34  2003/10/08 21:41:38  jalet 
    2427# External policies for printers works ! 
     
    453456msgstr "L'action externe %s sur l'imprimante %s n'a pas pu ajouter l'utilisateur %s. Job rejet� 
    454457 
     458msgid "Invalid option mailto %s for printer %s" 
     459msgstr "Option mailto %s invalide pour l'imprimante %s" 
     460 
  • pykota/trunk/po/pykota.pot

    r1152 r1192  
    2121# 
    2222# $Log$ 
     23# Revision 1.36  2003/11/18 23:43:11  jalet 
     24# Mailto can be any external command now, as usual. 
     25# 
    2326# Revision 1.35  2003/10/08 21:41:38  jalet 
    2427# External policies for printers works ! 
     
    443446msgstr "" 
    444447 
     448msgid "Invalid option mailto %s for printer %s" 
     449msgstr "" 
     450 
  • pykota/trunk/pykota/config.py

    r1152 r1192  
    2222# 
    2323# $Log$ 
     24# Revision 1.40  2003/11/18 23:43:12  jalet 
     25# Mailto can be any external command now, as usual. 
     26# 
    2427# Revision 1.39  2003/10/08 21:41:38  jalet 
    2528# External policies for printers works ! 
     
    209212                raise PyKotaConfigError, _("Option %s not found in section global of %s") % (option, self.filename) 
    210213                 
    211     def getPrinterOption(self, printer, option) :     
     214    def getPrinterOption(self, printername, option) :     
    212215        """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError.""" 
    213216        globaloption = self.getGlobalOption(option, ignore=1) 
    214217        try : 
    215             return self.config.get(printer, option, raw=1) 
     218            return self.config.get(printername, option, raw=1) 
    216219        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
    217220            if globaloption is not None : 
    218221                return globaloption 
    219222            else : 
    220                 raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printer, self.filename) 
     223                raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printername, self.filename) 
    221224         
    222225    def getStorageBackend(self) :     
     
    272275        return logger     
    273276         
    274     def getAccounterBackend(self, printer) :     
     277    def getAccounterBackend(self, printername) :     
    275278        """Returns the accounter backend to use for a given printer. 
    276279         
     
    280283        validaccounters = [ "querying", "stupid", "external" ]      
    281284        try : 
    282             fullaccounter = self.getPrinterOption(printer, "accounter").strip() 
     285            fullaccounter = self.getPrinterOption(printername, "accounter").strip() 
    283286        except PyKotaConfigError :     
    284287            fullaccounter = "querying" 
     
    287290                (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] 
    288291            except ValueError :     
    289                 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printer) 
     292                raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printername) 
    290293            if args.endswith(')') : 
    291294                args = args[:-1] 
    292295            if not args : 
    293                 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printer) 
     296                raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printername) 
    294297            return (accounter.lower(), args)     
    295298        elif fullaccounter.lower() not in validaccounters : 
    296             raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printer, str(validaccounters)) 
     299            raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printername, str(validaccounters)) 
    297300        else :     
    298301            return (fullaccounter.lower(), None) 
    299302         
    300     def getRequesterBackend(self, printer) :     
     303    def getRequesterBackend(self, printername) :     
    301304        """Returns the requester backend to use for a given printer, with its arguments.""" 
    302305        try : 
    303             fullrequester = self.getPrinterOption(printer, "requester") 
     306            fullrequester = self.getPrinterOption(printername, "requester") 
    304307        except PyKotaConfigError :     
    305308            # No requester defined, maybe it is not needed if accounting method 
    306309            # is not set to 'querying', but if we are called, then the accounting 
    307310            # method really IS 'querying', and so there's a big problem. 
    308             raise PyKotaConfigError, _("Option requester for printer %s was not set") % printer 
     311            raise PyKotaConfigError, _("Option requester for printer %s was not set") % printername 
    309312        else :     
    310313            try : 
    311314                (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] 
    312315            except ValueError :     
    313                 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
     316                raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printername) 
    314317            if args.endswith(')') : 
    315318                args = args[:-1] 
    316319            if not args : 
    317                 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
     320                raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printername) 
    318321            validrequesters = [ "snmp", "external" ] # TODO : add more requesters 
    319322            requester = requester.lower() 
    320323            if requester not in validrequesters : 
    321                 raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) 
     324                raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printername, str(validrequesters)) 
    322325            return (requester, args) 
    323326         
    324     def getPrinterPolicy(self, printer) :     
     327    def getPrinterPolicy(self, printername) :     
    325328        """Returns the default policy for the current printer.""" 
    326329        validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ]      
    327330        try : 
    328             fullpolicy = self.getPrinterOption(printer, "policy") 
     331            fullpolicy = self.getPrinterOption(printername, "policy") 
    329332        except PyKotaConfigError :     
    330333            return ("DENY", None) 
     
    333336                policy = [x.strip() for x in fullpolicy.split('(', 1)] 
    334337            except ValueError :     
    335                 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer) 
     338                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 
    336339            if len(policy) == 1 :     
    337340                policy.append("") 
     
    341344            policy = policy.upper()     
    342345            if (policy == "EXTERNAL") and not args : 
    343                 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer) 
     346                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 
    344347            if policy not in validpolicies : 
    345                 raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printer, str(validpolicies)) 
     348                raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printername, str(validpolicies)) 
    346349            return (policy, args) 
    347350         
     
    353356            return "localhost" 
    354357         
    355     def getAdminMail(self, printer) :     
     358    def getAdminMail(self, printername) :     
    356359        """Returns the Email address of the Print Quota Administrator.""" 
    357360        try : 
    358             return self.getPrinterOption(printer, "adminmail") 
     361            return self.getPrinterOption(printername, "adminmail") 
    359362        except PyKotaConfigError :     
    360363            return "root@localhost" 
    361364         
    362     def getAdmin(self, printer) :     
     365    def getAdmin(self, printername) :     
    363366        """Returns the full name of the Print Quota Administrator.""" 
    364367        try : 
    365             return self.getPrinterOption(printer, "admin") 
     368            return self.getPrinterOption(printername, "admin") 
    366369        except PyKotaConfigError :     
    367370            return "root" 
    368371         
    369     def getMailTo(self, printer) :     
     372    def getMailTo(self, printername) :     
    370373        """Returns the recipient of email messages.""" 
    371         validmailtos = [ "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] 
    372         try : 
    373             mailto = self.getPrinterOption(printer, "mailto").upper() 
    374         except PyKotaConfigError :     
    375             mailto = "BOTH" 
    376         if mailto not in validmailtos : 
    377             raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printer, str(validmailtos)) 
    378         return mailto     
    379          
    380     def getGraceDelay(self, printer) :     
     374        validmailtos = [ "EXTERNAL", "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] 
     375        try : 
     376            fullmailto = self.getPrinterOption(printername, "mailto") 
     377        except PyKotaConfigError :     
     378            return ("BOTH", None) 
     379        else :     
     380            try : 
     381                mailto = [x.strip() for x in fullmailto.split('(', 1)] 
     382            except ValueError :     
     383                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 
     384            if len(mailto) == 1 :     
     385                mailto.append("") 
     386            (mailto, args) = mailto     
     387            if args.endswith(')') : 
     388                args = args[:-1] 
     389            mailto = mailto.upper()     
     390            if (mailto == "EXTERNAL") and not args : 
     391                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 
     392            if mailto not in validmailtos : 
     393                raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printername, str(validmailtos)) 
     394            return (mailto, args) 
     395         
     396    def getGraceDelay(self, printername) :     
    381397        """Returns the grace delay in days.""" 
    382398        try : 
    383             gd = self.getPrinterOption(printer, "gracedelay") 
     399            gd = self.getPrinterOption(printername, "gracedelay") 
    384400        except PyKotaConfigError :     
    385401            gd = 7 
     
    407423            return _("Your Print Quota account balance is Low.\nSoon you'll not be allowed to print anymore.\nPlease contact the Print Quota Administrator to solve the problem.") 
    408424             
    409     def getHardWarn(self, printer) :     
     425    def getHardWarn(self, printername) :     
    410426        """Returns the hard limit error message.""" 
    411427        try : 
    412             return self.getPrinterOption(printer, "hardwarn") 
    413         except PyKotaConfigError :     
    414             return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printer 
    415              
    416     def getSoftWarn(self, printer) :     
     428            return self.getPrinterOption(printername, "hardwarn") 
     429        except PyKotaConfigError :     
     430            return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername 
     431             
     432    def getSoftWarn(self, printername) :     
    417433        """Returns the soft limit error message.""" 
    418434        try : 
    419             return self.getPrinterOption(printer, "softwarn") 
    420         except PyKotaConfigError :     
    421             return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printer 
     435            return self.getPrinterOption(printername, "softwarn") 
     436        except PyKotaConfigError :     
     437            return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername 
    422438             
    423439    def getDebug(self) :           
  • pykota/trunk/pykota/tool.py

    r1171 r1192  
    2222# 
    2323# $Log$ 
     24# Revision 1.55  2003/11/18 23:43:12  jalet 
     25# Mailto can be any external command now, as usual. 
     26# 
    2427# Revision 1.54  2003/10/24 21:52:46  jalet 
    2528# Now can force language when coming from CGI script. 
     
    506509        return action 
    507510     
     511    def externalMailTo(self, cmd, action, user, printername, message) : 
     512        """Warns the user with an external command.""" 
     513        username = user.Name 
     514        email = user.Email or user.Name 
     515        if "@" not in email : 
     516            email = "%s@%s" % (email, self.smtpserver) 
     517        os.system(cmd % locals()) 
     518     
    508519    def warnGroupPQuota(self, grouppquota) : 
    509520        """Checks a group quota and send messages if quota is exceeded on current printer.""" 
     
    512523        admin = self.config.getAdmin(printer.Name) 
    513524        adminmail = self.config.getAdminMail(printer.Name) 
    514         mailto = self.config.getMailTo(printer.Name) 
     525        (mailto, arguments) = self.config.getMailTo(printer.Name) 
    515526        action = self.checkGroupPQuota(grouppquota) 
    516527        if action.startswith("POLICY_") : 
     
    521532            if mailto in [ "BOTH", "ADMIN" ] : 
    522533                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
    523             if mailto in [ "BOTH", "USER" ] : 
     534            if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    524535                for user in self.storage.getGroupMembers(group) : 
    525                     self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 
     536                    if mailto != "EXTERNAL" : 
     537                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 
     538                    else :     
     539                        self.externalMailTo(arguments, action, user, printer.Name, message) 
    526540        elif action == "WARN" :     
    527541            adminmessage = _("Print Quota low for group %s on printer %s") % (group.Name, printer.Name) 
     
    533547            else :      
    534548                message = self.config.getSoftWarn(printer.Name) 
    535             if mailto in [ "BOTH", "USER" ] : 
     549            if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    536550                for user in self.storage.getGroupMembers(group) : 
    537                     self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
     551                    if mailto != "EXTERNAL" : 
     552                        self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
     553                    else :     
     554                        self.externalMailTo(arguments, action, user, printer.Name, message) 
    538555        return action         
    539556         
     
    544561        admin = self.config.getAdmin(printer.Name) 
    545562        adminmail = self.config.getAdminMail(printer.Name) 
    546         mailto = self.config.getMailTo(printer.Name) 
     563        (mailto, arguments) = self.config.getMailTo(printer.Name) 
    547564        action = self.checkUserPQuota(userpquota) 
    548565        if action.startswith("POLICY_") : 
     
    551568            adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) 
    552569            self.logger.log_message(adminmessage) 
    553             if mailto in [ "BOTH", "USER" ] : 
    554                 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 
     570            if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
     571                message = self.config.getHardWarn(printer.Name) 
     572                if mailto != "EXTERNAL" : 
     573                    self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 
     574                else :     
     575                    self.externalMailTo(arguments, action, user, printer.Name, message) 
    555576            if mailto in [ "BOTH", "ADMIN" ] : 
    556577                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
     
    558579            adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name) 
    559580            self.logger.log_message(adminmessage) 
    560             if mailto in [ "BOTH", "USER" ] : 
     581            if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 
    561582                if user.LimitBy and (user.LimitBy.lower() == "balance") :  
    562583                    message = self.config.getPoorWarn() 
    563584                else :      
    564585                    message = self.config.getSoftWarn(printer.Name) 
    565                 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 
     586                if mailto != "EXTERNAL" :     
     587                    self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 
     588                else :     
     589                    self.externalMailTo(arguments, action, user, printer.Name, message) 
    566590            if mailto in [ "BOTH", "ADMIN" ] : 
    567591                self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 
  • pykota/trunk/pykota/version.py

    r1189 r1192  
    2222# 
    2323 
    24 __version__ = "1.16alpha8_unofficial" 
     24__version__ = "1.16alpha9_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""