Map

Map of PhD-wiki

Map generation code

node_formatting = 'shape=box,style=filled,fillcolor="#adbbca",fontname="Monospace",fontsize=10,height=0.35'
page_specific_formatting = {"WelcomePage": 'color="0.7 0.2 0.8",style="bold"',
                            "StudyExpenses": 'color="red"'}
ignored_pages = ['^Setup.+.*','^Installing.+.*']

import os, re, sys, os.path

if len(sys.argv) > 1:
    cwd = sys.argv[1]
else:
    cwd = "."

files = os.listdir(cwd)
muse_re = re.compile('(.*)\.muse$')
WikiNames = [f.split('.')[0] for f in files if muse_re.match(f) and f.count('.') == 1]
for ignore_re in ignored_pages:
    try:
        WikiNames = [w for w in WikiNames if not re.compile(ignore_re).match(w)]
    except Exception, e:
        print e

wiki_links = {}
for wiki in WikiNames:
    f = file(os.path.join(cwd, wiki + '.muse'), 'r')
    text = f.readlines()

    for link in set(WikiNames).difference([wiki]):
        link_re = re.compile('(?<!]\[)'      # don't match if preceded by ][ -- it's a link
                             + link +
                             '{1,1}(?!\w)'); # linkname must not be followed by alpha-numerical chars
        for line in text:
            if 'backlinks:' in line:
                continue
            if link_re.search(line):
                if wiki_links.has_key(wiki):
                    wiki_links[wiki].append(link)
                else:
                    wiki_links[wiki] = [link]

print '''digraph wiki {
rankdir=LR;
nodesep=0.175;
node[%s];''' % node_formatting

for name in WikiNames:
    formatstr = ''
    if name in page_specific_formatting.keys():
        formatstr += ',' + page_specific_formatting[name]

    print '"%s" [href="%s"%s];' % (name, name + '.html', formatstr)

for page in wiki_links.keys():
    if page == "Map":
        continue

    for link in set(wiki_links[page]):
        print '"%s" -> "%s";' % (page, link)


print "}"
  (let* (
          (cwd (file-name-directory muse-publishing-current-file))
          (chd (concat "cd " cwd "; "))
          (generate-dot-command (concat chd "python musemap.py > map.dot"))
          (generate-map-command (concat chd "dot -Tcmapx -o map.html map.dot"))
          (generate-png-command (concat "dot -Tpng -o " output-dir "/map.png " cwd "map.dot"))
        )

        (if (/= 0 (shell-command generate-dot-command))
          (message (concat "Map.muse: failure calling " generate-dot-command)))

        (if (/= 0 (shell-command generate-map-command))
          (message (concat "Map.muse: failure calling " generate-map-command)))

        (if (eq 0 (shell-command generate-png-command))
          (progn (muse-publish-include-tag (point) (point) '(("file" . "map.html") ("markup" . "nil")))
                 (delete-file (expand-file-name "map.html" cwd))
                 (delete-file (expand-file-name "map.dot" cwd)))
          (message (concat "Map.muse: failure calling " generate-png-command)))

  )

IanKnot rainbow -->