File: add-slidge-dev-helpers.patch

package info (click to toggle)
slidge-matridge 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772 kB
  • sloc: python: 1,932; xml: 127; makefile: 16
file content (233 lines) | stat: -rw-r--r-- 6,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Description: add various tools to help slidge-based XMPP gateway development
 Source: https://codeberg.org/slidge/sphinx-extensions
Author: Nicolas Cedilnik <nicoco@nicoco.fr>, Martin <debacle@debian.org>
Origin: vendor
Bug-Debian: https://bugs.debian.org/1057869
Last-Update: 2025-01-22
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- /dev/null
+++ b/slidge_sphinx_extensions/config_obj.py
@@ -0,0 +1,74 @@
+import importlib
+from typing import get_type_hints
+
+from docutils import nodes
+from sphinx.util.docutils import SphinxDirective
+from sphinx.util.logging import getLogger
+
+
+def valid_option(name: str):
+    return (
+        not name.startswith("_")
+        and not name.endswith("__DOC")
+        and name.upper() == name
+        and not name.endswith("__DYNAMIC_DEFAULT")
+    )
+
+
+class ConfigObj(SphinxDirective):
+    has_content = True
+
+    def run(self):
+        module = importlib.import_module(self.content[0])
+
+        table = nodes.table()
+        tgroup = nodes.tgroup()
+
+        colspec = nodes.colspec()
+
+        tgroup += colspec
+        tgroup += colspec
+        tgroup += colspec
+
+        table += tgroup
+
+        tbody = nodes.tbody()
+
+        params = [name for name in dir(module) if valid_option(name)]
+
+        # options without default values
+        for name, _ in get_type_hints(module).items():
+            if not valid_option(name):
+                continue
+            if name not in params:
+                params.append(name)
+
+        for param in params:
+            row = nodes.row()
+
+            entry = nodes.entry()
+            entry.append(nodes.Text(param))
+            row += entry
+
+            entry = nodes.entry()
+            entry.append(nodes.Text(getattr(module, param + "__DOC")))
+            row += entry
+
+            tbody += row
+
+        tgroup += tbody
+
+        return [table]
+
+
+def setup(app):
+    app.add_directive("config-obj", ConfigObj)
+
+    return {
+        "version": "0.1",
+        "parallel_read_safe": True,
+        "parallel_write_safe": True,
+    }
+
+
+log = getLogger("config_obj")
--- /dev/null
+++ b/slidge_sphinx_extensions/doap.py
@@ -0,0 +1,141 @@
+"""
+Sphinx extension to generate a table from a DOAP file in XML format.
+
+This is a helper to generate "features" pages for the docs of slidge-powered
+gateways.
+"""
+
+import xml.etree.ElementTree as ET
+from pathlib import Path
+
+import requests
+from docutils import nodes
+from sphinx.util.docutils import SphinxDirective
+from sphinx.util.logging import getLogger
+
+
+def parse(el):
+    status = el.find("{https://linkmauve.fr/ns/xmpp-doap#}status").text
+    url = el.find("{https://linkmauve.fr/ns/xmpp-doap#}xep").get(
+        "{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource"
+    )
+
+    note_elem = el.find("{https://linkmauve.fr/ns/xmpp-doap#}note")
+
+    if note_elem is not None:
+        note = note_elem.text
+    else:
+        note = ""
+
+    if not note:
+        note = DEFAULT_NOTE.get(status, status)
+
+    return url, status, note
+
+
+def get_xep_titles(xep_urls: list[str]):
+    xep_titles = {
+        "https://xmpp.org/extensions/xep-0045.html": "Multi-User Chat",
+        "https://xmpp.org/extensions/xep-0085.html": "Chat State Notifications",
+        "https://xmpp.org/extensions/xep-0184.html": "Message Delivery Receipts",
+        "https://xmpp.org/extensions/xep-0201.html": "Best Practices for Message Threads",
+        "https://xmpp.org/extensions/xep-0245.html": "The /me Command",
+        "https://xmpp.org/extensions/xep-0308.html": "Last Message Correction",
+        "https://xmpp.org/extensions/xep-0319.html": "Last User Interaction in Presence",
+        "https://xmpp.org/extensions/xep-0333.html": "Chat Markers",
+        "https://xmpp.org/extensions/xep-0363.html": "HTTP File Upload",
+        "https://xmpp.org/extensions/xep-0393.html": "Message Styling",
+        "https://xmpp.org/extensions/xep-0424.html": "Message Retraction",
+        "https://xmpp.org/extensions/xep-0444.html": "Message Reactions",
+        "https://xmpp.org/extensions/xep-0461.html": "Message Replies",
+    }
+    titles = []
+    for xep_url in xep_urls:
+        if xep_url in xep_titles:
+            titles.append(xep_titles[xep_url])
+        else:
+            titles.append("Unknown XEP")
+    return titles
+
+
+class Doap(SphinxDirective):
+    has_content = True
+
+    def run(self):
+        xml = ET.parse(Path(self.get_location()).parent / self.content[0])
+
+        table = nodes.table()
+        tgroup = nodes.tgroup()
+
+        colspec = nodes.colspec()
+
+        tgroup += colspec
+        tgroup += colspec
+        tgroup += colspec
+
+        table += tgroup
+
+        tbody = nodes.tbody()
+
+        xep_urls = []
+        statuses = []
+        notes = []
+
+        for el in xml.iter("{https://linkmauve.fr/ns/xmpp-doap#}SupportedXep"):
+            try:
+                url, status, note = parse(el)
+            except Exception as e:
+                log.error("Problem parsing %s", el, exc_info=e)
+                continue
+            xep_urls.append(url)
+            statuses.append(status)
+            notes.append(note)
+
+        xep_titles = get_xep_titles(xep_urls)
+        for url, status, note, title in zip(xep_urls, statuses, notes, xep_titles):
+            row = nodes.row()
+
+            entry = nodes.entry()
+            entry.append(nodes.Text(SUPPORT[status]))
+            row += entry
+
+            entry = nodes.entry()
+            outer = nodes.paragraph("")
+            ref = nodes.reference()
+            ref["refuri"] = url
+            ref.append(nodes.Text(title))
+            outer.append(ref)
+
+            entry.append(outer)
+            row += entry
+
+            entry = nodes.entry()
+            entry.append(nodes.Text(note))
+            row += entry
+
+            tbody += row
+
+        tgroup += tbody
+
+        return [table]
+
+
+def setup(app):
+    app.add_directive("doap", Doap)
+
+    return {
+        "version": "0.1",
+        "parallel_read_safe": True,
+        "parallel_write_safe": True,
+    }
+
+
+SUPPORT = {"complete": "✅", "wontfix": "❌", "planned": "🔮", "partial": "🤏"}
+DEFAULT_NOTE = {
+    "complete": "Supported",
+    "wontfix": "Unsupported",
+    "planned": "Planned",
+    "partial": "Partially supported",
+}
+
+log = getLogger("doap")
--- /dev/null
+++ b/slidge_sphinx_extensions/__init__.py
@@ -0,0 +1 @@
+#