Catalogs: Modification of the configuration 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 14:01:19 +01:00
parent b8c05410e3
commit 9ec3e015b2
2 changed files with 16 additions and 6 deletions

View File

@ -6,7 +6,7 @@ from fnmatch import fnmatch, translate
import lxml.etree as ET import lxml.etree as ET
import os import os
from os.path import exists, join, relpath from os.path import exists, join, relpath
from os import walk from os import F_OK, access, walk
import re import re
import sgprops import sgprops
import sys import sys
@ -393,3 +393,16 @@ def fetch_zip_exclude_list(name, path, exclude_path):
# Return the list. # Return the list.
return blacklist return blacklist
def parse_config_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 configuration file '%s' cannot be found." % file_name)
sys.exit(1)
# Parse the XML and return the root node.
config = ET.parse(file_name, parser)
return config.getroot()

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 from catalog import make_aircraft_node, make_aircraft_zip, parse_config_file
CATALOG_VERSION = 4 CATALOG_VERSION = 4
@ -214,10 +214,7 @@ if not os.path.isdir(args.dir):
exit(0) exit(0)
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_file = os.path.join(args.dir, 'catalog.config.xml')
config = ET.parse(config_file, parser)
config_node = config.getroot()
template_file = os.path.join(args.dir, 'template.xml') template_file = os.path.join(args.dir, 'template.xml')
template = ET.parse(template_file, parser) template = ET.parse(template_file, parser)