Files @ 992c91fc90de
Branch filter:

Location: NPO-Accounting/oxrlib/oxrlib/__main__.py

Brett Smith
config: Nicer implementation of date parsing.

Keeps less local state through the function, to reduce the risk of that
state getting inconsistent.
import decimal
import importlib
import sys

import oxrlib.config

def decimal_context(base=decimal.BasicContext):
    context = base.copy()
    context.rounding = decimal.ROUND_HALF_EVEN
    context.traps[decimal.Inexact] = False
    context.traps[decimal.Rounded] = False
    return context

def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr):
    config = oxrlib.config.Configuration(arglist)
    subcmd_module = importlib.import_module('.commands.' + config.args.command, 'oxrlib')
    with decimal.localcontext(decimal_context()):
        subcmd_module.run(config, stdout, stderr)
    return 0

if __name__ == '__main__':
    exit(main())