Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs with boolean options and parsing of numbers with decimal dot #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions icsv2ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def decode_escape_sequences(string):
string),


def config_to_dict(config, key, defaults):
d = dict(config.items(key))
for k,v in defaults.items():
if type(v) is bool and type(d[k]) is not bool:
d[k] = config.getboolean(key, k)
return d


def parse_args_and_config_file():
""" Read options from config file and CLI args
1. Reads hard coded DEFAULTS
Expand Down Expand Up @@ -216,7 +224,7 @@ def parse_args_and_config_file():
.format(args.config_file, args.account),
file=sys.stderr)
sys.exit(1)
defaults = dict(config.items(args.account))
defaults = config_to_dict(config, args.account, DEFAULTS)

if defaults['src_account']:
print('Section {0} in config file {1} contains command line only option src_account'
Expand Down Expand Up @@ -639,7 +647,7 @@ def get_field_at_index(fields, index, csv_decimal_comma, ledger_decimal_comma):
if csv_decimal_comma:
decimal_separator = ','
else:
decimal_separator = '.'
decimal_separator = '\\.'

re_non_number = '[^-0-9' + decimal_separator + ']'

Expand Down