File: ticket.py

package info (click to toggle)
condor 23.9.6%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 60,012 kB
  • sloc: cpp: 528,272; perl: 87,066; python: 42,650; ansic: 29,558; sh: 11,271; javascript: 3,479; ada: 2,319; java: 619; makefile: 615; xml: 613; awk: 268; yacc: 78; fortran: 54; csh: 24
file content (58 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download
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
import os
import sys

from docutils import nodes
from docutils.parsers.rst import Directive

"""
Example of a Sphinx Directive.
This is useful for for working with large blocks of text. Leaving here as a reference.
Roles are more useful for inline text, which is what we need for tickets.

class Ticket(Directive):
    required_arguments = 1
    def run(self):
        ticket_url = "<a href=\"https://htcondor-wiki.cs.wisc.edu/index.cgi/tktview?tn=" + str(self.arguments[0]) + "\" target=\"blank\">link text</a>"
        paragraph_node = nodes.paragraph(text=ticket_url)
        return [paragraph_node]

def setup(app):
    app.add_directive("ticket", Ticket)

"""

# Custom role reference: https://doughellmann.com/blog/2010/05/09/defining-custom-roles-in-sphinx/

def make_link_node(rawtext, app, type, slug, options):
    """Create a link to an HTCondor ticket.

    :param rawtext: Text being replaced with link node.
    :param app: Sphinx application context
    :param type: Link type (issue, changeset, etc.)
    :param slug: ID of the ticket to link to
    :param options: Options dictionary passed to role func.
    """
    base = "https://htcondor-wiki.cs.wisc.edu/index.cgi/tktview?tn="
    ref = base + slug
    # set_classes(options)
    node = nodes.reference(rawtext, "(Ticket #" + slug + ")", refuri=ref, **options)
    return node

def ticket_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    try:
        ticket_id = int(text)
        if ticket_id <= 1000:
            raise ValueError
    except ValueError:
        msg = inliner.reporter.error(
            'HTCondor ticket number must be a number greater than or equal to 1000; '
            '"%s" is invalid.' % text, line=lineno)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]
    app = inliner.document.settings.env.app
    node = make_link_node(rawtext, app, 'issue', str(ticket_id), options)
    return [node], []

def setup(app):
    app.add_role("ticket", ticket_role)