Changeset 1492 for pykota/trunk/pykota
- Timestamp:
- 05/22/04 00:02:53 (20 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/tool.py
r1483 r1492 22 22 # 23 23 # $Log$ 24 # Revision 1.89 2004/05/21 22:02:52 jalet 25 # Preliminary work on pre-accounting 26 # 24 27 # Revision 1.88 2004/05/18 14:49:20 jalet 25 28 # Big code changes to completely remove the need for "requester" directives, … … 341 344 import signal 342 345 import socket 346 import tempfile 343 347 344 348 from mx import DateTime 345 349 346 from pykota import version, config, storage, logger, accounter 350 from pykota import version, config, storage, logger, accounter, pdlanalyzer 347 351 348 352 class PyKotaToolError(Exception): … … 757 761 def __init__(self) : 758 762 """Initialize local datas from current environment.""" 763 # We begin with ignoring signals, we may de-ignore them later on. 764 self.gotSigTerm = 0 765 signal.signal(signal.SIGTERM, signal.SIG_IGN) 766 signal.signal(signal.SIGCHLD, signal.SIG_IGN) 767 signal.signal(signal.SIGPIPE, signal.SIG_IGN) 768 759 769 PyKotaTool.__init__(self) 760 770 (self.printingsystem, \ … … 774 784 self.accounter = accounter.openAccounter(self) 775 785 self.exportJobInfo() 776 777 # then deal with signals 778 # CUPS backends always ignore SIGPIPE and ignore SIGTERM 779 # when printing from their stdin 780 # Here we have to catch them correctly, and pass 781 # SIGTERM to any child if needed. 782 self.gotSigTerm = self.gotSigChld = self.gotSigPipe = 0 783 signal.signal(signal.SIGTERM, self.sigterm_handler) 784 signal.signal(signal.SIGCHLD, self.sigchld_handler) 785 signal.signal(signal.SIGPIPE, self.sigpipe_handler) 786 786 self.jobdatastream = self.openJobDataStream() 787 self.softwareJobSize = self.precomputeJobSize() 788 self.logdebug("Precomputed job's size is : %s pages" % self.softwareJobSize) 789 790 def openJobDataStream(self) : 791 """Opens the file which contains the job's datas.""" 792 if self.preserveinputfile is None : 793 # Job comes from sys.stdin, but this is not 794 # seekable and complexifies our task, so create 795 # a temporary file and use it instead 796 self.logdebug("Duplicating data stream from stdin to temporary file") 797 MEGABYTE = 1024*1024 798 infile = tempfile.TemporaryFile() 799 while 1 : 800 data = sys.stdin.read(MEGABYTE) 801 if not data : 802 break 803 infile.write(data) 804 infile.flush() 805 infile.seek(0) 806 return infile 807 else : 808 # real file, just open it 809 self.logdebug("Opening data stream %s" % self.preserveinputfile) 810 return open(self.preserveinputfile, "rb") 811 812 def closeJobDataStream(self) : 813 """Closes the file which contains the job's datas.""" 814 self.logdebug("Closing data stream.") 815 try : 816 self.jobdatastream.close() 817 except : 818 pass 819 820 def precomputeJobSize(self) : 821 """Computes the job size with a software method.""" 822 try : 823 parser = pdlanalyzer.PDLAnalyzer(self.jobdatastream) 824 return parser.getJobSize() 825 except pdlanalyzer.PDLAnalyzerError, msg : 826 # Here we just log the failure, but 827 # we finally ignore it and return 0 since this 828 # computation is just an indication of what the 829 # job's size MAY be. 830 self.logger.log_message(_("Unable to precompute the job's size with the generic PDL analyzer."), "warn") 831 return 0 832 787 833 def sigterm_handler(self, signum, frame) : 788 834 """Sets an attribute whenever SIGTERM is received.""" … … 790 836 os.putenv("PYKOTASTATUS", "CANCELLED") 791 837 self.logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info") 792 793 def sigchld_handler(self, signum, frame) :794 """Sets an attribute whenever SIGCHLD is received."""795 self.gotSigChld = 1796 self.logdebug("SIGCHLD received")797 798 def sigpipe_handler(self, signum, frame) :799 """Sets an attribute whenever SIGPIPE is received."""800 self.gotSigPipe = 1801 self.logdebug("SIGPIPE received")802 838 803 839 def exportJobInfo(self) : -
pykota/trunk/pykota/version.py
r1490 r1492 22 22 # 23 23 24 __version__ = "1.19alpha1 1_unofficial"24 __version__ = "1.19alpha12_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""