Changeset 3413 for pykota/trunk/pykota/accounters/ink.py
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounters/ink.py
r3411 r3413 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 36 36 "GC" : { "G" : "grayscale", "C" : "colored" } , 37 37 } 38 def computeJobSize(self) : 38 def computeJobSize(self) : 39 39 """Do ink accounting for a print job.""" 40 40 if (not self.isPreAccounter) and \ … … 46 46 self.inkUsage = self.filter.preaccounter.inkUsage # Optimize : already computed ! 47 47 return self.filter.softwareJobSize # Optimize : already computed ! 48 48 49 49 parameters = [p.strip() for p in self.arguments.split(',')] 50 50 if len(parameters) == 1 : … … 54 54 if colorspace not in ("cmyk", "bw", "cmy", "rgb", "gc") : 55 55 raise PyKotaAccounterError, _("Invalid parameters for ink accounter : [%s]") % self.arguments 56 57 try : 56 57 try : 58 58 resolution = int(resolution) 59 except ValueError : 59 except ValueError : 60 60 raise PyKotaAccounterError, "Invalid parameters for ink accounter : [%s]" % self.arguments 61 61 62 62 self.filter.logdebug("Using internal parser to compute job's size and ink usage.") 63 63 64 64 jobsize = 0 65 65 if self.filter.JobSizeBytes : 66 66 try : 67 67 from pkpgpdls import analyzer, pdlparser 68 except ImportError : 68 except ImportError : 69 69 self.filter.printInfo("pkpgcounter is now distributed separately, please grab it from http://www.pykota.com/software/pkpgcounter", "error") 70 70 self.filter.printInfo("Precomputed job size will be forced to 0 pages.", "error") 71 else : 71 else : 72 72 options = analyzer.AnalyzerOptions(colorspace=colorspace, resolution=resolution) 73 73 try : 74 74 parser = analyzer.PDLAnalyzer(self.filter.DataFile, options) 75 75 (cspace, pages) = parser.getInkCoverage() 76 except pdlparser.PDLParserError, msg : 76 except pdlparser.PDLParserError, msg : 77 77 # Here we just log the failure, but 78 78 # we finally ignore it and return 0 since this … … 80 80 # job's size MAY be. 81 81 self.filter.printInfo(_("Unable to precompute the job's size and ink coverage with the generic PDL analyzer : %s") % msg, "warn") 82 else : 82 else : 83 83 cspacelabels = self.cspaceExpanded[cspace] 84 84 for page in pages : … … 86 86 for color in page.keys() : 87 87 colordict[cspacelabels[color]] = page[color] 88 self.inkUsage.append(colordict) 88 self.inkUsage.append(colordict) 89 89 jobsize = len(pages) 90 90 try : 91 91 if self.filter.Ticket.FileName is not None : 92 # when a filename is passed as an argument, the backend 92 # when a filename is passed as an argument, the backend 93 93 # must generate the correct number of copies. 94 94 jobsize *= self.filter.Ticket.Copies 95 95 self.inkUsage *= self.filter.Ticket.Copies 96 except AttributeError : # When not run from the cupspykota backend 96 except AttributeError : # When not run from the cupspykota backend 97 97 pass 98 98 self.filter.logdebug("Ink usage : %s ===> %s" % (cspace, repr(self.inkUsage))) 99 return jobsize 99 return jobsize