Changeset 527 for pkpgcounter/trunk/pkpgpdls
- Timestamp:
- 11/28/07 18:28:30 (17 years ago)
- Location:
- pkpgcounter/trunk/pkpgpdls
- Files:
-
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/analyzer.py
r524 r527 57 57 self.mustclose = None 58 58 59 def findExecutable(self, command) :60 """Finds an executable in the PATH and returns True if found else False."""61 for path in os.environ.get("PATH", "").split(":") :62 fullname = os.path.abspath(os.path.join(os.path.expanduser(path), command))63 if os.path.isfile(fullname) and os.access(fullname, os.X_OK) :64 return True65 return False66 67 59 def getJobSize(self) : 68 60 """Returns the job's size.""" … … 74 66 size = pdlhandler.getJobSize() 75 67 except pdlparser.PDLParserError, msg : 76 raise pdlparser.PDLParserError, "Un knownfile format for %s (%s)" % (self.filename, msg)68 raise pdlparser.PDLParserError, "Unsupported file format for %s (%s)" % (self.filename, msg) 77 69 finally : 78 70 self.closeFile() … … 98 90 dummyfile.close() 99 91 except pdlparser.PDLParserError, msg : 100 raise pdlparser.PDLParserError, "Un knownfile format for %s (%s)" % (self.filename, msg)92 raise pdlparser.PDLParserError, "Unsupported file format for %s (%s)" % (self.filename, msg) 101 93 finally : 102 94 self.closeFile() -
pkpgcounter/trunk/pkpgpdls/dvi.py
r522 r527 33 33 """A parser for DVI documents.""" 34 34 totiffcommands = [ 'dvips -q -o - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -' ] 35 required = [ "dvips", "gs" ] 35 36 def isValid(self) : 36 37 """Returns True if data is DVI, else False.""" -
pkpgcounter/trunk/pkpgpdls/inkcoverage.py
r520 r527 25 25 import sys 26 26 27 from PIL import Image 27 import pdlparser 28 28 29 import pdlparser 29 try : 30 from PIL import Image 31 except ImportError : 32 sys.stderr.write("ERROR: You MUST install the Python Imaging Library (python-imaging) for pkpgcounter to work.\n") 33 raise pdlparser.PDLParserError, "The Python Imaging Library is missing." 30 34 31 35 def getPercent(img, nbpix) : -
pkpgcounter/trunk/pkpgpdls/mscrap.py
r525 r527 32 32 """A parser for that MS crap thing.""" 33 33 totiffcommands = [ 'xvfb-run -a abiword --import-extension=.doc --print="| gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r\"%(dpi)i\" -sOutputFile=\"%(outfname)s\" -" "%(infname)s"' ] 34 required = [ "xvfb-run", "xauth", "abiword", "gs" ] 34 35 def isValid(self) : 35 36 """Returns True if data is MS crap, else False. … … 46 47 or self.firstblock[2112:].startswith("MSWordDoc") : 47 48 self.logdebug("DEBUG: Input file seems to be in a Microsoft shitty file format.") 48 return True 49 # Here we do the missing test because all commands will be needed even in page counting mode 50 if self.isMissing(self.required) : 51 return False 52 else : 53 return True 49 54 else : 50 55 return False -
pkpgcounter/trunk/pkpgpdls/ooo.py
r526 r527 31 31 """A parser for OpenOffice.org documents.""" 32 32 totiffcommands = [ 'xvfb-run -a abiword --import-extension=.odt --print="| gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r\"%(dpi)i\" -sOutputFile=\"%(outfname)s\" -" "%(infname)s"' ] 33 required = [ "xvfb-run", "xauth", "abiword", "gs" ] 33 34 def isValid(self) : 34 35 """Returns True if data is OpenDocument, else False.""" -
pkpgcounter/trunk/pkpgpdls/pcl345.py
r522 r527 42 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 required = [ "pcl6", "gs" ] 44 45 mediasizes = { # ESC&l####A 45 46 0 : "Default", -
pkpgcounter/trunk/pkpgpdls/pclxl.py
r522 r527 36 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 required = [ "pcl6", "gs" ] 38 39 mediasizes = { 39 40 0 : "Letter", -
pkpgcounter/trunk/pkpgpdls/pdf.py
r522 r527 44 44 """A parser for PDF documents.""" 45 45 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ] 46 required = [ "gs" ] 46 47 openmode = "rU" 47 48 def isValid(self) : -
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r522 r527 23 23 import sys 24 24 import os 25 import popen226 25 27 26 KILOBYTE = 1024 … … 41 40 class PDLParser : 42 41 """Generic PDL parser.""" 43 totiffcommands = None # Default command to convert to TIFF 44 openmode = "rb" # Default file opening mode 42 totiffcommands = None # Default command to convert to TIFF 43 required = [] # Default list of required commands 44 openmode = "rb" # Default file opening mode 45 45 def __init__(self, parent, (firstblock, lastblock)) : 46 46 """Initialize the generic parser.""" … … 71 71 self.infile.close() 72 72 73 def findExecutable(self, command) : 74 """Finds an executable in the PATH and returns True if found else False.""" 75 for cmd in [p.strip() for p in command.split("|")] : # | can separate alternatives for similar commands (e.g. a2ps|enscript) 76 for path in os.environ.get("PATH", "").split(":") : 77 fullname = os.path.abspath(os.path.join(os.path.expanduser(path), cmd)) 78 if os.path.isfile(fullname) and os.access(fullname, os.X_OK) : 79 return True 80 return False 81 82 def isMissing(self, commands) : 83 """Returns True if some required commands are missing, else False.""" 84 howmanythere = 0 85 for command in commands : 86 if not self.findExecutable(command) : 87 sys.stderr.write("ERROR: %(command)s is missing or not executable. You MUST install it for pkpgcounter to be able to do what you want.\n" % locals()) 88 sys.stderr.flush() 89 else : 90 howmanythere += 1 91 if howmanythere == len(commands) : 92 return False 93 else : 94 return True 95 73 96 def logdebug(self, message) : 74 97 """Logs a debug message if needed.""" … … 89 112 """ 90 113 if self.totiffcommands : 114 if self.isMissing(self.required) : 115 raise PDLParserError, "At least one of the following commands is missing and should be installed for the computation of ink coverage : %s" % repr(self.required) 91 116 infname = self.filename 92 117 for totiffcommand in self.totiffcommands : -
pkpgcounter/trunk/pkpgpdls/pil.py
r522 r527 23 23 """This modules implements a page counter for image formats supported by the Python Imaging Library.""" 24 24 25 from PIL import Image 25 import pdlparser 26 26 27 import pdlparser 27 try : 28 from PIL import Image 29 except ImportError : 30 sys.stderr.write("ERROR: You MUST install the Python Imaging Library (python-imaging) for pkpgcounter to work.\n") 31 raise pdlparser.PDLParserError, "The Python Imaging Library is missing." 32 28 33 import version 29 34 30 35 class Parser(pdlparser.PDLParser) : 31 36 """A parser for plain text documents.""" 32 totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ,33 ]37 totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ] 38 required = [ "convert" ] 34 39 def isValid(self) : 35 40 """Returns True if data is an image format supported by PIL, else False.""" -
pkpgcounter/trunk/pkpgpdls/plain.py
r522 r527 31 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 required = [ "a2ps | enscript", "gs" ] 33 34 openmode = "rU" 34 35 def isValid(self) : -
pkpgcounter/trunk/pkpgpdls/postscript.py
r522 r527 25 25 import sys 26 26 import os 27 import tempfile28 import popen229 27 30 28 import pdlparser … … 34 32 """A parser for PostScript documents.""" 35 33 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ] 34 required = [ "gs" ] 36 35 openmode = "rU" 37 36 def isValid(self) : … … 53 52 """Get the count through GhostScript, useful for non-DSC compliant PS files.""" 54 53 self.logdebug("Internal parser sucks, using GhostScript instead...") 54 if self.isMissing(self.required) : 55 raise pdlparser.PDLParserError, "The gs interpreter is nowhere to be found in your PATH (%s)" % os.environ.get("PATH", "") 55 56 infname = self.filename 56 57 command = 'gs -sDEVICE=bbox -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET "%(infname)s" 2>&1 | grep -c "%%HiResBoundingBox:" 2>/dev/null' -
pkpgcounter/trunk/pkpgpdls/tiff.py
r522 r527 32 32 class Parser(pdlparser.PDLParser) : 33 33 """A parser for TIFF documents.""" 34 totiffcommands = [ '/bin/cp "%(infname)s" "%(outfname)s"' ] 34 totiffcommands = [ 'cp "%(infname)s" "%(outfname)s"' ] 35 required = [ "cp" ] 35 36 def isValid(self) : 36 37 """Returns True if data is TIFF, else False."""