Changeset 1000 for pykota/trunk
- Timestamp:
- 05/28/03 01:00:21 (22 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykota
r976 r1000 23 23 # 24 24 # $Log$ 25 # Revision 1.32 2003/05/27 23:00:20 jalet 26 # Big rewrite of external accounting methods. 27 # Should work well now. 28 # 25 29 # Revision 1.31 2003/04/30 13:36:39 jalet 26 30 # Stupid accounting method was added. … … 150 154 def __init__(self) : 151 155 PyKotaTool.__init__(self) 152 (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile ) = self.extractInfoFromCupsOrLprng()156 (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile, self.copies) = self.extractInfoFromCupsOrLprng() 153 157 self.accounter = openAccounter(self) 154 158 … … 174 178 destination = destination[1:] 175 179 printerhostname = destination.split("/")[0].split(":")[0] 176 return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile )180 return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile, int(sys.argv[4].strip())) 177 181 else : 178 182 # Try to detect LPRng 179 jseen = Jseen = Pseen = nseen = rseen = None183 jseen = Jseen = Pseen = nseen = rseen = Kseen = None 180 184 for arg in sys.argv : 181 185 if arg.startswith("-j") : … … 191 195 elif arg.startswith("-r") : 192 196 rseen = arg[2:].strip() 197 elif arg.startswith("-K") or arg.startswith("-#") : 198 Kseen = int(arg[2:].strip()) 199 if Kseen is None : 200 Kseen = 1 # we assume the user wants at least one copy... 193 201 if jseen and Pseen and nseen and rseen : 194 return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen )195 return (None, None, None, None, None, None ) # Unknown printing system202 return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen, Kseen) 203 return (None, None, None, None, None, None, None) # Unknown printing system 196 204 197 205 def acceptJob(self) : -
pykota/trunk/conf/pykota.conf.sample
r999 r1000 68 68 # 69 69 # accounter: external(/bin/grep -c showpage) 70 # 71 # Another one, which should work with all DSC 72 # compliant Postscript files : 73 # 74 # accounter: external(/bin/grep -c "%%Page:") 70 75 # 71 76 # - stupid : counts the occurences of the 'showpage' postscript … … 83 88 # untested/postscript directory to another place. 84 89 # accounter: external(/usr/local/bin/pagecount.sh) 85 # WARNING : it may produce broken pipes, I don't know why yet. YMMV. 90 # WARNING : it may not work when multiple copies are asked. 91 # this breaks ghostscript, I don't know why yet. 86 92 # 87 93 # default value -
pykota/trunk/NEWS
r998 r1000 22 22 PyKota NEWS : 23 23 24 - 1.08alpha3 : 25 26 - External accounting methods were partly rewritten : 27 28 - No more "broken pipe" should happen. 29 30 - They now take care of the number of copies 31 This may be unneeded though, if the postscript 32 file already does this, because this would 33 overcharge users (number of copies counted 34 two times). NEEDS MORE TESTING. 35 36 - The sample configuration file now contains 37 an external accounting method example which should 38 work with all DSC compliant Postscript files. 39 40 - Some small bugs were fixed. 41 24 42 - 1.08alpha2 : 25 43 26 44 - Now works with net-snmp v5.0 and above. 27 45 It already worked, but the sample configuration 28 46 file didn't contain appropriate values... 29 47 30 48 - 1.07 : Release of the Shame ! -
pykota/trunk/pykota/accounters/external.py
r995 r1000 21 21 # 22 22 # $Log$ 23 # Revision 1.3 2003/05/27 23:00:21 jalet 24 # Big rewrite of external accounting methods. 25 # Should work well now. 26 # 23 27 # Revision 1.2 2003/05/13 13:54:20 jalet 24 28 # Better handling of broken pipes … … 42 46 The command must print the job size on its standard output and exit successfully. 43 47 """ 44 # get the job size 45 jobsize = self.getJobSize() 48 # get the job size, which is real job size * number of copies. 49 jobsize = self.getJobSize() * self.filter.copies 46 50 47 51 # get last job information for this printer … … 81 85 82 86 # launches external accounter 87 infilename = tempfile.mktemp() 88 outfilename = tempfile.mktemp() 89 errfilename = tempfile.mktemp() 90 83 91 try : 84 process = popen2.Popen3("%s" % self.arguments)85 86 92 # feed it with our data 93 fakeinput = open(infilename, "wb") 87 94 data = infile.read(256*1024) 88 95 while data : 89 process.tochild.write(data) 90 temporary.write(data) 96 fakeinput.write(data) 97 if temporary is not None : 98 temporary.write(data) 91 99 data = infile.read(256*1024) 92 process.tochild.close()100 fakeinput.close() 93 101 94 # wait for child process to exit (or die) 95 retcode = process.wait() 102 # launches child process 103 command = "%s <%s >%s 2>%s" % (self.arguments, infilename, outfilename, errfilename) 104 o = open("/tmp/comm", "w") 105 o.write("%s\n" % command) 106 o.close() 107 retcode = os.system(command) 96 108 97 109 # check exit status 98 if os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode) :110 if (os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode)) or os.stat(errfilename) : 99 111 # tries to extract the job size from the external accounter's 100 112 # standard output 113 childoutput = open(outfilename, "r") 101 114 try : 102 pagecount = int( process.fromchild.readline().strip())115 pagecount = int(childoutput.readline().strip()) 103 116 except (AttributeError, ValueError) : 104 117 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 105 118 pagecount = 0 119 childoutput.close() 106 120 else : 107 121 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 108 122 pagecount = 0 109 process.fromchild.close() 123 os.remove(infilename) 124 os.remove(outfilename) 125 os.remove(errfilename) 110 126 except IOError, msg : 127 # TODO : temporary files may remain on the filesystem... 111 128 msg = "%s : %s" % (self.arguments, msg) 112 129 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % msg) -
pykota/trunk/pykota/accounters/stupid.py
r977 r1000 21 21 # 22 22 # $Log$ 23 # Revision 1.3 2003/05/27 23:00:21 jalet 24 # Big rewrite of external accounting methods. 25 # Should work well now. 26 # 23 27 # Revision 1.2 2003/04/30 13:40:47 jalet 24 28 # Small fix … … 44 48 45 49 # get the job size 46 jobsize = self.getJobSize() 50 jobsize = self.getJobSize() * self.filter.copies 47 51 48 52 # get last job information for this printer … … 86 90 pagecount = 0 87 91 for line in infile.xreadlines() : 88 if line.startswith("showpage") : 89 pagecount += 1 92 pagecount += line.count("showpage") 90 93 if temporary is not None : 91 94 temporary.write(line) -
pykota/trunk/pykota/config.py
r980 r1000 21 21 # 22 22 # $Log$ 23 # Revision 1.27 2003/05/27 23:00:21 jalet 24 # Big rewrite of external accounting methods. 25 # Should work well now. 26 # 23 27 # Revision 1.26 2003/04/30 19:53:58 jalet 24 28 # 1.05 … … 205 209 validaccounters = [ "querying", "stupid", "external" ] 206 210 try : 207 fullaccounter = self.getPrinterOption(printer, "accounter").strip() .lower()211 fullaccounter = self.getPrinterOption(printer, "accounter").strip() 208 212 except PyKotaConfigError : 209 213 fullaccounter = "querying" 210 if fullaccounter. startswith("external") :214 if fullaccounter.lower().startswith("external") : 211 215 try : 212 216 (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] … … 217 221 if not args : 218 222 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printer) 219 return (accounter , args)220 elif fullaccounter not in validaccounters :223 return (accounter.lower(), args) 224 elif fullaccounter.lower() not in validaccounters : 221 225 raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printer, str(validaccounters)) 222 226 else : 223 return (fullaccounter , None)227 return (fullaccounter.lower(), None) 224 228 225 229 def getRequesterBackend(self, printer) : … … 242 246 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 243 247 validrequesters = [ "snmp", "external" ] # TODO : add more requesters 248 requester = requester.lower() 244 249 if requester not in validrequesters : 245 250 raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) -
pykota/trunk/pykota/version.py
r998 r1000 21 21 # 22 22 23 __version__ = "1.08alpha 2_unofficial"23 __version__ = "1.08alpha3_unofficial" 24 24 25 25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""