From 0bab6e867441c4d9d62b436e0aac48b7dc0096a3 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Jan 2009 06:00:31 -0400 Subject: Added a tools/ subdirectory, with various maintainer related files. --- tools/confirm.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tools/confirm.py (limited to 'tools/confirm.py') diff --git a/tools/confirm.py b/tools/confirm.py new file mode 100755 index 00000000..fa650074 --- /dev/null +++ b/tools/confirm.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +# This script confirms what ledger tells you. + +import sys +import os +import re + +def clean(num): + return float(re.sub("(\s+|\$|,)","", num)) + +running_total = 0.0 +index = 1 +last_line = "" +errors = 0 + +report = sys.argv[1] +for line in os.popen("./ledger -f tools/standard.dat -e 2004/4 %s reg %s" % + (report, sys.argv[2])): + match = re.match("\\s*([-$,0-9.]+)\\s+([-$,0-9.]+)", line[55:]) + if not match: + continue + value = clean(match.group(1)) + total = clean(match.group(2)) + + running_total += value + diff = abs(running_total - total) + if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 + if diff > 0.001: + print "! discrepancy of %.2f (%.2f - %.2f) at line %d:" % \ + (running_total - total, running_total, total, index) + print line, + running_total = total + errors += 1 + + index += 1 + last_line = line + +balance_total = 0.0 + +for line in os.popen("./ledger -f tools/standard.dat -e 2004/4 %s bal %s" % + (report, sys.argv[2])): + if line[0] != '-': + balance_total = clean(line[:20]) + +diff = abs(balance_total - running_total) +if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 +if diff > 0.001: + print + print "! discrepancy of %.2f (%.2f - %.2f) between register and balance" % \ + (balance_total - running_total, balance_total, running_total) + print last_line, + errors += 1 + +sys.exit(errors) -- cgit v1.2.3