added missing modeldef.py and fixed genfieldfill
This commit is contained in:
parent
9bbe100929
commit
b9982c3a21
2 changed files with 88 additions and 2 deletions
86
pyaccuwage/modeldef.py
Normal file
86
pyaccuwage/modeldef.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env python
|
||||
import re
|
||||
|
||||
class ClassEntryCommentSequence(object):
|
||||
re_rangecomment = re.compile('#\s+(\d+)\-?(\d*)$')
|
||||
|
||||
def __init__(self, classname, line):
|
||||
self.classname = classname,
|
||||
self.line = line
|
||||
self.lines = []
|
||||
|
||||
def add_line(self, line):
|
||||
self.lines.append(line)
|
||||
|
||||
def process(self):
|
||||
i = 0
|
||||
for (line_no, line) in enumerate(self.lines):
|
||||
match = self.re_rangecomment.search(line)
|
||||
if match:
|
||||
(a, b) = match.groups()
|
||||
a = int(a)
|
||||
|
||||
if (i + 1) != a:
|
||||
line_number = self.line + line_no
|
||||
print("ERROR\tline:%d\tnear:%s\texpected:%d\tsaw:%d" % (line_number, line.split(' ')[0].strip(), i+1, a))
|
||||
|
||||
i = int(b) if b else a
|
||||
|
||||
class ModelDefParser(object):
|
||||
re_triplequote = re.compile('"""')
|
||||
re_whitespace = re.compile("^(\s*)[^\s]+")
|
||||
re_classdef = re.compile(r"^\s*class\s(.*)\((.*)\):\s*$")
|
||||
|
||||
def __init__(self, infile, entryclass):
|
||||
self.infile = infile
|
||||
self.line = 0
|
||||
self.EntryClass = entryclass
|
||||
|
||||
def endclass(self):
|
||||
if self.current_class:
|
||||
self.current_class.process()
|
||||
self.current_class = None
|
||||
|
||||
def beginclass(self, classname, line):
|
||||
self.current_class = self.EntryClass(classname, line)
|
||||
|
||||
def parse(self):
|
||||
infile = self.infile
|
||||
whitespace = 0
|
||||
in_block_comment = False
|
||||
self.current_class = None
|
||||
|
||||
for line in infile:
|
||||
self.line += 1
|
||||
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
|
||||
if self.re_triplequote.search(line):
|
||||
in_block_comment = not in_block_comment
|
||||
|
||||
if in_block_comment:
|
||||
continue
|
||||
|
||||
match_whitespace = self.re_whitespace.match(line)
|
||||
if match_whitespace:
|
||||
match_whitespace = len(match_whitespace.groups()[0])
|
||||
else:
|
||||
match_whitespace = 0
|
||||
|
||||
classmatch = self.re_classdef.match(line)
|
||||
if classmatch:
|
||||
classname, subclass = classmatch.groups()
|
||||
self.beginclass(classname, self.line)
|
||||
continue
|
||||
|
||||
if match_whitespace < whitespace:
|
||||
whitespace = match_whitespace
|
||||
self.endclass()
|
||||
continue
|
||||
|
||||
if self.current_class:
|
||||
whitespace = match_whitespace
|
||||
self.current_class.add_line(line)
|
||||
|
||||
|
|
@ -20,13 +20,13 @@ class ModelDefFFParser(ModelDefParser):
|
|||
|
||||
class ClassEntryFieldFill(ClassEntryCommentSequence):
|
||||
def process(self):
|
||||
print("def s(k,v):\n\tgetattr(record, k).value = v\n")
|
||||
print("# " + ''.join(self.classname))
|
||||
print("def s(k,v):\n getattr(record, k).value = v\n")
|
||||
for line in self.lines:
|
||||
parts = line.strip().split()
|
||||
if parts and not parts[0].startswith('blank'):
|
||||
print( ("s('%s'," % parts[0]).ljust(50) + ')')
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate prototype field filling commands from pyaccuwage model definition."
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue