source: rtems-docs/common/rtemsdomain.py @ 17aca24

5
Last change on this file since 17aca24 was 17aca24, checked in by Sebastian Huber <sebastian.huber@…>, on 07/07/20 at 05:29:45

common: Remove probably superfluous import

The purpose of this import is unclear.

This import caused the following error with Sphinx 3.0:

Extension error:
Could not import extension rtemsdomain (exception: cannot import name 'l_')

  • Property mode set to 100644
File size: 3.5 KB
Line 
1from docutils import nodes
2from docutils.parsers.rst import directives
3
4from sphinx import addnodes
5from sphinx.roles import XRefRole
6from sphinx.directives import ObjectDescription
7from sphinx.domains import Domain, ObjType, Index
8from sphinx.util.nodes import make_refnode
9from sphinx.util.docfields import Field, TypedField
10
11"""
12:r:bsp:`sparc/sis`
13
14:r:arch:`sparc`
15
16:r:board:`...`
17
18:r:user:`amar`
19
20:r:list:`devel`
21"""
22
23role_name = {
24        "bsp":          "BSP",
25        "arch":         "Architecture",
26        "board":        "Board",
27        "user":         "User",
28        "list":         "Mailing List",
29        "rtems":        "`RTEMS`",
30}
31
32role_url = {
33        "trac":                         ("Trac",                                "https://devel.rtems.org"),
34        "devel":                        ("Developer Site",              "https://devel.rtems.org"),
35        "www":                          ("RTEMS Home",                  "https://www.rtems.org/"),
36        "buildbot":                     ("Buildbot Instance",   "https://buildbot.rtems.org/"),
37        "builder":                      ("Builder Site",                "https://builder.rtems.org/"),
38        "docs":                         ("Documentation Site",  "https://docs.rtems.org/"),
39        "lists":                        ("Mailing Lists",               "https://lists.rtems.org/"),
40        "git":                          ("Git Repositories",    "https://git.rtems.org/"),
41        "ftp":                          ("FTP File Server",     "https://ftp.rtems.org/"),
42        "review":                       ("Gerrit Code Review",  "https://review.rtems.org/"),
43        "bugs":                         ("Bugs Database",               "https://devel.rtems.org/wiki/Bugs/"),
44        "gsoc":                         ("Google Summer of Code", "https://devel.rtems.org/wiki/GSoC/"),
45        "socis":                        ("ESA SOCIS",                   "https://devel.rtems.org/wiki/SOCIS/")
46}
47
48
49role_list = {
50        "announce":     ("Announce Mailing List",                       "https://lists.rtems.org/mailman/listinfo/announce/"),
51        "bugs":         ("Bugs Mailing List",                           "https://lists.rtems.org/mailman/listinfo/bugs/"),
52        "devel":        ("Developers Mailing List",                     "https://lists.rtems.org/mailman/listinfo/devel/"),
53        "build":        ("Build Logs",                                  "https://lists.rtems.org/mailman/listinfo/build"),
54        "users":        ("Users Mailing List",                          "https://lists.rtems.org/mailman/listinfo/users/"),
55        "vc":           ("Version Control Mailing List",        "https://lists.rtems.org/mailman/listinfo/vc/"),
56}
57
58
59def rtems_resolve_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
60        role = name.split(":")[1] #XXX: is there a better way?
61
62        try:
63                if role == "list":
64                        text, url = role_list[text]
65                elif role == "url":
66                        text, url = role_url[text]
67        except KeyError:
68                msg = inliner.reporter.error("rtems_resolve_role: '%s' is not a valid %s" % (text, role))
69                err = inliner.problematic("ERROR: %s" % rawtext, None, msg)
70                return [err], [msg]
71
72        # XXX: how do you add an alt tag?
73        node = nodes.reference(rawtext, text, refuri=url, **options)
74        return [node], []
75
76
77
78class RTEMSXrefRole(XRefRole):
79        def __init__(self, item, title, **kwargs):
80                XRefRole.__init__(self, **kwargs)
81                self.item = item
82                self.title = title
83
84        def process_link(self, env, refnode, has_explicit_title, title, target):
85                if has_explicit_title:
86                        title = has_explicit_title
87
88                return has_explicit_title or self.title, target
89
90
91
92
93class RTEMSDomain(Domain):
94        """RTEMS domain."""
95
96        name = "r"
97        label = "RTEMS"
98
99        directives = {}
100        object_types = {}
101
102        roles = {
103                "bsp":          RTEMSXrefRole("bsp", "BSP"),
104                "arch":         RTEMSXrefRole("arch", "Architecture"),
105                "user":         RTEMSXrefRole("user", "User"),
106                "list":         rtems_resolve_role,
107                "url":          rtems_resolve_role,
108        }
109
110
111        def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
112                info = "*info*"
113                anchor = "*anchor*"
114                title = "*title*"
115
116                return make_refnode(builder, fromdocname, info, anchor, contnode, title)
117
118        def merge_domaindata(self, docnames, otherdata):
119                pass # XXX is this needed?
120
121
122
123def setup(app):
124        app.add_domain(RTEMSDomain)
125        return {'version': "1.0", 'parallel_read_safe': True}
Note: See TracBrowser for help on using the repository browser.