From 1ae86e28984462a92e327819bd7c9b0812f1a087 Mon Sep 17 00:00:00 2001 From: needlen0se <116135691+needlen0se@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:18:22 -0700 Subject: [PATCH] Error if XML is missing --- Util/MachineProductCfg.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Util/MachineProductCfg.py b/Util/MachineProductCfg.py index 77722c7..221e8fe 100644 --- a/Util/MachineProductCfg.py +++ b/Util/MachineProductCfg.py @@ -1,13 +1,18 @@ import json +import sys import xmltodict # Open the MachineProductCfg.xml file in the root directory -with open("MachineProductCfg.xml", mode = 'r', encoding= 'utf-8') as MPCxml: - MPCdict = xmltodict.parse(MPCxml.read()) - MPCdump = json.dumps(MPCdict) - data = json.loads(MPCdump) - +try: + with open("MachineProductCfg.xml", mode = 'r', encoding= 'utf-8') as MPCxml: + MPCdict = xmltodict.parse(MPCxml.read()) + MPCdump = json.dumps(MPCdict) + data = json.loads(MPCdump) +except Exception as e: + print(e) + sys.exit("There was an error opening your MachineProductCfg.xml. Is the file in the root folder?") + def getPrimaryLocations(): """ Returns all of the primary locations in the MachineProductCfg """