root / pkpgcounter / trunk / pkpgpdls / lidil.py @ 484

Revision 484, 2.3 kB (checked in by jerome, 16 years ago)

Added the eject page marker.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2# -*- coding: ISO-8859-15 -*-
3#
4# pkpgcounter : a generic Page Description Language parser
5#
6# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com>
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20# $Id$
21#
22
23"""This modules implements a page counter for HP LIDIL format.
24
25   Documentation used :
26   
27        hplip-2.7.10/prnt/ldl.py
28        hplip-2.7.10/prnt/hpijs/ldlencap.h
29"""
30
31import sys
32import os
33import mmap
34from struct import unpack
35
36import pdlparser
37
38class Parser(pdlparser.PDLParser) :
39    """A parser for HP LIDIL documents."""
40    def isValid(self) :   
41        """Returns True if data is LIDIL, else False."""
42        # Beginning Of File marker is a Sync packet, followed with
43        # a Sync Complete packet followed with a Reset packet.
44        # We just look at the start of the Sync packet for simplicity's sake.
45        BOFMarker = "$\x01\x00\x00\x07"
46        # End Of File marker is a Sync Complete packet followed
47        # with a Reset packet. We ignore the preceding Sync packet
48        # for simplicity's sake.
49        EOFMarker = "$\x00\x10\x00\x08\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$$\x00\x10\x00\x06\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$" 
50        if self.firstblock.startswith(BOFMarker) \
51           and self.lastblock.endswith(EOFMarker) :
52            self.logdebug("DEBUG: Input file is in the Hewlett-Packard LIDIL format.")
53            return True
54        else :   
55            return False
56       
57    def getJobSize(self) :
58        """Computes the number of pages in a HP LIDIL document."""
59        ejectpagemarker = "$\x00\x01\x00\x00\x02" # ensure it's a complete packet (ends with '$')
60        return 0
61
62if __name__ == "__main__" :   
63    pdlparser.test(Parser)
Note: See TracBrowser for help on using the browser.