Changeset 3436 for pkpgcounter/trunk/pkpgpdls/pdlparser.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r3410 r3436 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/>. … … 25 25 import os 26 26 27 KILOBYTE = 1024 28 MEGABYTE = 1024 * KILOBYTE 27 KILOBYTE = 1024 28 MEGABYTE = 1024 * KILOBYTE 29 29 FIRSTBLOCKSIZE = 16 * KILOBYTE 30 30 LASTBLOCKSIZE = int(KILOBYTE / 4) … … 38 38 return self.message 39 39 __str__ = __repr__ 40 40 41 41 class PDLParser : 42 42 """Generic PDL parser.""" … … 56 56 if not self.isValid() : 57 57 raise PDLParserError, "Invalid file format !" 58 else : 58 else : 59 59 self.logdebug("Input file is in the '%s' file format." % self.format) 60 60 try : 61 import psyco 62 except ImportError : 61 import psyco 62 except ImportError : 63 63 pass # Psyco is not installed 64 else : 64 else : 65 65 # Psyco is installed, tell it to compile 66 66 # the CPU intensive methods : PCL and PCLXL … … 69 69 self.infile = open(self.filename, self.openmode) 70 70 # self.logdebug("Opened %s in '%s' mode." % (self.filename, self.openmode)) 71 71 72 72 def __del__(self) : 73 73 """Ensures the input file gets closed.""" 74 74 if self.infile : 75 75 self.infile.close() 76 76 77 77 def findExecutable(self, command) : 78 78 """Finds an executable in the PATH and returns True if found else False.""" … … 83 83 return True 84 84 return False 85 86 def isMissing(self, commands) : 87 """Returns True if some required commands are missing, else False.""" 85 86 def isMissing(self, commands) : 87 """Returns True if some required commands are missing, else False.""" 88 88 howmanythere = 0 89 89 for command in commands : … … 91 91 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()) 92 92 sys.stderr.flush() 93 else : 93 else : 94 94 howmanythere += 1 95 95 if howmanythere == len(commands) : 96 96 return False 97 else : 97 else : 98 98 return True 99 100 def logdebug(self, message) : 99 100 def logdebug(self, message) : 101 101 """Logs a debug message if needed.""" 102 102 if self.parent.options.debug : 103 103 sys.stderr.write("%s\n" % message) 104 105 def isValid(self) : 104 105 def isValid(self) : 106 106 """Returns True if data is in the expected format, else False.""" 107 107 raise RuntimeError, "Not implemented !" 108 109 def getJobSize(self) : 108 109 def getJobSize(self) : 110 110 """Counts pages in a document.""" 111 111 raise RuntimeError, "Not implemented !" 112 112 113 113 def convertToTiffMultiPage24NC(self, outfname, dpi) : 114 114 """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed. 115 115 Writes TIFF datas to the file named by outfname. 116 """ 116 """ 117 117 if self.totiffcommands : 118 118 if self.isMissing(self.required) : … … 127 127 if os.WEXITSTATUS(status) : 128 128 error = True 129 else : 129 else : 130 130 error = True 131 131 if not os.path.exists(outfname) : … … 133 133 elif not os.stat(outfname).st_size : 134 134 error = True 135 else : 135 else : 136 136 break # Conversion worked fine it seems. 137 137 sys.stderr.write("Command failed : %s\n" % repr(commandline)) 138 138 if error : 139 139 raise PDLParserError, "Problem during conversion to TIFF." 140 else : 140 else : 141 141 raise PDLParserError, "Impossible to compute ink coverage for this file format."