Skip to content

Instantly share code, notes, and snippets.

@MatMoore
Created July 5, 2019 13:27
Show Gist options
  • Save MatMoore/6d652d3f0c26cd9781529afeda5d4339 to your computer and use it in GitHub Desktop.
Save MatMoore/6d652d3f0c26cd9781529afeda5d4339 to your computer and use it in GitHub Desktop.
Tool to show the ROOF view structure
from xml.etree.ElementTree import parse, tostring
from glob import glob
child_perspectives = {}
all_viewpoints = []
for filename in glob('pui/webroot/WEB-INF/config/view/*.xml'):
with open(filename) as f:
doc = parse(f)
for viewpoint in doc.getroot().findall('.//{http://roof.ezgov.com/xmlbeans}ViewPoint'):
perspectiverefs = viewpoint.findall('./{http://roof.ezgov.com/xmlbeans}PerspectiveRef')
viewpointid = viewpoint.attrib['id']
all_viewpoints.append(viewpointid)
child_perspectives[viewpointid] = [elem.attrib['perspectiveId'] for elem in perspectiverefs]
for perspective in doc.findall('.//{http://roof.ezgov.com/xmlbeans}Perspective'):
perspectiverefs = perspective.findall('.//{http://roof.ezgov.com/xmlbeans}PerspectiveRef')
perspectiveid = perspective.attrib['id']
if perspectiverefs:
child_perspectives[perspectiveid] = [elem.attrib['perspectiveId'] for elem in perspectiverefs]
def pretty_print(current_nodes, indent=0):
for node in current_nodes:
print(indent * '\t' + node)
children = child_perspectives.get(node)
if children:
pretty_print(children, indent+1)
# Usage:
# $ python ~/roof_debug.py yca04
#
# CCMS_YCA04
# pageHeaderPerspective
# pageTitlePerspective_yca04
# errorMessagesPerspective
# page_yca04
# page_yca04_resultspanel_header
# page_yca04_infopanel
# pageFooterPerspective
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
query = sys.argv[1]
all_viewpoints = [vp for vp in all_viewpoints if query.lower() in vp.lower()]
pretty_print(sorted(all_viewpoints))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment