Changeset 472 for pkpgcounter/trunk/pkpgpdls/pjl.py
- Timestamp:
- 09/19/07 14:20:25 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pjl.py
r463 r472 21 21 # 22 22 23 """This modules implements a really minimalist PJL parser."""23 """This modules implements a really minimalist PJL/EJL parser.""" 24 24 25 25 # NOTES : QTY= is the number of collated copies for a job. … … 42 42 Information extracted for bpl11897.pdf which was 43 43 downloaded from Hewlett-Packard's website. 44 45 Only extracts the PJL SET variables. Ignore other statements.46 44 """ 45 JL = "PJL" 47 46 def __init__(self, pjljob, debug=0) : 48 """Initializes PJL Parser."""47 """Initializes JL Parser.""" 49 48 self.debug = debug 49 self.jlmarker = "@%s" % self.JL 50 50 self.statements = pjljob.replace("\r\n", "\n").split("\n") 51 51 self.default_variables = {} … … 83 83 84 84 def parse(self) : 85 """Parses a PJL job."""85 """Parses a JL job.""" 86 86 for i in range(len(self.statements)) : 87 87 statement = self.statements[i] 88 if statement.startswith( "@PJL") :88 if statement.startswith(self.jlmarker) : 89 89 parts = statement.split() 90 90 nbparts = len(parts) 91 if parts[0] == "@PJL":92 # this is a valid PJL statement, but we don't91 if parts[0] == self.jlmarker : 92 # this is a valid JL statement, but we don't 93 93 # 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"))) : 95 97 # this is what we are interested in ! 96 98 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 98 100 except : 99 self.logdebug("Invalid PJL SET statement [%s]" % repr(statement))101 self.logdebug("Invalid JL SET statement [%s]" % repr(statement)) 100 102 else : 101 103 # all still looks fine... … … 107 109 variable.append(value) 108 110 else : 109 self.logdebug("Ignored PJL statement [%s]" % repr(statement)) 111 self.logdebug("Ignored JL statement [%s]" % repr(statement)) 112 self.logdebug(parts) 110 113 else : 111 self.logdebug("Invalid PJL statement [%s]" % repr(statement))114 self.logdebug("Invalid JL statement [%s]" % repr(statement)) 112 115 else : 113 self.logdebug("Invalid PJL statement [%s]" % repr(statement))116 self.logdebug("Invalid JL statement [%s]" % repr(statement)) 114 117 self.cleanvars() 115 118 self.parsed = 1 119 120 class EJLParser(PJLParser) : 121 """A parser for EJL (Epson Job Language) documents.""" 122 JL = "EJL" 116 123 117 124 def test() : … … 120 127 sys.argv.append("-") 121 128 for arg in sys.argv[1:] : 129 klass = PJLParser 122 130 if arg == "-" : 123 131 infile = sys.stdin 124 132 mustclose = 0 125 133 else : 134 if arg.endswith(".ejl") : 135 klass = EJLParser 126 136 infile = open(arg, "rb") 127 137 mustclose = 1 128 138 try : 129 parser = PJLParser(infile.read(), debug=1)139 parser = klass(infile.read(), debug=1) 130 140 except PJLParserError, msg : 131 141 sys.stderr.write("ERROR: %s\n" % msg)