From 8534a8aba4b4839a5e7a80a76d622676194ddac6 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Wed, 13 Nov 2019 17:35:11 +0100 Subject: [PATCH] Catalogs: Modification of the template file parsing. The code is now a function in the 'catalog' module and checks for the existence of the file are now performed. --- catalog/catalog.py | 14 ++++++++++++++ catalog/update-catalog.py | 8 ++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/catalog/catalog.py b/catalog/catalog.py index 003bb03..f3ff304 100644 --- a/catalog/catalog.py +++ b/catalog/catalog.py @@ -406,3 +406,17 @@ def parse_config_file(parser=None, file_name=None): # Parse the XML and return the root node. config = ET.parse(file_name, parser) return config.getroot() + + +def parse_template_file(parser=None, file_name=None): + """Test and parse the catalog configuration file.""" + + # Check for the file. + if not access(file_name, F_OK): + print("CatalogError: The catalog template file '%s' cannot be found." % file_name) + sys.exit(1) + + # Parse the XML and return the template node. + template = ET.parse(file_name, parser) + template_root = template.getroot() + return template_root.find('template') diff --git a/catalog/update-catalog.py b/catalog/update-catalog.py index fdce1c0..da7940b 100755 --- a/catalog/update-catalog.py +++ b/catalog/update-catalog.py @@ -13,7 +13,7 @@ import sgprops import sys import catalogTags import catalog -from catalog import make_aircraft_node, make_aircraft_zip, parse_config_file +from catalog import make_aircraft_node, make_aircraft_zip, parse_config_file, parse_template_file CATALOG_VERSION = 4 @@ -215,11 +215,7 @@ if not os.path.isdir(args.dir): parser = ET.XMLParser(remove_blank_text=True) config_node = parse_config_file(parser=parser, file_name=os.path.join(args.dir, 'catalog.config.xml')) - -template_file = os.path.join(args.dir, 'template.xml') -template = ET.parse(template_file, parser) -template_root = template.getroot() -template_node = template_root.find('template') +template_node = parse_template_file(parser=parser, file_name=os.path.join(args.dir, 'template.xml')) md5sum_file = os.path.join(args.dir, 'md5sum.xml') if os.path.exists(md5sum_file):