Changeset 492 for pkpgcounter
- Timestamp:
- 11/20/07 00:56:15 (17 years ago)
- Location:
- pkpgcounter/trunk/pkpgpdls
- Files:
-
- 10 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/analyzer.py
r491 r492 82 82 try : 83 83 pdlhandler = self.detectPDLHandler() 84 pdlhandler.convertToTiffMultiPage24NC(self.filename, self.options.resolution) 85 result = inkcoverage.getInkCoverage(self.filename, cspace) 84 (handle, filename) = tempfile.mkstemp(".tmp", "pkpgcounter") 85 os.close(handle) 86 try : 87 pdlhandler.convertToTiffMultiPage24NC(filename, self.options.resolution) 88 result = inkcoverage.getInkCoverage(filename, cspace) 89 finally : 90 try : 91 os.remove(filename) 92 except OSError : 93 sys.stderr.write("Problem while trying to remove temporary file %s\n" % filename) 86 94 except pdlparser.PDLParserError, msg : 87 95 raise pdlparser.PDLParserError, "Unknown file format for %s (%s)" % (self.filename, msg) 88 finally : 96 finally : 89 97 self.closeFile() 90 98 return result -
pkpgcounter/trunk/pkpgpdls/dvi.py
r491 r492 32 32 class Parser(pdlparser.PDLParser) : 33 33 """A parser for DVI documents.""" 34 totiffcommands = [ ' cat >%(fname)s && dvips -q -o - %(fname)s | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ]34 totiffcommands = [ 'dvips -q -o - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -' ] 35 35 def isValid(self) : 36 36 """Returns True if data is DVI, else False.""" -
pkpgcounter/trunk/pkpgpdls/inkcoverage.py
r463 r492 116 116 else : 117 117 try : 118 while 1:118 while True : 119 119 nbpixels = image.size[0] * image.size[1] 120 120 result.append(computation(image, nbpixels)) -
pkpgcounter/trunk/pkpgpdls/pcl345.py
r491 r492 39 39 class Parser(pdlparser.PDLParser) : 40 40 """A parser for PCL3, PCL4, PCL5 documents.""" 41 totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r %(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',42 'pcl6 -sDEVICE=pswrite -r %(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',41 totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 42 'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 43 43 ] 44 44 mediasizes = { # ESC&l####A -
pkpgcounter/trunk/pkpgpdls/pclxl.py
r491 r492 33 33 class Parser(pdlparser.PDLParser) : 34 34 """A parser for PCLXL (aka PCL6) documents.""" 35 totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r %(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',36 'pcl6 -sDEVICE=pswrite -r %(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',35 totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 36 'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 37 37 ] 38 38 mediasizes = { -
pkpgcounter/trunk/pkpgpdls/pdf.py
r491 r492 43 43 class Parser(pdlparser.PDLParser) : 44 44 """A parser for PDF documents.""" 45 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r %(dpi)i -sOutputFile="%(fname)s" -' ]45 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ] 46 46 openmode = "rU" 47 47 def isValid(self) : -
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r491 r492 94 94 raise RuntimeError, "Not implemented !" 95 95 96 def convertToTiffMultiPage24NC(self, fname, dpi) :96 def convertToTiffMultiPage24NC(self, outfname, dpi) : 97 97 """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed. 98 Writes TIFF datas to the file named by fname.98 Writes TIFF datas to the file named by outfname. 99 99 """ 100 100 if self.totiffcommands : 101 infile = open(self.filename, "rb") 102 try : 103 for totiffcommand in self.totiffcommands : 104 infile.seek(0) 105 error = False 106 commandline = totiffcommand % locals() 107 child = popen2.Popen4(commandline) 108 try : 109 try : 110 data = infile.read(MEGABYTE) 111 while data : 112 child.tochild.write(data) 113 child.tochild.flush() 114 data = infile.read(MEGABYTE) 115 except (IOError, OSError) : 116 error = True 117 finally : 118 child.tochild.close() 119 dummy = child.fromchild.read() 120 child.fromchild.close() 121 122 try : 123 status = child.wait() 124 except OSError : 101 infname = self.filename 102 for totiffcommand in self.totiffcommands : 103 error = False 104 commandline = totiffcommand % locals() 105 # self.logdebug("Executing '%s'" % commandline) 106 status = os.system(commandline) 107 if os.WIFEXITED(status) : 108 if os.WEXITSTATUS(status) : 125 109 error = True 126 else : 127 if os.WIFEXITED(status) : 128 if os.WEXITSTATUS(status) : 129 error = True 130 else : 131 error = True 132 133 if not os.path.exists(fname) : 134 error = True 135 elif not os.stat(fname).st_size : 136 error = True 137 else : 138 break # Conversion worked fine it seems. 139 self.logdebug("Command failed : %s" % repr(commandline)) 140 finally : 141 infile.close() 110 else : 111 error = True 112 if not os.path.exists(outfname) : 113 error = True 114 elif not os.stat(outfname).st_size : 115 error = True 116 else : 117 break # Conversion worked fine it seems. 118 sys.stderr.write("Command failed : %s\n" % repr(commandline)) 142 119 if error : 143 120 raise PDLParserError, "Problem during conversion to TIFF." -
pkpgcounter/trunk/pkpgpdls/plain.py
r491 r492 28 28 class Parser(pdlparser.PDLParser) : 29 29 """A parser for plain text documents.""" 30 totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',31 'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',30 totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 31 'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 32 32 ] 33 33 openmode = "rU" -
pkpgcounter/trunk/pkpgpdls/postscript.py
r491 r492 33 33 class Parser(pdlparser.PDLParser) : 34 34 """A parser for PostScript documents.""" 35 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r %(dpi)i -sOutputFile="%(fname)s" -' ]35 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ] 36 36 openmode = "rU" 37 37 def isValid(self) : -
pkpgcounter/trunk/pkpgpdls/tiff.py
r491 r492 32 32 class Parser(pdlparser.PDLParser) : 33 33 """A parser for TIFF documents.""" 34 totiffcommands = [ "cat >%(fname)s"]34 totiffcommands = [ '/bin/cp "%(infname)s" "%(outfname)s"' ] 35 35 def isValid(self) : 36 36 """Returns True if data is TIFF, else False."""