Changeset 472

Show
Ignore:
Timestamp:
09/19/07 14:20:25 (17 years ago)
Author:
jerome
Message:

Improved the detection of ESC/P2.
Made the PJL parser also handle EJL (in a limited way).

Location:
pkpgcounter/trunk/pkpgpdls
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/escp2.py

    r463 r472  
    3434           self.firstblock.startswith("\033*") or \ 
    3535           self.firstblock.startswith("\n\033@") or \ 
     36           self.firstblock.startswith("\033\1@EJL") or \ 
    3637           self.firstblock.startswith("\0\0\0\033\1@EJL") : # ESC/P Raster ??? Seen on Stylus Photo 1284 
    3738            self.logdebug("DEBUG: Input file is in the ESC/P2 format.") 
  • pkpgcounter/trunk/pkpgpdls/pjl.py

    r463 r472  
    2121# 
    2222 
    23 """This modules implements a really minimalist PJL parser.""" 
     23"""This modules implements a really minimalist PJL/EJL parser.""" 
    2424 
    2525# NOTES : QTY= is the number of collated copies for a job. 
     
    4242       Information extracted for bpl11897.pdf which was 
    4343       downloaded from Hewlett-Packard's website. 
    44      
    45        Only extracts the PJL SET variables. Ignore other statements. 
    4644    """ 
     45    JL = "PJL" 
    4746    def __init__(self, pjljob, debug=0) : 
    48         """Initializes PJL Parser.""" 
     47        """Initializes JL Parser.""" 
    4948        self.debug = debug 
     49        self.jlmarker = "@%s" % self.JL 
    5050        self.statements = pjljob.replace("\r\n", "\n").split("\n") 
    5151        self.default_variables = {} 
     
    8383         
    8484    def parse(self) : 
    85         """Parses a PJL job.""" 
     85        """Parses a JL job.""" 
    8686        for i in range(len(self.statements)) : 
    8787            statement = self.statements[i] 
    88             if statement.startswith("@PJL") : 
     88            if statement.startswith(self.jlmarker) : 
    8989                parts = statement.split() 
    9090                nbparts = len(parts) 
    91                 if parts[0] == "@PJL" : 
    92                     # this is a valid PJL statement, but we don't 
     91                if parts[0] == self.jlmarker : 
     92                    # this is a valid JL statement, but we don't 
    9393                    # want to examine all of them... 
    94                     if (nbparts > 2) and (parts[1].upper() in ("SET", "DEFAULT")) : 
     94                    if (nbparts > 2) \ 
     95                         and ((parts[1].upper() in ("SET", "DEFAULT")) \ 
     96                                  or ((self.jlmarker == "@EJL") and (parts[1].upper() == "JI"))) : 
    9597                        # this is what we are interested in ! 
    9698                        try :     
    97                             (varname, value) = "".join(parts[2:]).split("=", 1) 
     99                            (varname, value) = "".join(parts[2:]).split("=", 1) # TODO : parse multiple assignments on the same SET/JI statement 
    98100                        except :     
    99                             self.logdebug("Invalid PJL SET statement [%s]" % repr(statement)) 
     101                            self.logdebug("Invalid JL SET statement [%s]" % repr(statement)) 
    100102                        else :     
    101103                            # all still looks fine... 
     
    107109                            variable.append(value) 
    108110                    else : 
    109                         self.logdebug("Ignored PJL statement [%s]" % repr(statement)) 
     111                        self.logdebug("Ignored JL statement [%s]" % repr(statement)) 
     112                        self.logdebug(parts) 
    110113                else : 
    111                     self.logdebug("Invalid PJL statement [%s]" % repr(statement)) 
     114                    self.logdebug("Invalid JL statement [%s]" % repr(statement)) 
    112115            else : 
    113                 self.logdebug("Invalid PJL statement [%s]" % repr(statement)) 
     116                self.logdebug("Invalid JL statement [%s]" % repr(statement)) 
    114117        self.cleanvars() 
    115118        self.parsed = 1 
     119         
     120class EJLParser(PJLParser) : 
     121    """A parser for EJL (Epson Job Language) documents.""" 
     122    JL = "EJL" 
    116123         
    117124def test() :         
     
    120127        sys.argv.append("-") 
    121128    for arg in sys.argv[1:] : 
     129        klass = PJLParser 
    122130        if arg == "-" : 
    123131            infile = sys.stdin 
    124132            mustclose = 0 
    125133        else :     
     134            if arg.endswith(".ejl") : 
     135                klass = EJLParser 
    126136            infile = open(arg, "rb") 
    127137            mustclose = 1 
    128138        try : 
    129             parser = PJLParser(infile.read(), debug=1) 
     139            parser = klass(infile.read(), debug=1) 
    130140        except PJLParserError, msg :     
    131141            sys.stderr.write("ERROR: %s\n" % msg)