From 04b3c3f273baa93303ab8657a4d3ae44f246fc38 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 2 Jun 2012 15:16:13 -0500 Subject: [PATCH] Added pyaccuwage-parse script. We encountered a problem with the parser where a description contained a range value and the parse thought it was the beginning of a new field definition. We should be able to exclude the incorrect range values by looking at our last good range, and if the range does not continue the previous range, then it is probably incorrect and can be discarded. These changes can probably be performed in the tokenize section of the parser. --- scripts/pyaccuwage-parse | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/scripts/pyaccuwage-parse b/scripts/pyaccuwage-parse index 75bbf52..4e269c3 100755 --- a/scripts/pyaccuwage-parse +++ b/scripts/pyaccuwage-parse @@ -1,4 +1,44 @@ #!/usr/bin/python +from pyaccuwage.parser import PastedDefParser +import argparse +import sys + +parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.") +parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true") +parser.add_argument("-c", "--classname", help="Name to use for generated class.", type=str) + +args = parser.parse_args() + +lines = [] +for x in sys.stdin.readlines(): + lines.append(x) + +pdp = PastedDefParser() +tokens = pdp.load("".join(lines)) + +def generate_imports(): + return "\n".join([ + "from pyaccuwage import model", + "from pyaccuwage.fields import *", + "", + "", + ]) + +def generate_class_begin(name): + return "class %s(mode.Model):\n" % name + +if args.full: + sys.stdout.write(generate_imports()) + +if args.classname: + classname = args.classname +else: + classname = "GeneratedRecord" + +sys.stdout.write(generate_class_begin(classname)) + + +for x in tokens: + sys.stdout.write('\t' + x + '\n') -print "PYTHON!"