Changeset 253
- Timestamp:
- 09/03/05 09:29:28 (19 years ago)
- Location:
- pkpgcounter/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/NEWS
r252 r253 22 22 pkpgcounter News : 23 23 24 * 1.63 : 25 26 - Now handles PJL statements to extract number of copies, duplex mode 27 and paper size in the PCLXL and PCL3/4/5 parsers. 28 24 29 * 1.62 : 25 30 -
pkpgcounter/trunk/pkpgpdls/pcl345.py
r252 r253 27 27 28 28 import pdlparser 29 import pjl 29 30 30 31 class Parser(pdlparser.PDLParser) : … … 91 92 def setPageDict(self, pages, number, attribute, value) : 92 93 """Initializes a page dictionnary.""" 93 dic = pages.setdefault(number, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : []})94 dic = pages.setdefault(number, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : ""}) 94 95 dic[attribute] = value 95 96 … … 146 147 pagecount += 1 147 148 elif char == "\033" : 149 starb = ampl = 0 148 150 if minfile[pos : pos+8] == r"%-12345X" : 149 151 endpos = pos + 9 150 152 while (minfile[endpos] not in endmark) and (minfile[endpos] < asciilimit) : 151 153 endpos += 1 152 self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos].replace('\r\n', '\n').split('\n')) 153 self.logdebug("Escaped datas : [%s]" % repr(minfile[pos : endpos])) 154 self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos]) 154 155 pos += (endpos - pos) 155 156 else : 156 starb = ampl = 0157 157 # 158 158 # <ESC>*b###y#m###v###w... -> PCL3 raster graphics … … 349 349 pagecount = abs(startgfx - endgfx) 350 350 351 pjlstatements = [] 351 defaultpjlcopies = 1 352 defaultduplexmode = "Simplex" 353 defaultpapersize = "" 354 oldpjlcopies = -1 355 oldduplexmode = "" 356 oldpapersize = "" 352 357 for pnum in range(pagecount) : 353 358 # if no number of copies defined, take the preceding one else the one set before any page else 1. 354 page = pages.get(pnum, pages.get(pnum - 1, pages.get(0, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : []})))359 page = pages.get(pnum, pages.get(pnum - 1, pages.get(0, { "copies" : 1, "mediasource" : "Main", "mediasize" : "Default", "mediatype" : "Plain", "orientation" : "Portrait", "escaped" : ""}))) 355 360 pjlstuff = page["escaped"] 356 if not pjlstuff : 357 pjlcopies = 1 358 else : 359 pjlstatements.extend(pjlstuff) 360 newpjl = "\n".join(pjlstatements) 361 copiesstatement = newpjl.rfind("@PJL SET COPIES=") 362 qtystatement = newpjl.rfind("@PJL SET QTY=") 363 if copiesstatement > qtystatement : 364 # we use the COPIES= statement 365 try : 366 pjlcopies = int(newpjl[copiesstatement+16:].split()[0].strip()) 367 except : 368 pjlcopies = 1 369 elif qtystatement > copiesstatement : 370 # we use the QTY= statement 371 try : 372 pjlcopies = int(newpjl[qtystatement+13:].split()[0].strip()) 373 except : 374 pjlcopies = 1 361 if pjlstuff : 362 pjlparser = pjl.PJLParser(pjlstuff) 363 nbdefaultcopies = int(pjlparser.default_variables.get("COPIES", -1)) 364 nbcopies = int(pjlparser.environment_variables.get("COPIES", -1)) 365 nbdefaultqty = int(pjlparser.default_variables.get("QTY", -1)) 366 nbqty = int(pjlparser.environment_variables.get("QTY", -1)) 367 if nbdefaultcopies > -1 : 368 defaultpjlcopies = nbdefaultcopies 369 if nbdefaultqty > -1 : 370 defaultpjlcopies = nbdefaultqty 371 if nbcopies > -1 : 372 pjlcopies = nbcopies 373 elif nbqty > -1 : 374 pjlcopies = nbqty 375 375 else : 376 # both can't be equal unless they both equal -1 (not found) 377 pjlcopies = 1 376 if oldpjlcopies == -1 : 377 pjlcopies = defaultpjlcopies 378 else : 379 pjlcopies = oldpjlcopies 380 defaultdm = pjlparser.default_variables.get("DUPLEX", "") 381 if defaultdm : 382 if defaultdm.upper() == "ON" : 383 defaultduplexmode = "Duplex" 384 else : 385 defaultduplexmode = "Simplex" 386 envdm = pjlparser.environment_variables.get("DUPLEX", "") 387 if envdm : 388 if envdm.upper() == "ON" : 389 duplexmode = "Duplex" 390 else : 391 duplexmode = "Simplex" 392 else : 393 if not oldduplexmode : 394 duplexmode = defaultduplexmode 395 else : 396 duplexmode = oldduplexmode 397 defaultps = pjlparser.default_variables.get("PAPER", "") 398 if defaultps : 399 defaultpapersize = defaultps 400 envps = pjlparser.environment_variables.get("PAPER", "") 401 if envps : 402 papersize = envps 403 else : 404 if not oldpapersize : 405 papersize = defaultpapersize 406 else : 407 papersize = oldpapersize 408 else : 409 if oldpjlcopies == -1 : 410 pjlcopies = defaultpjlcopies 411 else : 412 pjlcopies = oldpjlcopies 413 if not oldduplexmode : 414 duplexmode = defaultduplexmode 415 else : 416 duplexmode = oldduplexmode 417 if not oldpapersize : 418 papersize = defaultpapersize 419 else : 420 papersize = oldpapersize 421 duplexmode = oldduplexmode 422 papersize = oldpapersize or page["mediasize"] 423 if page["mediasize"] != "Default" : 424 papersize = page["mediasize"] 425 if not duplexmode : 426 duplexmode = oldduplexmode or defaultduplexmode 427 oldpjlcopies = pjlcopies 428 oldduplexmode = duplexmode 429 oldpapersize = papersize 378 430 copies = pjlcopies * page["copies"] 379 431 pagecount += (copies - 1) 380 self.logdebug("%s*%s*%s*%s*%s " % (copies, \432 self.logdebug("%s*%s*%s*%s*%s*%s*BW" % (copies, \ 381 433 page["mediatype"], \ 382 pa ge["mediasize"], \434 papersize, \ 383 435 page["orientation"], \ 384 page["mediasource"])) 436 page["mediasource"], \ 437 duplexmode)) 385 438 386 439 return pagecount -
pkpgcounter/trunk/pkpgpdls/pclxl.py
r252 r253 486 486 colormode = "Color" 487 487 else : 488 colormode = "Black" 489 488 colormode = "BW" 489 490 defaultduplexmode = "Simplex" 491 defaultpapersize = "" 490 492 defaultpjlcopies = 1 491 493 oldpjlcopies = -1 494 oldduplexmode = "" 495 oldpapersize = "" 492 496 for pnum in range(1, self.pagecount + 1) : 493 497 # if no number of copies defined, take 1, as explained … … 496 500 # but the formula below is still correct : we want 497 501 # to decrease the total number of pages in this case. 498 page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1 }))502 page = self.pages.get(pnum, self.pages.get(1, { "copies" : 1, "mediasize" : "Default" })) 499 503 pjlstuff = self.escapedStuff.get(pnum, []) 500 504 if pjlstuff : … … 509 513 defaultpjlcopies = nbdefaultqty 510 514 if nbcopies > -1 : 511 oldpjlcopies =pjlcopies = nbcopies515 pjlcopies = nbcopies 512 516 elif nbqty > -1 : 513 oldpjlcopies =pjlcopies = nbqty517 pjlcopies = nbqty 514 518 else : 515 519 if oldpjlcopies == -1 : 516 oldpjlcopies = defaultpjlcopies 517 pjlcopies = oldpjlcopies 520 pjlcopies = defaultpjlcopies 521 else : 522 pjlcopies = oldpjlcopies 523 defaultdm = pjlparser.default_variables.get("DUPLEX", "") 524 if defaultdm : 525 if defaultdm.upper() == "ON" : 526 defaultduplexmode = "Duplex" 527 else : 528 defaultduplexmode = "Simplex" 529 envdm = pjlparser.environment_variables.get("DUPLEX", "") 530 if envdm : 531 if envdm.upper() == "ON" : 532 duplexmode = "Duplex" 533 else : 534 duplexmode = "Simplex" 535 else : 536 if not oldduplexmode : 537 duplexmode = defaultduplexmode 538 else : 539 duplexmode = oldduplexmode 540 defaultps = pjlparser.default_variables.get("PAPER", "") 541 if defaultps : 542 defaultpapersize = defaultps 543 envps = pjlparser.environment_variables.get("PAPER", "") 544 if envps : 545 papersize = envps 546 else : 547 if not oldpapersize : 548 papersize = defaultpapersize 549 else : 550 papersize = oldpapersize 518 551 else : 519 552 if oldpjlcopies == -1 : … … 521 554 else : 522 555 pjlcopies = oldpjlcopies 556 if not oldduplexmode : 557 duplexmode = defaultduplexmode 558 else : 559 duplexmode = oldduplexmode 560 if not oldpapersize : 561 papersize = defaultpapersize 562 else : 563 papersize = oldpapersize 564 duplexmode = oldduplexmode 565 papersize = oldpapersize or page["mediasize"] 566 if page["mediasize"] != "Default" : 567 papersize = page["mediasize"] 568 if not duplexmode : 569 duplexmode = oldduplexmode or defaultduplexmode 570 oldpjlcopies = pjlcopies 571 oldduplexmode = duplexmode 572 oldpapersize = papersize 523 573 copies = pjlcopies * page["copies"] 524 574 self.pagecount += (copies - 1) 525 self.logdebug("%s*%s*%s*%s*%s*%s " % (copies,575 self.logdebug("%s*%s*%s*%s*%s*%s*%s" % (copies, 526 576 page["mediatype"], 527 pa ge["mediasize"],577 papersize, 528 578 page["orientation"], 529 579 page["mediasource"], 580 duplexmode, 530 581 colormode)) 531 582 return self.pagecount -
pkpgcounter/trunk/pkpgpdls/version.py
r252 r253 20 20 # 21 21 22 __version__ = "1.6 2"22 __version__ = "1.63" 23 23 24 24 __doc__ = """pkpgcounter : a generic Page Description Languages parser."""