Changeset 3436 for pkpgcounter/trunk/pkpgpdls/postscript.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/postscript.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/>. … … 34 34 openmode = "rU" 35 35 format = "PostScript" 36 def isValid(self) : 36 def isValid(self) : 37 37 """Returns True if data is PostScript, else False.""" 38 38 if self.firstblock.startswith("%!") or \ … … 45 45 (self.firstblock.find("%!PS-Adobe") != -1) : 46 46 return True 47 else : 47 else : 48 48 return False 49 49 50 50 def throughGhostScript(self) : 51 51 """Get the count through GhostScript, useful for non-DSC compliant PS files.""" … … 62 62 except (IOError, OSError, AttributeError, ValueError), msg : 63 63 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document : %s" % msg 64 finally : 64 finally : 65 65 if fromchild.close() is not None : 66 66 raise pdlparser.PDLParserError, "Problem during analysis of Binary PostScript document" 67 self.logdebug("GhostScript said : %s pages" % pagecount) 67 self.logdebug("GhostScript said : %s pages" % pagecount) 68 68 return pagecount * self.copies 69 70 def setcopies(self, pagenum, txtvalue) : 69 70 def setcopies(self, pagenum, txtvalue) : 71 71 """Tries to extract a number of copies from a textual value and set the instance attributes accordingly.""" 72 72 try : 73 73 number = int(txtvalue) 74 except (ValueError, TypeError) : 74 except (ValueError, TypeError) : 75 75 pass 76 else : 76 else : 77 77 if number > self.pages[pagenum]["copies"] : 78 78 self.pages[pagenum]["copies"] = number 79 79 80 80 def natively(self) : 81 81 """Count pages in a DSC compliant PostScript document.""" … … 94 94 if nbparts >= 1 : 95 95 part0 = parts[0] 96 else : 96 else : 97 97 part0 = "" 98 98 if part0 == r"%ADOPrintSettings:" : 99 99 acrobatmarker = True 100 elif part0 == "!R!" : 100 elif part0 == "!R!" : 101 101 prescribe = True 102 102 elif part0 == r"%%Pages:" : … … 119 119 if nbparts > 1 : 120 120 self.setcopies(pagecount, parts[1]) 121 elif part0 == r"%RBINumCopies:" : 121 elif part0 == r"%RBINumCopies:" : 122 122 if nbparts > 1 : 123 123 self.setcopies(pagecount, parts[1]) … … 135 135 # treats both "%%Page: x x" and "%%Page: (x-y) z" (probably N-up mode) 136 136 newpagenum = int(line.split(']')[0].split()[-1]) 137 except : 137 except : 138 138 notinteger = True # It seems that sometimes it's not an integer but an EPS file name 139 else : 139 else : 140 140 notinteger = False 141 141 if newpagenum == oldpagenum : … … 143 143 else : 144 144 oldpagenum = newpagenum 145 if proceed and not notinteger : 145 if proceed and not notinteger : 146 146 pagecount += 1 147 147 self.pages[pagecount] = { "copies" : self.pages[pagecount-1]["copies"] } … … 155 155 self.setcopies(pagecount, part0) 156 156 previousline = line 157 158 # extract max number of copies to please the ghostscript parser, just 157 158 # extract max number of copies to please the ghostscript parser, just 159 159 # in case we will use it later 160 160 self.copies = max([ v["copies"] for (k, v) in self.pages.items() ]) 161 161 162 162 # now apply the number of copies to each page 163 if not pagecount and pagescomment : 163 if not pagecount and pagescomment : 164 164 pagecount = pagescomment 165 165 for pnum in range(1, pagecount + 1) : … … 168 168 pagecount += (copies - 1) 169 169 self.logdebug("%s * page #%s" % (copies, pnum)) 170 170 171 171 self.logdebug("Internal parser said : %s pages" % pagecount) 172 172 return (pagecount, notrust) 173 174 def getJobSize(self) : 173 174 def getJobSize(self) : 175 175 """Count pages in PostScript document.""" 176 176 self.copies = 1 … … 182 182 except pdlparser.PDLParserError, msg : 183 183 self.logdebug(msg) 184 return max(nbpages, newnbpages) 184 return max(nbpages, newnbpages)