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.
This commit is contained in:
Edward d'Auvergne 2019-11-13 17:35:11 +01:00
parent 9ec3e015b2
commit 8534a8aba4
2 changed files with 16 additions and 6 deletions

View File

@ -406,3 +406,17 @@ def parse_config_file(parser=None, file_name=None):
# Parse the XML and return the root node. # Parse the XML and return the root node.
config = ET.parse(file_name, parser) config = ET.parse(file_name, parser)
return config.getroot() 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')

View File

@ -13,7 +13,7 @@ import sgprops
import sys import sys
import catalogTags import catalogTags
import catalog 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 CATALOG_VERSION = 4
@ -215,11 +215,7 @@ if not os.path.isdir(args.dir):
parser = ET.XMLParser(remove_blank_text=True) parser = ET.XMLParser(remove_blank_text=True)
config_node = parse_config_file(parser=parser, file_name=os.path.join(args.dir, 'catalog.config.xml')) config_node = parse_config_file(parser=parser, file_name=os.path.join(args.dir, 'catalog.config.xml'))
template_node = parse_template_file(parser=parser, file_name=os.path.join(args.dir, 'template.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')
md5sum_file = os.path.join(args.dir, 'md5sum.xml') md5sum_file = os.path.join(args.dir, 'md5sum.xml')
if os.path.exists(md5sum_file): if os.path.exists(md5sum_file):