Added initial conversion script Signed-off-by: Grzegorz Latosinski <glatosinski@antmicro.com>
diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8a18954 --- /dev/null +++ b/setup.cfg
@@ -0,0 +1,8 @@ +[metadata] +license_files = COPYING + +[bdist_wheel] +universal=1 + +[aliases] +test=pytest
diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..da4df12 --- /dev/null +++ b/setup.py
@@ -0,0 +1,26 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="vtr_xml_utils", + version="0.0.1", + author="SymbiFlow Authors", + author_email="symbiflow@lists.librecores.org", + description="A set of Python utilities for working with Verilog to \ + Routing XML files", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/SymbiFlow/vtr-xml-utils", + packages=setuptools.find_packages(), + install_requires=['lxml'], + setup_requires=["pytest-runner"], + tests_require=["pytest"], + include_package_data=True, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: ISC License", + "Operating System :: OS Independent", + ], +)
diff --git a/vtr_xml_utils/__init__.py b/vtr_xml_utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vtr_xml_utils/__init__.py
diff --git a/vtr_xml_utils/convert.py b/vtr_xml_utils/convert.py new file mode 100644 index 0000000..d751651 --- /dev/null +++ b/vtr_xml_utils/convert.py
@@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import lxml.etree as ET +import pkg_resources +import os +from pathlib import Path + + +def get_filenames_containing(pattern, rootdir): + return list(set([str(f) for f in + Path(os.path.dirname(rootdir)).rglob(pattern)])) + + +def vtr_stylize_xml(xmlfilename: str): + """Applies a set of stylesheet rules to the input model or PB type XML file. + It also includes the XInclude blocks in the final output. + + Parameters + ---------- + xmlfilename : str + The path to the input XML file. + + Returns + ------- + str + A string containing formatted XML file, with added parts from the + XInclude statements in the original XML. + """ + xslresourcesroot = pkg_resources.resource_filename('vtr_xml_utils', + 'resources') + xslresourcesroot += '/' + converters = [ + 'identity.xsl', + 'convert-pb_type-attributes.xsl', + 'convert-port-tag.xsl', + 'convert-prefix-port.xsl', + 'pack-patterns.xsl', + 'remove-duplicate-models.xsl', + 'attribute-fixes.xsl', + 'sort-tags.xsl'] + parser = ET.XMLParser(remove_comments=True) + etdata = ET.parse(xmlfilename, parser) + etdata.xinclude() + for c in converters: + xslt = ET.parse(xslresourcesroot + c, parser) + transform = ET.XSLT(xslt) + etdata = transform(etdata) + return '<?xml version="1.0"?>\n' \ + + ET.tostring(etdata, pretty_print=True).decode('utf-8')