mirror of
https://github.com/mewtek/i2ME-Legacy.git
synced 2025-05-16 11:00:24 -05:00
Refactor MachineProductCfg
This commit is contained in:
parent
c713bc71d1
commit
3fa05f5ee2
39
Util/MachineProductCfg.py
Normal file
39
Util/MachineProductCfg.py
Normal file
@ -0,0 +1,39 @@
|
||||
import json
|
||||
import xmltodict
|
||||
|
||||
|
||||
# Open the MachineProductCfg.xml file in the root directory
|
||||
with open("MachineProductCfg.xml") as MPCxml:
|
||||
MPCdict = xmltodict.parse(MPCxml.read())
|
||||
MPCdump = json.dumps(MPCdict)
|
||||
data = json.loads(MPCdump)
|
||||
|
||||
|
||||
def getPrimaryLocations():
|
||||
""" Returns all of the primary locations in the MachineProductCfg """
|
||||
locationIds = []
|
||||
# iterate on the json data and grab anything that has PrimaryLocation.
|
||||
# Also needs to return anything in the Regional area.
|
||||
for i in data['Config']['ConfigDef']['ConfigItems']['ConfigItem']:
|
||||
if "PrimaryLocation" in i['@key'] and i['@value'] != "":
|
||||
# Split the string up
|
||||
locationIds.append(i['@value'].split("_")[2])
|
||||
|
||||
if "NearbyLocation" in i['@key'] and i['@value'] != "":
|
||||
locationIds.append(i['@value'].split("_")[2])
|
||||
|
||||
return locationIds
|
||||
|
||||
|
||||
def getAirportCodes():
|
||||
""" Returns all of the airport identifiers present in the MachineProductCfg """
|
||||
airports = []
|
||||
for i in data['Config']['ConfigDef']['ConfigItems']['ConfigItem']:
|
||||
if "Airport" in i['@key'] and i['@value'] != "":
|
||||
# Split the string up
|
||||
airports.append(i['@value'].split("_")[2])
|
||||
|
||||
return airports
|
||||
|
||||
|
||||
print(getPrimaryLocations())
|
@ -1 +0,0 @@
|
||||
|
Loading…
x
Reference in New Issue
Block a user