Skip to content

Commit

Permalink
Support non-xml configs too
Browse files Browse the repository at this point in the history
  • Loading branch information
penn5 committed Jun 8, 2019
1 parent f0021a3 commit c77005a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions idtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

from lxml import etree

def get_images(xml: bytes):
tree = etree.fromstring(xml)
def get_images(cfg: bytes):
try:
tree = etree.fromstring(cfg)
except:
return get_simple(cfg.decode("utf-8"))
ddr_images = tree.xpath("(//configurations/configuration)[1]/bootloaderimage_ddr/image")
std_images = tree.xpath("(//configurations/configuration)[1]/bootloaderimage/image")
images = {int(img.get("address"), 0):img.text for img in ddr_images}
Expand All @@ -21,3 +24,14 @@ def get_images(xml: bytes):
images[int(img.get("address"), 0)] = img.text
print(images)
return images

def get_simple(cfg):
ret = {}
for line in cfg.readlines:
match = re.fullmatch(r"(\w+)(?:\W+)(.+)")
if not match:
return None
addr = int(match[1], 0)
file = match[2]
ret[addr] = file
return ret

0 comments on commit c77005a

Please sign in to comment.