Changeset 521 for pkpgcounter/trunk/pkpgpdls
- Timestamp:
- 11/28/07 01:08:32 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/postscript.py
r520 r521 53 53 """Get the count through GhostScript, useful for non-DSC compliant PS files.""" 54 54 self.logdebug("Internal parser sucks, using GhostScript instead...") 55 command = 'gs -sDEVICE=bbox -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET - 2>&1 | grep -c "%%HiResBoundingBox:" 2>/dev/null' 55 infname = self.parent.filename 56 command = 'gs -sDEVICE=bbox -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET "%(infname)s" 2>&1 | grep -c "%%HiResBoundingBox:" 2>/dev/null' 56 57 pagecount = 0 57 # we need to reopen the input file in binary mode again, just in case 58 # otherwise we might break the original file's contents. 59 infile = open(self.parent.filename, "rb") 58 fromchild = os.popen(command % locals(), "r") 60 59 try : 61 child = popen2.Popen4(command)62 60 try : 63 data = infile.read(pdlparser.MEGABYTE) 64 while data : 65 child.tochild.write(data) 66 data = infile.read(pdlparser.MEGABYTE) 67 child.tochild.flush() 68 child.tochild.close() 69 except (IOError, OSError), msg : 70 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg 71 72 pagecount = 0 73 try : 74 pagecount = int(child.fromchild.readline().strip()) 61 pagecount = int(fromchild.readline().strip()) 75 62 except (IOError, OSError, AttributeError, ValueError), msg : 76 63 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg 77 child.fromchild.close()78 79 try :80 child.wait()81 except OSError, msg :82 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg83 64 finally : 84 infile.close() 65 if fromchild.close() is not None : 66 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document" 85 67 self.logdebug("GhostScript said : %s pages" % pagecount) 86 68 return pagecount * self.copies … … 92 74 oldpagenum = None 93 75 previousline = "" 94 notrust = 095 prescribe = 0# Kyocera's Prescribe commands96 acrobatmarker = 076 notrust = False 77 prescribe = False # Kyocera's Prescribe commands 78 acrobatmarker = False 97 79 pagescomment = None 98 80 for line in self.infile : … … 100 82 if (not prescribe) and line.startswith(r"%%BeginResource: procset pdf") \ 101 83 and not acrobatmarker : 102 notrust = 1# Let this stuff be managed by GhostScript, but we still extract number of copies84 notrust = True # Let this stuff be managed by GhostScript, but we still extract number of copies 103 85 elif line.startswith(r"%ADOPrintSettings: L") : 104 acrobatmarker = 186 acrobatmarker = True 105 87 elif line.startswith("!R!") : 106 prescribe = 188 prescribe = True 107 89 elif line.startswith(r"%%Pages: ") : 108 90 try :