main: Don't use importers whose template isn't configured.
This lets users import only some information from sources that provide multiple transaction streams at once.
This commit is contained in:
parent
0b665d388e
commit
fea64ee138
1 changed files with 12 additions and 3 deletions
|
@ -18,7 +18,17 @@ class FileImporter:
|
|||
for importer in self.importers:
|
||||
in_file.seek(0)
|
||||
if importer.can_import(in_file):
|
||||
importers.append(importer)
|
||||
try:
|
||||
template = self.config.get_template(importer.TEMPLATE_KEY)
|
||||
except errors.UserInputConfigurationError as error:
|
||||
if error.strerror.startswith('template not defined '):
|
||||
have_template = False
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
have_template = not template.is_empty()
|
||||
if have_template:
|
||||
importers.append((importer, template))
|
||||
if not importers:
|
||||
raise errors.UserInputFileError("no importers available", in_file.name)
|
||||
with contextlib.ExitStack() as exit_stack:
|
||||
|
@ -27,8 +37,7 @@ class FileImporter:
|
|||
out_file = self.stdout
|
||||
else:
|
||||
out_file = exit_stack.enter_context(output_path.open('a'))
|
||||
for importer in importers:
|
||||
template = self.config.get_template(importer.TEMPLATE_KEY)
|
||||
for importer, template in importers:
|
||||
default_date = self.config.get_default_date()
|
||||
in_file.seek(0)
|
||||
for entry_data in importer(in_file):
|
||||
|
|
Loading…
Reference in a new issue