Index: /pykota/trunk/conf/pykota.conf.sample
===================================================================
--- /pykota/trunk/conf/pykota.conf.sample (revision 1368)
+++ /pykota/trunk/conf/pykota.conf.sample (revision 1372)
@@ -439,2 +439,55 @@
 policy: deny
 
+# Pre and Post Hooks 
+# These directives allow the easy plug-in of any command of your choice
+# at different phases of PyKota's execution.
+# Pre and Post Hooks can access some of PyKota's internal information
+# by reading environment variables as described below.
+# The actual phase of PyKota's execution is available in the
+# PYKOTAPHASE environment variable.
+# Pre and Post Hooks can be defined either globally, per printer,
+# or both if both are defined, the printer specific hook has
+# priority.
+#
+# List of available environment variables :
+# NB : Most of these variables are also available during the execution
+# of external commands defined in the accounter, requester or mailto 
+# directives.
+#
+# PYKOTAPHASE : BEFORE or AFTER the job is sent to the printer
+# PYKOTAUSERNAME : user's name
+# PYKOTAPRINTERNAME : printer's name
+# PYKOTAJOBID : job's id
+# PYKOTATITLE : job's title
+# PYKOTAFILENAME : job's filename
+# PYKOTACOPIES : number of copies
+# PYKOTAOPTIONS : job's options
+# PYKOTABALANCE : user's account balance
+# PYKOTALIFETIMEPAID : user's grand total paid 
+# PYKOTAPAGECOUNTER : user's page counter on this printer
+# PYKOTALIFEPAGECOUNTER : user's life time page counter on this printer
+# PYKOTASOFTLIMIT : user's soft page limit on this printer
+# PYKOTAHARDLIMIT : user's hard page limit on this printer
+# PYKOTADATELIMIT : user's soft to hard limit date limit on this printer
+
+# PreHook : gets executed after being sure the user, printer and user quota
+# entry on the printer both exist in the PyKota database, but just before
+# checking if the user is allowed to print or not.
+# prehook has access to many environment variables :
+#
+# PYKOTAACTION contains either "ALLOW", "WARN" or "DENY" and 
+# represents the action which is to be done wrt the print job.
+# PYKOTAPHASE contains 'BEFORE' during execution of prehook 
+#
+# uncomment the line below to see what environment variables are available
+# prehook: /usr/bin/printenv >/tmp/before
+
+# PostHook : gets executed after the job has been added to the history.
+# posthook has access to all the environment variables defined above,
+# as well as two additionnal environment variables : PYKOTAJOBPRICE 
+# and PYKOTAJOBSIZE. 
+# PYKOTAPHASE contains 'AFTER' during execution of posthook.
+#
+# uncomment the line below to see what environment variables are available
+#posthook: /usr/bin/printenv >/tmp/after
+
Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 1365)
+++ /pykota/trunk/pykota/tool.py (revision 1372)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.75  2004/03/01 11:23:25  jalet
+# Pre and Post hooks to external commands are available in the cupspykota
+# backend. Forthe pykota filter they will be implemented real soon now.
+#
 # Revision 1.74  2004/02/26 14:18:07  jalet
 # Should fix the remaining bugs wrt printers groups and users groups.
@@ -721,5 +725,42 @@
         self.preserveinputfile = self.inputfile 
         self.accounter = accounter.openAccounter(self)
+        self.exportJobInfo()
+        
+    def exportJobInfo(self) :    
+        """Exports job information to the environment."""
+        os.putenv("PYKOTAUSERNAME", self.username)
+        os.putenv("PYKOTAPRINTERNAME", self.printername)
+        os.putenv("PYKOTAJOBID", self.jobid)
+        os.putenv("PYKOTATITLE", self.title or "")
+        os.putenv("PYKOTAFILENAME", self.preserveinputfile or "")
+        os.putenv("PYKOTACOPIES", str(self.copies))
+        os.putenv("PYKOTAOPTIONS", self.options or "")
     
+    def exportUserInfo(self, userpquota) :
+        """Exports user information to the environment."""
+        os.putenv("PYKOTABALANCE", str(userpquota.User.AccountBalance or 0.0))
+        os.putenv("PYKOTALIFETIMEPAID", str(userpquota.User.LifeTimePaid or 0.0))
+        os.putenv("PYKOTAPAGECOUNTER", str(userpquota.PageCounter or 0))
+        os.putenv("PYKOTALIFEPAGECOUNTER", str(userpquota.LifePageCounter or 0))
+        os.putenv("PYKOTASOFTLIMIT", str(userpquota.SoftLimit))
+        os.putenv("PYKOTAHARDLIMIT", str(userpquota.HardLimit))
+        os.putenv("PYKOTADATELIMIT", str(userpquota.DateLimit))
+            
+    def prehook(self, userpquota) :
+        """Allows pluging of an external hook before the job gets printed."""
+        os.putenv("PYKOTAPHASE", "BEFORE")
+        prehook = self.config.getPreHook(userpquota.Printer.Name)
+        if prehook :
+            self.logdebug("Executing pre-hook [%s]" % prehook)
+            os.system(prehook)
+        
+    def posthook(self, userpquota) :
+        """Allows pluging of an external hook after the job gets printed and/or denied."""
+        os.putenv("PYKOTAPHASE", "AFTER")
+        posthook = self.config.getPostHook(userpquota.Printer.Name)
+        if posthook :
+            self.logdebug("Executing post-hook [%s]" % posthook)
+            os.system(posthook)
+        
     def extractInfoFromCupsOrLprng(self) :    
         """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename, title, options, backend).
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1368)
+++ /pykota/trunk/pykota/version.py (revision 1372)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.18alpha11_unofficial"
+__version__ = "1.18alpha12_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1365)
+++ /pykota/trunk/bin/cupspykota (revision 1372)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.29  2004/03/01 11:23:25  jalet
+# Pre and Post hooks to external commands are available in the cupspykota
+# backend. Forthe pykota filter they will be implemented real soon now.
+#
 # Revision 1.28  2004/02/26 14:18:07  jalet
 # Should fix the remaining bugs wrt printers groups and users groups.
@@ -201,5 +205,16 @@
         #            be allowed if current user is allowed to print on this printer
         if policy == "OK" :
+            # exports user information with initial values
+            self.exportUserInfo(userpquota)
+            
+            # checks the user's quota
             action = self.warnUserPQuota(userpquota)
+            
+            # exports some new environment variables
+            os.putenv("PYKOTAACTION", action)
+            
+            # launches the pre hook
+            self.prehook(userpquota)
+            
             self.logdebug("Job accounting begins.")
             self.accounter.beginJob(userpquota)
@@ -236,4 +251,14 @@
             printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options)
             self.logdebug("Job added to history.")
+            
+            # exports some new environment variables
+            os.putenv("PYKOTAJOBSIZE", str(jobsize))
+            os.putenv("PYKOTAJOBPRICE", str(jobprice))
+            
+            # then re-export user information with new values
+            self.exportUserInfo(userpquota)
+            
+            # Launches the post hook
+            self.posthook(userpquota)
             
         return retcode    
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1368)
+++ /pykota/trunk/NEWS (revision 1372)
@@ -22,4 +22,11 @@
 PyKota NEWS :
 
+    - 1.18alpha12 :
+    
+        - pre and post hooks to external commands with many 
+          many environment variables available are useable 
+          from the cupspykota backend.
+          See sample configuration file for details and help.
+          
     - 1.18alpha11 : 
     
