Ejemplo n.º 1
0
def get_topics():
    topics = []
    for line in nullstrip(open("outline.txt")):
        line = line.rstrip().rstrip(" *")
        sline = line.lstrip()
        topics.append((sline, len(line) - len(sline)))
    return topics
Ejemplo n.º 2
0
root = Directory(".") # may be redundant for now.
# Load configuration data from outline (currently just a list of topics)
root_snippet = Snippet(title="O'Reilly Media: Intermediate Python",
                       slug="SOMETHING MEANINGFUL AT A SYSTEM LEVEL",
                       indent_level=0, section=None, snippets=[])
# An exaggerated description of this approach: build every possible
# structure and see what turns out to be useful.
slug_snippets = {}
indent_stack = [0]
snippet_stack = [root_snippet]
last_snippet  = root_snippet
slug_list = []
snippet_list = []
top_level_snippets = []
for line in nullstrip(open("outline.txt", "r")):
    assert len(snippet_stack), "Nothing on the stack!"
    name_of_article = line.strip().rstrip(" *")
    indent = (len(line)-len(line.lstrip()))
    if indent > indent_stack[-1]: # Lower level than previous
        indent_stack.append(indent)
        snippet_stack.append(last_snippet)
    else:
        while indent < indent_stack[-1]:
            indent_stack.pop()
            snippet_stack.pop()
            if indent > indent_stack[-1]:
                sys.exit("Mismatched indentation on", name_of_article)
    slug = slugify(name_of_article)
    snippet = Snippet(title=name_of_article, slug=slug, indent_level=len(indent_stack),
                      section=False, snippets=[])