1. scope
  2. scope.bitbucket.org


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():
    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('#'):
        if cur_value:
            globals()[cur_key] = "".join(cur_value)

if __name__ == "__main__":