Updated the Python driver to mostly match the C++ driver again.
This commit is contained in:
parent
74456d89b5
commit
6e5996e3d0
1 changed files with 113 additions and 92 deletions
205
main.py
205
main.py
|
|
@ -37,12 +37,6 @@ journal = Journal ()
|
||||||
|
|
||||||
add_config_option_handlers ()
|
add_config_option_handlers ()
|
||||||
|
|
||||||
output_for_emacs = false
|
|
||||||
def handle_emacs_option (arg):
|
|
||||||
global output_for_emacs
|
|
||||||
output_for_emacs = true
|
|
||||||
add_option_handler ("emacs", "", handle_emacs_option)
|
|
||||||
|
|
||||||
averages = {}
|
averages = {}
|
||||||
compute_monthly_avg = false
|
compute_monthly_avg = false
|
||||||
|
|
||||||
|
|
@ -106,6 +100,10 @@ elif command == "register" or command == "reg" or command == "r":
|
||||||
command = "r"
|
command = "r"
|
||||||
elif command == "print" or command == "p":
|
elif command == "print" or command == "p":
|
||||||
command = "p"
|
command = "p"
|
||||||
|
elif command == "output":
|
||||||
|
command = "w"
|
||||||
|
elif command == "emacs":
|
||||||
|
command = "x"
|
||||||
elif command == "entry":
|
elif command == "entry":
|
||||||
command = "e"
|
command = "e"
|
||||||
elif command == "equity":
|
elif command == "equity":
|
||||||
|
|
@ -125,20 +123,27 @@ else:
|
||||||
# module was built with such support (which requires the xmlparse C
|
# module was built with such support (which requires the xmlparse C
|
||||||
# library).
|
# library).
|
||||||
|
|
||||||
text_parser = TextualParser ()
|
|
||||||
bin_parser = BinaryParser ()
|
bin_parser = BinaryParser ()
|
||||||
qif_parser = QifParser ()
|
|
||||||
gnucash_parser = None
|
gnucash_parser = None
|
||||||
try:
|
xml_parser = None
|
||||||
gnucash_parser = GnucashParser ()
|
try: xml_parser = GnucashParser ()
|
||||||
except:
|
except: pass
|
||||||
pass
|
try: gnucash_parser = GnucashParser ()
|
||||||
|
except: pass
|
||||||
|
try: ofx_parser = OfxParser ()
|
||||||
|
except: pass
|
||||||
|
qif_parser = QifParser ()
|
||||||
|
text_parser = TextualParser ()
|
||||||
|
|
||||||
register_parser (text_parser)
|
|
||||||
register_parser (bin_parser)
|
register_parser (bin_parser)
|
||||||
|
if xml_parser:
|
||||||
|
register_parser (xml_parser)
|
||||||
if gnucash_parser:
|
if gnucash_parser:
|
||||||
register_parser (gnucash_parser)
|
register_parser (gnucash_parser)
|
||||||
|
if ofx_parser:
|
||||||
|
register_parser (ofx_parser)
|
||||||
register_parser (qif_parser)
|
register_parser (qif_parser)
|
||||||
|
register_parser (text_parser)
|
||||||
|
|
||||||
# Parse all entries from the user specified locations (found in
|
# Parse all entries from the user specified locations (found in
|
||||||
# 'config') into the journal object we created. The two parsers given
|
# 'config') into the journal object we created. The two parsers given
|
||||||
|
|
@ -194,6 +199,8 @@ elif command == "P":
|
||||||
format = config.prices_format
|
format = config.prices_format
|
||||||
elif command == "D":
|
elif command == "D":
|
||||||
format = config.pricesdb_format
|
format = config.pricesdb_format
|
||||||
|
elif command == "w":
|
||||||
|
format = config.write_xact_format
|
||||||
else:
|
else:
|
||||||
format = config.print_format
|
format = config.print_format
|
||||||
|
|
||||||
|
|
@ -364,93 +371,108 @@ if command == "b" or command == "E":
|
||||||
handler = SetAccountValue ()
|
handler = SetAccountValue ()
|
||||||
elif command == "p" or command == "e":
|
elif command == "p" or command == "e":
|
||||||
handler = FormatEntries (format)
|
handler = FormatEntries (format)
|
||||||
elif output_for_emacs:
|
elif command == "x":
|
||||||
import emacs
|
import emacs
|
||||||
handler = emacs.EmacsFormatTransactions ()
|
handler = emacs.EmacsFormatTransactions ()
|
||||||
else:
|
else:
|
||||||
handler = FormatTransactions (format)
|
handler = FormatTransactions (format)
|
||||||
|
|
||||||
# Chain transaction filters on top of the base handler. Most of these
|
if command == "w":
|
||||||
# filters customize the output for reporting. None of this is done
|
if config.output_file:
|
||||||
# for balance or equity reports, which don't need it.
|
out = open (config.output_file, "w")
|
||||||
|
else:
|
||||||
|
out = sys.stdout
|
||||||
|
|
||||||
if not (command == "b" or command == "E"):
|
write_textual_journal(journal, args, handler, out);
|
||||||
if config.display_predicate:
|
|
||||||
handler = FilterTransactions (handler, config.display_predicate)
|
|
||||||
|
|
||||||
handler = CalcTransactions (handler)
|
if config.output_file:
|
||||||
|
out.close ()
|
||||||
if config.sort_string:
|
|
||||||
handler = SortTransactions (handler, config.sort_string)
|
|
||||||
|
|
||||||
if config.show_revalued:
|
|
||||||
handler = ChangedValueTransactions (handler, config.show_revalued_only)
|
|
||||||
|
|
||||||
if config.show_collapsed:
|
|
||||||
handler = CollapseTransactions (handler);
|
|
||||||
|
|
||||||
if config.show_subtotal and not (command == "b" or command == "E"):
|
|
||||||
handler = SubtotalTransactions (handler)
|
|
||||||
|
|
||||||
if config.days_of_the_week:
|
|
||||||
handler = DowTransactions (handler)
|
|
||||||
elif config.by_payee:
|
|
||||||
handler = ByPayeeTransactions (handler)
|
|
||||||
|
|
||||||
if config.report_period:
|
|
||||||
handler = IntervalTransactions (handler, config.report_period,
|
|
||||||
config.report_period_sort)
|
|
||||||
handler = SortTransactions (handler, "d")
|
|
||||||
|
|
||||||
if compute_monthly_avg:
|
|
||||||
handler = ComputeMonthlyAvg (handler)
|
|
||||||
|
|
||||||
# The next set of transaction filters are used by all reports.
|
|
||||||
|
|
||||||
if config.show_inverted:
|
|
||||||
handler = InvertTransactions (handler)
|
|
||||||
|
|
||||||
if config.show_related:
|
|
||||||
handler = RelatedTransactions (handler, config.show_all_related)
|
|
||||||
|
|
||||||
if config.predicate:
|
|
||||||
handler = FilterTransactions (handler, config.predicate)
|
|
||||||
|
|
||||||
if config.budget_flags:
|
|
||||||
handler = BudgetTransactions (handler, config.budget_flags)
|
|
||||||
handler.add_period_entries (journal)
|
|
||||||
elif config.forecast_limit:
|
|
||||||
handler = ForecastTransactions (handler, config.forecast_limit)
|
|
||||||
handler.add_period_entries (journal)
|
|
||||||
|
|
||||||
if config.comm_as_payee:
|
|
||||||
handler = SetCommAsPayee (handler)
|
|
||||||
|
|
||||||
# Walk the journal's entries, and pass each entry's transaction to the
|
|
||||||
# handler chain established above. And although a journal's entries
|
|
||||||
# can be walked using Python, it is significantly faster to do this
|
|
||||||
# simple walk in C++, using `walk_entries'.
|
|
||||||
#
|
|
||||||
# if command == "e":
|
|
||||||
# for xact in new_entry:
|
|
||||||
# handler (xact)
|
|
||||||
# else:
|
|
||||||
# for entry in journal:
|
|
||||||
# for xact in entry:
|
|
||||||
# handler (xact)
|
|
||||||
|
|
||||||
if command == "e":
|
|
||||||
walk_transactions (new_entry, handler)
|
|
||||||
elif command == "P" or command == "D":
|
|
||||||
walk_commodities (handler)
|
|
||||||
else:
|
else:
|
||||||
walk_entries (journal, handler)
|
# Chain transaction filters on top of the base handler. Most of these
|
||||||
|
# filters customize the output for reporting. None of this is done
|
||||||
|
# for balance or equity reports, which don't need it.
|
||||||
|
|
||||||
# Flush the handlers, causing them to output whatever data is still
|
if not (command == "b" or command == "E"):
|
||||||
# pending.
|
if config.head_entries or config.tail_entries:
|
||||||
|
handler = TruncateEntries (handler, config.head_entries,
|
||||||
|
config.tail_entries)
|
||||||
|
|
||||||
if command != "P" and command != "D":
|
if config.display_predicate:
|
||||||
handler.flush ()
|
handler = FilterTransactions (handler, config.display_predicate)
|
||||||
|
|
||||||
|
handler = CalcTransactions (handler)
|
||||||
|
|
||||||
|
if config.sort_string:
|
||||||
|
handler = SortTransactions (handler, config.sort_string)
|
||||||
|
|
||||||
|
if config.show_revalued:
|
||||||
|
handler = ChangedValueTransactions (handler, config.show_revalued_only)
|
||||||
|
|
||||||
|
if config.show_collapsed:
|
||||||
|
handler = CollapseTransactions (handler);
|
||||||
|
|
||||||
|
if config.show_subtotal and not (command == "b" or command == "E"):
|
||||||
|
handler = SubtotalTransactions (handler)
|
||||||
|
|
||||||
|
if config.days_of_the_week:
|
||||||
|
handler = DowTransactions (handler)
|
||||||
|
elif config.by_payee:
|
||||||
|
handler = ByPayeeTransactions (handler)
|
||||||
|
|
||||||
|
if config.report_period:
|
||||||
|
handler = IntervalTransactions (handler, config.report_period,
|
||||||
|
config.report_period_sort)
|
||||||
|
handler = SortTransactions (handler, "d")
|
||||||
|
|
||||||
|
if compute_monthly_avg:
|
||||||
|
handler = ComputeMonthlyAvg (handler)
|
||||||
|
|
||||||
|
# The next set of transaction filters are used by all reports.
|
||||||
|
|
||||||
|
if config.show_inverted:
|
||||||
|
handler = InvertTransactions (handler)
|
||||||
|
|
||||||
|
if config.show_related:
|
||||||
|
handler = RelatedTransactions (handler, config.show_all_related)
|
||||||
|
|
||||||
|
if config.predicate:
|
||||||
|
handler = FilterTransactions (handler, config.predicate)
|
||||||
|
|
||||||
|
if config.budget_flags:
|
||||||
|
handler = BudgetTransactions (handler, config.budget_flags)
|
||||||
|
handler.add_period_entries (journal)
|
||||||
|
elif config.forecast_limit:
|
||||||
|
handler = ForecastTransactions (handler, config.forecast_limit)
|
||||||
|
handler.add_period_entries (journal)
|
||||||
|
|
||||||
|
if config.comm_as_payee:
|
||||||
|
handler = SetCommAsPayee (handler)
|
||||||
|
|
||||||
|
# Walk the journal's entries, and pass each entry's transaction to the
|
||||||
|
# handler chain established above. And although a journal's entries
|
||||||
|
# can be walked using Python, it is significantly faster to do this
|
||||||
|
# simple walk in C++, using `walk_entries'.
|
||||||
|
#
|
||||||
|
# if command == "e":
|
||||||
|
# for xact in new_entry:
|
||||||
|
# handler (xact)
|
||||||
|
# else:
|
||||||
|
# for entry in journal:
|
||||||
|
# for xact in entry:
|
||||||
|
# handler (xact)
|
||||||
|
|
||||||
|
if command == "e":
|
||||||
|
walk_transactions (new_entry, handler)
|
||||||
|
elif command == "P" or command == "D":
|
||||||
|
walk_commodities (handler)
|
||||||
|
else:
|
||||||
|
walk_entries (journal, handler)
|
||||||
|
|
||||||
|
# Flush the handlers, causing them to output whatever data is still
|
||||||
|
# pending.
|
||||||
|
|
||||||
|
if command != "P" and command != "D":
|
||||||
|
handler.flush ()
|
||||||
|
|
||||||
# For the balance and equity reports, the account totals now need to
|
# For the balance and equity reports, the account totals now need to
|
||||||
# be displayed. This is different from outputting transactions, in
|
# be displayed. This is different from outputting transactions, in
|
||||||
|
|
@ -473,8 +495,7 @@ elif command == "E":
|
||||||
# If it were important to clean things up, we would have to clear out
|
# If it were important to clean things up, we would have to clear out
|
||||||
# the accumulated xdata at this point:
|
# the accumulated xdata at this point:
|
||||||
|
|
||||||
#clear_transactions_xdata ()
|
#clear_all_xdata ()
|
||||||
#clear_accounts_xdata ()
|
|
||||||
|
|
||||||
# If the cache is being used, and is dirty, update it now.
|
# If the cache is being used, and is dirty, update it now.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue