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
53
main.py
53
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,17 +371,32 @@ 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)
|
||||||
|
|
||||||
|
if command == "w":
|
||||||
|
if config.output_file:
|
||||||
|
out = open (config.output_file, "w")
|
||||||
|
else:
|
||||||
|
out = sys.stdout
|
||||||
|
|
||||||
|
write_textual_journal(journal, args, handler, out);
|
||||||
|
|
||||||
|
if config.output_file:
|
||||||
|
out.close ()
|
||||||
|
else:
|
||||||
# Chain transaction filters on top of the base handler. Most of these
|
# Chain transaction filters on top of the base handler. Most of these
|
||||||
# filters customize the output for reporting. None of this is done
|
# filters customize the output for reporting. None of this is done
|
||||||
# for balance or equity reports, which don't need it.
|
# for balance or equity reports, which don't need it.
|
||||||
|
|
||||||
if not (command == "b" or command == "E"):
|
if not (command == "b" or command == "E"):
|
||||||
|
if config.head_entries or config.tail_entries:
|
||||||
|
handler = TruncateEntries (handler, config.head_entries,
|
||||||
|
config.tail_entries)
|
||||||
|
|
||||||
if config.display_predicate:
|
if config.display_predicate:
|
||||||
handler = FilterTransactions (handler, config.display_predicate)
|
handler = FilterTransactions (handler, config.display_predicate)
|
||||||
|
|
||||||
|
|
@ -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