~citrix-openstack/nova/xenapi

« back to all changes in this revision

Viewing changes to doc/ext/nova_todo.py

  • Committer: Tarmac
  • Author(s): Todd Willey, root, Vishvananda Ishaya, Joe Heck, root, Andy Smith, Anne Gentle, Dean Troyer, Devin Carlen
  • Date: 2010-11-16 02:34:47 UTC
  • mfrom: (386.2.71 trunkdoc)
  • Revision ID: hudson@openstack.org-20101116023447-pz7n6ps5rf0fnjea
Lots of documentation and docstring updates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# This is a hack of the builtin todo extension, to make the todo_list more user friendly
 
3
 
 
4
from sphinx.ext.todo import *
 
5
from docutils.parsers.rst import directives
 
6
import re
 
7
 
 
8
def _(s):
 
9
    return s
 
10
 
 
11
 
 
12
def process_todo_nodes(app, doctree, fromdocname):
 
13
    if not app.config['todo_include_todos']:
 
14
        for node in doctree.traverse(todo_node):
 
15
            node.parent.remove(node)
 
16
 
 
17
    # Replace all todolist nodes with a list of the collected todos.
 
18
    # Augment each todo with a backlink to the original location.
 
19
    env = app.builder.env
 
20
 
 
21
    if not hasattr(env, 'todo_all_todos'):
 
22
        env.todo_all_todos = []
 
23
 
 
24
 
 
25
    # remove the item that was added in the constructor, since I'm tired of 
 
26
    # reading through docutils for the proper way to construct an empty list
 
27
    lists = []
 
28
    for i in xrange(5):
 
29
        lists.append(nodes.bullet_list("", nodes.Text('','')));
 
30
        lists[i].remove(lists[i][0]) 
 
31
        lists[i].set_class('todo_list')
 
32
 
 
33
    for node in doctree.traverse(todolist):
 
34
        if not app.config['todo_include_todos']:
 
35
            node.replace_self([])
 
36
            continue
 
37
 
 
38
        for todo_info in env.todo_all_todos:
 
39
            para = nodes.paragraph()
 
40
            filename = env.doc2path(todo_info['docname'], base=None)
 
41
 
 
42
            # Create a reference
 
43
            newnode = nodes.reference('', '')
 
44
 
 
45
            link = _('%s, line %d') % (filename, todo_info['lineno']);
 
46
            innernode = nodes.emphasis(link, link)
 
47
            newnode['refdocname'] = todo_info['docname']
 
48
 
 
49
            try:
 
50
                newnode['refuri'] = app.builder.get_relative_uri(
 
51
                    fromdocname, todo_info['docname'])
 
52
                newnode['refuri'] += '#' + todo_info['target']['refid']
 
53
            except NoUri:
 
54
                # ignore if no URI can be determined, e.g. for LaTeX output
 
55
                pass
 
56
 
 
57
            newnode.append(innernode)
 
58
            para += newnode
 
59
            para.set_class('todo_link')
 
60
 
 
61
            todo_entry = todo_info['todo']
 
62
                
 
63
            env.resolve_references(todo_entry, todo_info['docname'], app.builder)
 
64
 
 
65
            item = nodes.list_item('', para)
 
66
            todo_entry[1].set_class('details')
 
67
 
 
68
            comment = todo_entry[1]
 
69
        
 
70
            m = re.match(r"^P(\d)", comment.astext())
 
71
            priority = 5
 
72
            if m:
 
73
                priority = int(m.group(1))
 
74
                if (priority < 0): priority = 1
 
75
                if (priority > 5): priority = 5
 
76
 
 
77
            item.set_class('todo_p' + str(priority))
 
78
            todo_entry.set_class('todo_p' + str(priority))
 
79
 
 
80
            item.append(comment)
 
81
 
 
82
            lists[priority-1].insert(0, item)
 
83
 
 
84
 
 
85
        node.replace_self(lists)
 
86
 
 
87
def setup(app):
 
88
    app.add_config_value('todo_include_todos', False, False)
 
89
 
 
90
    app.add_node(todolist)
 
91
    app.add_node(todo_node,
 
92
                 html=(visit_todo_node, depart_todo_node),
 
93
                 latex=(visit_todo_node, depart_todo_node),
 
94
                 text=(visit_todo_node, depart_todo_node))
 
95
 
 
96
    app.add_directive('todo', Todo)
 
97
    app.add_directive('todolist', TodoList)
 
98
    app.connect('doctree-read', process_todos)
 
99
    app.connect('doctree-resolved', process_todo_nodes)
 
100
    app.connect('env-purge-doc', purge_todos)
 
101