Changeset 1372

Show
Ignore:
Timestamp:
03/01/04 12:23:25 (20 years ago)
Author:
jalet
Message:

Pre and Post hooks to external commands are available in the cupspykota
backend. Forthe pykota filter they will be implemented real soon now.

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1365 r1372  
    2424# 
    2525# $Log$ 
     26# Revision 1.29  2004/03/01 11:23:25  jalet 
     27# Pre and Post hooks to external commands are available in the cupspykota 
     28# backend. Forthe pykota filter they will be implemented real soon now. 
     29# 
    2630# Revision 1.28  2004/02/26 14:18:07  jalet 
    2731# Should fix the remaining bugs wrt printers groups and users groups. 
     
    201205        #            be allowed if current user is allowed to print on this printer 
    202206        if policy == "OK" : 
     207            # exports user information with initial values 
     208            self.exportUserInfo(userpquota) 
     209             
     210            # checks the user's quota 
    203211            action = self.warnUserPQuota(userpquota) 
     212             
     213            # exports some new environment variables 
     214            os.putenv("PYKOTAACTION", action) 
     215             
     216            # launches the pre hook 
     217            self.prehook(userpquota) 
     218             
    204219            self.logdebug("Job accounting begins.") 
    205220            self.accounter.beginJob(userpquota) 
     
    236251            printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options) 
    237252            self.logdebug("Job added to history.") 
     253             
     254            # exports some new environment variables 
     255            os.putenv("PYKOTAJOBSIZE", str(jobsize)) 
     256            os.putenv("PYKOTAJOBPRICE", str(jobprice)) 
     257             
     258            # then re-export user information with new values 
     259            self.exportUserInfo(userpquota) 
     260             
     261            # Launches the post hook 
     262            self.posthook(userpquota) 
    238263             
    239264        return retcode     
  • pykota/trunk/conf/pykota.conf.sample

    r1368 r1372  
    439439policy: deny 
    440440 
     441# Pre and Post Hooks  
     442# These directives allow the easy plug-in of any command of your choice 
     443# at different phases of PyKota's execution. 
     444# Pre and Post Hooks can access some of PyKota's internal information 
     445# by reading environment variables as described below. 
     446# The actual phase of PyKota's execution is available in the 
     447# PYKOTAPHASE environment variable. 
     448# Pre and Post Hooks can be defined either globally, per printer, 
     449# or both if both are defined, the printer specific hook has 
     450# priority. 
     451# 
     452# List of available environment variables : 
     453# NB : Most of these variables are also available during the execution 
     454# of external commands defined in the accounter, requester or mailto  
     455# directives. 
     456# 
     457# PYKOTAPHASE : BEFORE or AFTER the job is sent to the printer 
     458# PYKOTAUSERNAME : user's name 
     459# PYKOTAPRINTERNAME : printer's name 
     460# PYKOTAJOBID : job's id 
     461# PYKOTATITLE : job's title 
     462# PYKOTAFILENAME : job's filename 
     463# PYKOTACOPIES : number of copies 
     464# PYKOTAOPTIONS : job's options 
     465# PYKOTABALANCE : user's account balance 
     466# PYKOTALIFETIMEPAID : user's grand total paid  
     467# PYKOTAPAGECOUNTER : user's page counter on this printer 
     468# PYKOTALIFEPAGECOUNTER : user's life time page counter on this printer 
     469# PYKOTASOFTLIMIT : user's soft page limit on this printer 
     470# PYKOTAHARDLIMIT : user's hard page limit on this printer 
     471# PYKOTADATELIMIT : user's soft to hard limit date limit on this printer 
     472 
     473# PreHook : gets executed after being sure the user, printer and user quota 
     474# entry on the printer both exist in the PyKota database, but just before 
     475# checking if the user is allowed to print or not. 
     476# prehook has access to many environment variables : 
     477# 
     478# PYKOTAACTION contains either "ALLOW", "WARN" or "DENY" and  
     479# represents the action which is to be done wrt the print job. 
     480# PYKOTAPHASE contains 'BEFORE' during execution of prehook  
     481# 
     482# uncomment the line below to see what environment variables are available 
     483# prehook: /usr/bin/printenv >/tmp/before 
     484 
     485# PostHook : gets executed after the job has been added to the history. 
     486# posthook has access to all the environment variables defined above, 
     487# as well as two additionnal environment variables : PYKOTAJOBPRICE  
     488# and PYKOTAJOBSIZE.  
     489# PYKOTAPHASE contains 'AFTER' during execution of posthook. 
     490# 
     491# uncomment the line below to see what environment variables are available 
     492#posthook: /usr/bin/printenv >/tmp/after 
     493 
  • pykota/trunk/NEWS

    r1368 r1372  
    2222PyKota NEWS : 
    2323 
     24    - 1.18alpha12 : 
     25     
     26        - pre and post hooks to external commands with many  
     27          many environment variables available are useable  
     28          from the cupspykota backend. 
     29          See sample configuration file for details and help. 
     30           
    2431    - 1.18alpha11 :  
    2532     
  • pykota/trunk/pykota/tool.py

    r1365 r1372  
    2222# 
    2323# $Log$ 
     24# Revision 1.75  2004/03/01 11:23:25  jalet 
     25# Pre and Post hooks to external commands are available in the cupspykota 
     26# backend. Forthe pykota filter they will be implemented real soon now. 
     27# 
    2428# Revision 1.74  2004/02/26 14:18:07  jalet 
    2529# Should fix the remaining bugs wrt printers groups and users groups. 
     
    721725        self.preserveinputfile = self.inputfile  
    722726        self.accounter = accounter.openAccounter(self) 
     727        self.exportJobInfo() 
     728         
     729    def exportJobInfo(self) :     
     730        """Exports job information to the environment.""" 
     731        os.putenv("PYKOTAUSERNAME", self.username) 
     732        os.putenv("PYKOTAPRINTERNAME", self.printername) 
     733        os.putenv("PYKOTAJOBID", self.jobid) 
     734        os.putenv("PYKOTATITLE", self.title or "") 
     735        os.putenv("PYKOTAFILENAME", self.preserveinputfile or "") 
     736        os.putenv("PYKOTACOPIES", str(self.copies)) 
     737        os.putenv("PYKOTAOPTIONS", self.options or "") 
    723738     
     739    def exportUserInfo(self, userpquota) : 
     740        """Exports user information to the environment.""" 
     741        os.putenv("PYKOTABALANCE", str(userpquota.User.AccountBalance or 0.0)) 
     742        os.putenv("PYKOTALIFETIMEPAID", str(userpquota.User.LifeTimePaid or 0.0)) 
     743        os.putenv("PYKOTAPAGECOUNTER", str(userpquota.PageCounter or 0)) 
     744        os.putenv("PYKOTALIFEPAGECOUNTER", str(userpquota.LifePageCounter or 0)) 
     745        os.putenv("PYKOTASOFTLIMIT", str(userpquota.SoftLimit)) 
     746        os.putenv("PYKOTAHARDLIMIT", str(userpquota.HardLimit)) 
     747        os.putenv("PYKOTADATELIMIT", str(userpquota.DateLimit)) 
     748             
     749    def prehook(self, userpquota) : 
     750        """Allows pluging of an external hook before the job gets printed.""" 
     751        os.putenv("PYKOTAPHASE", "BEFORE") 
     752        prehook = self.config.getPreHook(userpquota.Printer.Name) 
     753        if prehook : 
     754            self.logdebug("Executing pre-hook [%s]" % prehook) 
     755            os.system(prehook) 
     756         
     757    def posthook(self, userpquota) : 
     758        """Allows pluging of an external hook after the job gets printed and/or denied.""" 
     759        os.putenv("PYKOTAPHASE", "AFTER") 
     760        posthook = self.config.getPostHook(userpquota.Printer.Name) 
     761        if posthook : 
     762            self.logdebug("Executing post-hook [%s]" % posthook) 
     763            os.system(posthook) 
     764         
    724765    def extractInfoFromCupsOrLprng(self) :     
    725766        """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename, title, options, backend). 
  • pykota/trunk/pykota/version.py

    r1368 r1372  
    2222# 
    2323 
    24 __version__ = "1.18alpha11_unofficial" 
     24__version__ = "1.18alpha12_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""