fixed rangetoken issue with single byte values
This commit is contained in:
parent
e8145c5616
commit
b3aed20388
2 changed files with 13 additions and 23 deletions
|
@ -97,7 +97,7 @@ class RangeToken(BaseToken):
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
if '-' not in self._value:
|
if '-' not in self._value:
|
||||||
return int(self._value)
|
return 1
|
||||||
return reduce(lambda x,y: y-x, map(int, self._value.split('-')))+1
|
return reduce(lambda x,y: y-x, map(int, self._value.split('-')))+1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
from pyaccuwage.parser import RecordBuilder
|
from pyaccuwage.parser import RecordBuilder
|
||||||
from pyaccuwage.pdfexport import PDFRecordFinder
|
from pyaccuwage.pdfextract import PDFRecordFinder
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.")
|
parser = argparse.ArgumentParser(description="Parse and convert contents of IRS files into pyaccuwage e-file classes.")
|
||||||
|
parser.add_argument("-i", "--input", nargs=1, required=True, metavar="file", type=argparse.FileType('r'), help="Source PDF file, ie: p1220.pdf")
|
||||||
parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true")
|
parser.add_argument("-f", "--full", help="Generate full python file, including related imports.", action="store_true")
|
||||||
parser.add_argument("-i", "--input", metavar="file", type=argparse.FileType('r'), help="Source PDF file, ie: p1220.pdf")
|
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
"""
|
|
||||||
lines = []
|
|
||||||
for x in sys.stdin.readlines():
|
|
||||||
lines.append(x)
|
|
||||||
|
|
||||||
pdp = PastedDefParser()
|
|
||||||
tokens = pdp.load("".join(lines))
|
|
||||||
"""
|
|
||||||
def generate_imports():
|
def generate_imports():
|
||||||
return "\n".join([
|
return "\n".join([
|
||||||
"from pyaccuwage import model",
|
"from pyaccuwage import model",
|
||||||
|
@ -33,15 +25,13 @@ def generate_class_begin(name):
|
||||||
if args.full:
|
if args.full:
|
||||||
sys.stdout.write(generate_imports())
|
sys.stdout.write(generate_imports())
|
||||||
|
|
||||||
if args.classname:
|
source_file = os.path.abspath(args.input[0].name)
|
||||||
classname = args.classname
|
|
||||||
else:
|
|
||||||
classname = "GeneratedRecord"
|
|
||||||
|
|
||||||
sys.stdout.write(generate_class_begin(classname))
|
|
||||||
|
|
||||||
|
|
||||||
for x in tokens:
|
|
||||||
sys.stdout.write('\t' + x + '\n')
|
|
||||||
|
|
||||||
|
|
||||||
|
doc = PDFRecordFinder(source_file)
|
||||||
|
records = doc.records()
|
||||||
|
builder = RecordBuilder()
|
||||||
|
for rec in records:
|
||||||
|
print 'name', rec[0]
|
||||||
|
for field in builder.load(map(lambda x:x.tuple, rec[1][1:])):
|
||||||
|
print field
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue