Changeset 676
- Timestamp:
- 06/27/06 14:28:16 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r674 r676 26 26 import sys 27 27 import os 28 import time 28 29 import pwd 29 30 import errno … … 123 124 self.tags[0x05] = "unsupported-attributes-tag" 124 125 self.tags[0x06] = "subscription-attributes-tag" 125 self.tags[0x07] = "event -notification-attributes-tag"126 self.tags[0x07] = "event_notification-attributes-tag" 126 127 127 128 # out of band values … … 531 532 self.DeviceURI = device_uri 532 533 self.PrinterName = os.environ.get("PRINTER", "") 533 self.Directory = self.getPrintQueueOption(self.PrinterName, "directory" )534 self.Directory = self.getPrintQueueOption(self.PrinterName, "directory", ignore=1) or tempfile.gettempdir() 534 535 self.DataFile = os.path.join(self.Directory, "%s-%s-%s-%s" % (self.myname, self.PrinterName, self.UserName, self.JobId)) 535 536 (ippfilename, ippmessage) = self.parseIPPRequestFile() … … 675 676 def cleanUp(self) : 676 677 """Cleans up the place.""" 677 if not self.isTrue(self.getPrintQueueOption(self.PrinterName, "keepfiles", ignore=1)) : 678 os.remove(self.DataFile) 678 if (not self.isTrue(self.getPrintQueueOption(self.PrinterName, "keepfiles", ignore=1))) \ 679 and os.path.exists(self.DataFile) : 680 try : 681 os.remove(self.DataFile) 682 except OSError, msg : 683 self.logInfo("Problem when removing %s : %s" % (self.DataFile, msg), "error") 679 684 680 685 def sigtermHandler(self, signum, frame) : … … 698 703 if not self.isCancelled and not self.gotSigTerm : 699 704 if self.RealBackend : 700 retcode = self. runOriginalBackend()705 retcode = self.launchOriginalBackend() 701 706 if retcode : 702 707 onfail = self.getPrintQueueOption(self.PrinterName, \ … … 802 807 return exitcode 803 808 809 def launchOriginalBackend(self) : 810 """Launches the original backend, optionally retrying if needed.""" 811 number = 1 812 delay = 0 813 retry = self.getPrintQueueOption(self.PrinterName, "retry", ignore=1) 814 if retry is not None : 815 try : 816 (number, delay) = [int(p) for p in retry.strip().split(",")] 817 except (ValueError, AttributeError, TypeError) : 818 self.logInfo("Invalid value '%s' for the 'retry' directive for printer %s in %s." % (retry, self.PrinterName, self.conffile), "error") 819 number = 1 820 delay = 0 821 822 loopcount = 1 823 while 1 : 824 retcode = self.runOriginalBackend() 825 if not retcode : 826 break 827 else : 828 if (not number) or (loopcount < number) : 829 self.logInfo(_("The real backend produced an error, we will try again in %s seconds.") % delay, "warn") 830 time.sleep(delay) 831 loopcount += 1 832 else : 833 break 834 return retcode 835 804 836 def runOriginalBackend(self) : 805 837 """Launches the original backend.""" … … 814 846 os.dup2(f.fileno(), 0) 815 847 f.close() 848 else : 849 arguments[6] = self.DataFile # in case a tea4cups filter was applied 816 850 try : 817 851 os.execve(originalbackend, arguments, os.environ) … … 831 865 status = os.WEXITSTATUS(status) 832 866 if status : 833 self.logInfo("CUPS backend %s returned %d." % (originalbackend,\867 self.logInfo("CUPS backend %s returned %d." % (originalbackend,\ 834 868 status), "error") 835 869 return status … … 852 886 sys.exit(1) 853 887 else : 888 retcode = 1 854 889 try : 855 wrapper.readConfig() 856 wrapper.initBackend() 857 wrapper.saveDatasAndCheckSum() 858 wrapper.exportAttributes() 859 retcode = wrapper.runBranches() 890 try : 891 wrapper.readConfig() 892 wrapper.initBackend() 893 wrapper.saveDatasAndCheckSum() 894 wrapper.exportAttributes() 895 retcode = wrapper.runBranches() 896 except SystemExit, e : 897 retcode = e.code 898 except : 899 import traceback 900 lines = [] 901 for line in traceback.format_exception(*sys.exc_info()) : 902 lines.extend([l for l in line.split("\n") if l]) 903 msg = "ERROR: ".join(["%s (PID %s) : %s\n" % (wrapper.MyName, \ 904 wrapper.pid, l) \ 905 for l in (["ERROR: Tea4CUPS v%s" % __version__] + lines)]) 906 sys.stderr.write(msg) 907 sys.stderr.flush() 908 retcode = 1 909 finally : 860 910 wrapper.cleanUp() 861 except SystemExit, e :862 retcode = e.code863 except :864 import traceback865 lines = []866 for line in traceback.format_exception(*sys.exc_info()) :867 lines.extend([l for l in line.split("\n") if l])868 msg = "ERROR: ".join(["%s (PID %s) : %s\n" % (wrapper.MyName, \869 wrapper.pid, l) \870 for l in (["ERROR: Tea4CUPS v%s" % __version__] + lines)])871 sys.stderr.write(msg)872 sys.stderr.flush()873 retcode = 1874 911 sys.exit(retcode)