Commit 74e10586 authored by Tristan Gingold's avatar Tristan Gingold

Merge branch 'tl-xci-rework' into 'master'

Fixes for XCI parsing in Python 3.6

See merge request !23
parents 3b813182 953d32b0
......@@ -40,27 +40,26 @@ class XCIParserBase(DepParser):
def __init__(self, dep_file):
DepParser.__init__(self, dep_file)
def _parse_xml_xci(self, f):
def _parse_xml_xci(self, xml_str):
"""Parse a Xilinx XCI IP description file in XML format"""
# extract namespaces with a regex -- not really ideal, but without pulling in
# an external xml lib I can't think of a better way.
xmlnsre = re.compile(r'''\bxmlns:(\w+)\s*=\s*"(\w+://[^"]*)"''', re.MULTILINE)
xml = f.read()
nsmap = dict(xmlnsre.findall(xml))
value = ET.fromstring(xml).find('spirit:componentInstances/spirit:componentInstance/spirit:instanceName', nsmap)
nsmap = dict(xmlnsre.findall(xml_str))
value = ET.fromstring(xml_str).find('spirit:componentInstances/spirit:componentInstance/spirit:instanceName', nsmap)
if not value is None:
return value.text
def _parse_json_xci(self, f):
def _parse_json_xci(self, json_str):
"""Parse a Xilinx XCI IP description file in JSON format"""
data = json.load(f)
data = json.loads(json_str)
ip_inst = data.get('ip_inst')
if ip_inst is not None:
return ip_inst.get('xci_name')
def _parse_xci(self, dep_file, f):
def _parse_xci(self, dep_file, file):
"""Parse a Xilinx XCI IP description file to determine the provided module(s)
This file can either be in XML or JSON file format depending on the
......@@ -75,8 +74,9 @@ class XCIParserBase(DepParser):
# Hacky file format detection, just check the first character of the
# file which should be "<" for XML and "{" for JSON
c = f.readline().strip()[0]
f.seek(0)
f = file.read()
c = f.splitlines()[0].strip()[0]
if c == "<":
logging.debug("Parsing xci as xml format")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment