root / pkpgcounter / trunk / pkpgpdls / pnmascii.py @ 3434

Revision 3410, 1.9 kB (checked in by jerome, 16 years ago)

Changed coding statement to please this fucking Emacs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# -*- coding: utf-8 -*-
2#
3# pkpgcounter : a generic Page Description Language parser
4#
5# (c) 2003, 2004, 2005, 2006, 2007, 2008 Jerome Alet <alet@librelogiciel.com>
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19# $Id$
20#
21
22"""This modules implements a page counter for PNM (ascii) documents."""
23
24import pdlparser
25
26class Parser(pdlparser.PDLParser) :
27    """A parser for PNM (ascii) documents."""
28    openmode = "rU"                 
29    format = "PNM (ascii)"
30    def isValid(self) :   
31        """Returns True if data is ASCII PNM, else False."""
32        if self.firstblock.split()[0] in ("P1", "P2", "P3") :
33            self.marker = self.firstblock[:2]
34            return True
35        else :   
36            return False
37           
38    def getJobSize(self) :
39        """Counts pages in a PNM (ascii) document."""
40        pagecount = 0
41        linecount = 0
42        divby = 1
43        marker = self.marker
44        for line in self.infile :
45            linecount += 1
46            if (linecount == 2) and (line.find("device=pksm") != -1) :
47                # Special case of cmyk map
48                divby = 4
49            # Unfortunately any whitespace is valid,
50            # so we do it the slow way...
51            pagecount += line.split().count(marker)
52           
53        if not (pagecount % divby) :   
54            return pagecount // divby
55        else :   
56            return pagecount
Note: See TracBrowser for help on using the browser.