Source

scope.bitbucket.org / makeindex.py

import os

TEMPLATES = os.path.join("resources", "TEMPLATES")
UI_WIDGET_DIR = "ui-elements"
SCOPE_DIR = "scope"
TEST_DIR = "tests"
INDEX = "index.html"

def write_index():
    load_templates()
    with open(INDEX, 'wb') as f:
        f.write(HTML_INDEX % {"stylesheet": "style.css",
                              "scope-links": get_scope_links(),
                              "ui-widget-links": get_indexes(UI_WIDGET_DIR),
                              "test-links": get_indexes(TEST_DIR)})

def get_indexes(directory):
    links = []
    links_sorted = []
    for dir in os.listdir(directory):
        if os.path.isdir(os.path.join(directory, dir)):
            index = get_index(os.path.join(directory, dir))
            if index:
                links.append((directory, dir, index))
    for directory, dir, index in sorted(links, key=lambda parts: parts[1]):
        href = "./%s/%s/%s" % (directory, dir, index)
        links_sorted.append(HTML_LIST_LINK % {"text": dir, "href": href})
    return ''.join(links_sorted)

def get_scope_links():
    links = [
        HTML_LIST_LINK % ({"text": "Scope Architecure", "href": "http://operasoftware.github.com/scope-architecure/"}),
        HTML_LIST_LINK % ({"text": "Scope Interface", "href": "http://operasoftware.github.com/scope-interface/"})
    ]
    return ''.join(links)

def get_index(dir_path):
    for file in os.listdir(dir_path):
        if os.path.isfile(os.path.join(dir_path, file)) and file.startswith('index.'):
            return file
    return None

def load_templates():
    with open(TEMPLATES, 'rb') as f:
        cur_key = ""
        cur_value = []
        for line in f.readlines():
            if line.startswith('HTML_'):
                if cur_value:
                    globals()[cur_key] = "".join(cur_value)
                    cur_value = []
                cur_key = line.strip()
            elif not line.startswith('#'):
                cur_value.append(line)
        if cur_value:
            globals()[cur_key] = "".join(cur_value)

if __name__ == "__main__":
    write_index()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.