{{{id=0| import os, subprocess from sagenb.misc.misc import DATA, SAGENB_VERSION /// }}} {{{id=1| html_template_dir = os.path.join(DATA, 'sage', 'html') pre = '{% ' extends = pre + 'extends' include = pre + 'include' post = ' %}' def shorten(x): x = x.replace('accounts/', 'A/') x = x.replace('notebook/', 'N/') x = x.replace('settings/', 'S/') x = x.replace('worksheets/', 'W/') x = x.replace('.html', '') x = x.replace('.tmpl', '.t') return x /// }}} {{{id=2| deps = {} for root, dirs, files in os.walk(html_template_dir): for filename in files: path = os.path.join(root, filename) fd = open(path, 'r') lines = fd.readlines() fd.close() for li in lines: for hier in [extends, include]: if hier in li: i = li.find(hier) j = li.find(post) if i == -1 or j == -1: continue base = os.path.basename(root) base = '' if base == 'html' else base + '/' upper = shorten(base + filename) lower = shorten(li[i + len(hier) + 7:j - len(post) + 2]) try: deps[upper].append(lower) except KeyError: deps[upper] = [lower] /// }}} {{{id=3| ext_col = '#abcdef' inc_col = '#fedcba' vcols = {ext_col: [], inc_col: []} for d in deps: if d.endswith('.t'): vcols[inc_col].append(d) else: vcols[ext_col].append(d) vcols[ext_col].append('base') vcols[inc_col].append('N/render_cell.t') /// }}} {{{id=4| g = DiGraph(deps).reverse() g.add_vertex('base') g.add_vertex('N/render_worksheet.t') print g.is_directed_acyclic() p = Poset(g) p.plot(vertex_size=1500, vertex_colors=vcols).show(aspect_ratio=1.0, figsize=20) /// }}} {{{id=5| loc = '' format = 'png' gv_base = os.path.join(loc, 'jinja_deps-' + SAGENB_VERSION) gv_dot = gv_base + '.dot' g.graphviz_to_file_named(gv_dot) cmd = 'dot ' + gv_dot + ' -T' + format + ' -o ' + gv_base + '.' + format + ' ' opts = '-Gratio=auto -Gsize=50,10' ret = subprocess.call(cmd + opts, shell=True) /// }}} {{{id=6| /// }}}