added pyaccuwage-genfieldfill
This commit is contained in:
parent
ef9f012bd2
commit
9bbe100929
3 changed files with 59 additions and 83 deletions
51
scripts/pyaccuwage-genfieldfill
Executable file
51
scripts/pyaccuwage-genfieldfill
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python
|
||||
from pyaccuwage import model as pyaccuwagemodel
|
||||
from pyaccuwage.modeldef import ModelDefParser, ClassEntryCommentSequence
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
class ModelDefFFParser(ModelDefParser):
|
||||
def __init__(self, infile, entryclass, wantedclass = None):
|
||||
super(ModelDefFFParser, self).__init__(infile, entryclass)
|
||||
self.wantedclass = wantedclass
|
||||
|
||||
def endclass(self):
|
||||
if self.current_class:
|
||||
if not self.wantedclass or self.wantedclass in self.current_class.classname:
|
||||
self.current_class.process()
|
||||
self.current_class = None
|
||||
|
||||
class ClassEntryFieldFill(ClassEntryCommentSequence):
|
||||
def process(self):
|
||||
print("def s(k,v):\n\tgetattr(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."
|
||||
)
|
||||
|
||||
parser.add_argument("-i", "--input",
|
||||
nargs=1,
|
||||
required=True,
|
||||
metavar="file",
|
||||
type=argparse.FileType('r'),
|
||||
help="Source file to generate")
|
||||
|
||||
parser.add_argument("-c", "--classname",
|
||||
nargs=1,
|
||||
required=False,
|
||||
metavar="string",
|
||||
default="",
|
||||
help="Specific model to generate field fills from")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
parser = ModelDefFFParser(args.input[0], ClassEntryFieldFill, args.classname[0])
|
||||
parser.parse()
|
Loading…
Add table
Add a link
Reference in a new issue