From e6437425dde0a0749cd89ca541acb55899caba9b Mon Sep 17 00:00:00 2001 From: imcovangent <I.vanGent@tudelft.nl> Date: Tue, 8 May 2018 17:00:10 +0200 Subject: [PATCH] Added XML file checks to the merger for use in KE-chain. Former-commit-id: d2831b9be098a66a3f8ece168fdb0a18248d0097 --- kadmos/external/XML_merger/XMLmerger.py | 7 ++++++- kadmos/graph/graph_kadmos.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kadmos/external/XML_merger/XMLmerger.py b/kadmos/external/XML_merger/XMLmerger.py index 688f78fdb..5a5daaa6c 100644 --- a/kadmos/external/XML_merger/XMLmerger.py +++ b/kadmos/external/XML_merger/XMLmerger.py @@ -4,6 +4,8 @@ from xml.etree import ElementTree as et import os +from kadmos.graph.graph_kadmos import _parse_check, _check_roots + class hashabledict(dict): def __hash__(self): @@ -53,7 +55,7 @@ class XMLCombiner(object): one.append(el) -def merge_xmls(filenames, output_file_name, destination_folder=None): +def merge_xmls(filenames, output_file_name, destination_folder=None, perform_checks=False): assert isinstance(filenames, list), 'First argument must be a list of filenames.' assert len(filenames) > 0, 'List of files to be merged must contain at least one element.' if destination_folder is not None: @@ -64,6 +66,9 @@ def merge_xmls(filenames, output_file_name, destination_folder=None): for file in filenames: assert file.endswith('.xml'), 'Files should be XML files with extension xml.' + if perform_checks: + _parse_check([[filename] for filename in filenames]) # TODO: Why a nested list? + _check_roots([[filename] for filename in filenames]) # TODO: Why a nested list? roots = [et.parse(f).getroot() for f in filenames] r = XMLCombiner(roots).combine() print '-' * 20 diff --git a/kadmos/graph/graph_kadmos.py b/kadmos/graph/graph_kadmos.py index 0ec9326ac..c55cbe5ee 100644 --- a/kadmos/graph/graph_kadmos.py +++ b/kadmos/graph/graph_kadmos.py @@ -5530,6 +5530,7 @@ def _check_leafs(io_list, leafs, keep_running=False): def _parse_check(io_list): logger.info('Checking for parsing errors...') for entry in io_list: + # TODO: Check what is happening here and why... file_path=entry[0] if os.path.isfile(file_path): tree = _try_parsing(file_path) @@ -5543,6 +5544,6 @@ def _try_parsing(file_path, keep_running=False): logger.debug('Could not parse XML file {}. Check file structure.'.format(os.path.split(file_path)[1])) logger.debug('To avoid parser errors, use an XML editor to build and adjust files.') logger.warning('ERROR: {}'.format(e)) - raise IOError('Could not parse XML file {}. Check file structure.'.format(os.path.split(file_path)[1])) + raise IOError('Could not parse XML file {}. Check file structure. Parsing error: {}'.format(os.path.split(file_path)[1], e)) return tree -- GitLab