Show
Ignore:
Timestamp:
09/03/05 00:40:57 (19 years ago)
Author:
jerome
Message:

Added a PJL parsing module to extract SET and DEFAULT statements.
Improved general readability.
Fixed some minor problems thanks to pychecker.

Files:
1 modified

Legend:

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

    r248 r252  
    2828 
    2929import pdlparser 
     30import pjl 
    3031 
    3132class Parser(pdlparser.PDLParser) : 
     
    8283             ((self.firstblock.find("LANGUAGE=PCLXL") != -1) or \ 
    8384              (self.firstblock.find("LANGUAGE = PCLXL") != -1))) : 
    84             if self.debug :   
    85                 sys.stderr.write("DEBUG: Input file is in the PCLXL (aka PCL6) format.\n") 
     85            self.logdebug("DEBUG: Input file is in the PCLXL (aka PCL6) format.") 
    8686            return 1 
    8787        else :     
     
    116116            elif val == 0x28 :     
    117117                orientation = ord(minfile[pos - 2]) 
    118                 orienationlabel = self.orientations.get(orientation, str(orientation)) 
     118                orientationlabel = self.orientations.get(orientation, str(orientation)) 
    119119                pos = pos - 4 
    120120            elif val == 0x27 :     
     
    246246    def reservedForFutureUse(self) : 
    247247        """Outputs something when a reserved byte is encountered.""" 
    248         if self.debug : 
    249             sys.stderr.write("Byte at %s is out of the PCLXL Protocol Class 2.0 Specification\n" % self.pos) 
     248        self.logdebug("Byte at %s is out of the PCLXL Protocol Class 2.0 Specification" % self.pos) 
    250249        return 0     
    251250         
     
    255254        if self.minfile[pos : pos+8] == r"%-12345X" : 
    256255            endpos = pos + 9 
    257             endmark = chr(0x0c) + chr(0x00) 
     256            endmark = chr(0x0c) + chr(0x00) + chr(0x1b) 
    258257            asciilimit = chr(0x80) 
    259258            while (self.minfile[endpos] not in endmark) and (self.minfile[endpos] < asciilimit) : 
     
    264263            stuff = self.escapedStuff.setdefault(self.pagecount, []) 
    265264            stuff.append(self.minfile[pos : endpos]) 
    266             if self.debug : 
    267                 sys.stderr.write("Escaped datas : [%s]\n" % repr(self.minfile[pos : endpos])) 
     265            self.logdebug("Escaped datas : [%s]" % repr(self.minfile[pos : endpos])) 
    268266        return endpos - pos 
    269267         
     
    489487        else :     
    490488            colormode = "Black" 
     489             
     490        defaultpjlcopies = 1     
     491        oldpjlcopies = -1 
    491492        for pnum in range(1, self.pagecount + 1) : 
    492493            # if no number of copies defined, take 1, as explained 
     
    496497            # to decrease the total number of pages in this case. 
    497498            page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1 })) 
    498             copies = page["copies"] 
     499            pjlstuff = self.escapedStuff.get(pnum, []) 
     500            if pjlstuff : 
     501                pjlparser = pjl.PJLParser("".join(pjlstuff)) 
     502                nbdefaultcopies = int(pjlparser.default_variables.get("COPIES", -1)) 
     503                nbcopies = int(pjlparser.environment_variables.get("COPIES", -1)) 
     504                nbdefaultqty = int(pjlparser.default_variables.get("QTY", -1)) 
     505                nbqty = int(pjlparser.environment_variables.get("QTY", -1)) 
     506                if nbdefaultcopies > -1 : 
     507                    defaultpjlcopies = nbdefaultcopies 
     508                if nbdefaultqty > -1 : 
     509                    defaultpjlcopies = nbdefaultqty 
     510                if nbcopies > -1 : 
     511                    oldpjlcopies = pjlcopies = nbcopies 
     512                elif nbqty > -1 : 
     513                    oldpjlcopies = pjlcopies = nbqty 
     514                else : 
     515                    if oldpjlcopies == -1 :     
     516                        oldpjlcopies = defaultpjlcopies 
     517                    pjlcopies = oldpjlcopies     
     518            else :         
     519                if oldpjlcopies == -1 : 
     520                    pjlcopies = defaultpjlcopies 
     521                else :     
     522                    pjlcopies = oldpjlcopies 
     523            copies = pjlcopies * page["copies"] 
    499524            self.pagecount += (copies - 1) 
    500             if self.debug : 
    501                 sys.stderr.write("%s*%s*%s*%s*%s*%s\n" % (copies,  
    502                                                           page["mediatype"],  
    503                                                           page["mediasize"],  
    504                                                           page["orientation"],  
    505                                                           page["mediasource"],  
    506                                                           colormode)) 
     525            self.logdebug("%s*%s*%s*%s*%s*%s" % (copies,  
     526                                                 page["mediatype"],  
     527                                                 page["mediasize"],  
     528                                                 page["orientation"],  
     529                                                 page["mediasource"],  
     530                                                 colormode)) 
    507531        return self.pagecount 
    508532