Changeset 1492
- Timestamp:
- 05/22/04 00:02:53 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1484 r1492 24 24 # 25 25 # $Log$ 26 # Revision 1.46 2004/05/21 22:02:51 jalet 27 # Preliminary work on pre-accounting 28 # 26 29 # Revision 1.45 2004/05/19 07:15:32 jalet 27 30 # Could the 'misterious' bug in my loop be finally fixed ??? … … 381 384 killed = 0 382 385 status = -1 386 self.logdebug("Catching SIGTERM.") 387 signal.signal(signal.SIGTERM, self.sigterm_handler) 383 388 self.logdebug("Entering streams polling loop...") 384 389 while status == -1 : … … 459 464 460 465 self.logdebug("Exiting streams polling loop...") 466 467 self.logdebug("Ignoring SIGTERM again.") 468 signal.signal(signal.SIGTERM, signal.SIG_IGN) 469 461 470 status = subprocess.wait() # just in case 462 471 if os.WIFEXITED(status) : … … 528 537 except (TypeError, NameError, AttributeError) : 529 538 pass 539 540 kotabackend.closeJobDataStream() 530 541 531 542 sys.exit(retcode) -
pykota/trunk/NEWS
r1490 r1492 22 22 PyKota NEWS : 23 23 24 - 1.19alpha12 : 25 26 - Job's size is now precomputed unconditionnally using 27 the generic PDL analyzer. 28 NB : This value is not yet used to pre-allow/deny the 29 job. 30 24 31 - 1.19alpha11 : 25 32 -
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."""