Changeset 527 for pkpgcounter/trunk/pkpgpdls/pdlparser.py
- Timestamp:
- 11/28/07 18:28:30 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 :