Changeset 428 for pkpgcounter/trunk/pkpgpdls/pdlparser.py
- Timestamp:
- 10/17/06 09:41:55 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r425 r428 23 23 24 24 import sys 25 import os 25 26 import popen2 26 27 … … 41 42 class PDLParser : 42 43 """Generic PDL parser.""" 43 totiffcommand = None # Default command to convert to TIFF44 totiffcommands = None # Default command to convert to TIFF 44 45 def __init__(self, infile, debug=0, firstblock=None, lastblock=None) : 45 46 """Initialize the generic parser.""" … … 89 90 Writes TIFF datas to the file named by fname. 90 91 """ 91 if self.totiffcommand : 92 commandline = self.totiffcommand % locals() 93 child = popen2.Popen4(commandline) 94 try : 92 if self.totiffcommands : 93 for totiffcommand in self.totiffcommands : 94 self.infile.seek(0) 95 error = False 96 commandline = totiffcommand % locals() 97 child = popen2.Popen4(commandline) 95 98 try : 96 data = self.infile.read(MEGABYTE) 97 while data : 98 child.tochild.write(data) 99 data = self.infile.read(MEGABYTE) 100 except (IOError, OSError), msg : 101 raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 102 finally : 103 child.tochild.close() 104 child.fromchild.close() 105 106 try : 107 child.wait() 108 except OSError, msg : 109 raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 99 try : 100 data = self.infile.read(MEGABYTE) 101 while data : 102 child.tochild.write(data) 103 data = self.infile.read(MEGABYTE) 104 except (IOError, OSError) : 105 error = True 106 finally : 107 child.tochild.close() 108 child.fromchild.close() 109 110 try : 111 child.wait() 112 except OSError : 113 error = True 114 115 if not os.path.exists(fname) : 116 error = True 117 elif not os.stat(fname).st_size : 118 error = True 119 else : 120 break # Conversion worked fine it seems. 121 self.logdebug("Command failed : %s" % repr(commandline)) 122 if error : 123 raise PDLParserError, "Problem during conversion to TIFF." 110 124 else : 111 125 raise PDLParserError, "Impossible to compute ink coverage for this file format."