You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gendoxylayout.py 2.3 KiB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # This python program generates parameters for the linker script generator feature.
  3. # This file is part of the libopencm3 project.
  4. #
  5. # 2019 Guillaume Revaillot <g.revaillot@gmail.com>
  6. #
  7. # This library is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. from xml.etree import ElementTree
  20. import argparse
  21. parser = argparse.ArgumentParser(prog='gendoxylayout')
  22. parser.add_argument("--template", required=True)
  23. parser.add_argument("--out", required=True)
  24. parser.add_argument("--target")
  25. parser.add_argument("devices", nargs='*')
  26. args = parser.parse_args()
  27. class CommentedTreeBuilder(ElementTree.TreeBuilder):
  28. def __init__(self, *args, **kwargs):
  29. super(CommentedTreeBuilder, self).__init__(*args, **kwargs)
  30. def comment(self, data):
  31. self.start(ElementTree.Comment, {})
  32. self.data(data)
  33. self.end(ElementTree.Comment)
  34. tree = ElementTree.parse(args.template, ElementTree.XMLParser(target=CommentedTreeBuilder()))
  35. parent_map = {c:p for p in tree.iter() for c in p}
  36. for element in tree.iter(tag=ElementTree.Comment):
  37. if ("#devices#" in element.text):
  38. idx = (list(parent_map[element]).index(element))
  39. for device in args.devices:
  40. tab = ElementTree.Element('tab')
  41. tab.set("visible", "yes")
  42. tab.set("title", str(device).upper())
  43. tab.set("intro", "")
  44. if (args.target != None):
  45. if (device == args.target):
  46. tab.set("type", "modules")
  47. else:
  48. tab.set("type", "user")
  49. tab.set("url", "../../" + device + "/html/modules.html")
  50. else:
  51. tab.set("type", "user")
  52. tab.set("url", "../" + device + "/html/modules.html")
  53. parent_map[element].insert(idx, tab)
  54. idx = idx+1;
  55. parent_map[element].remove(element)
  56. tree.write(args.out)