Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/items.py
blob: 6815b33a16e9a493fa5d5118198b804a4bc5b1ad (plain)
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
# Richard Darst, June 2009

import os
import time

import writers
#from writers import html, rst
import itertools

def inbase(i, chars='abcdefghijklmnopqrstuvwxyz', place=0):
    """Converts an integer into a postfix in base 26 using ascii chars.

    This is used to make a unique postfix for ReStructured Text URL
    references, which must be unique.  (Yes, this is over-engineering,
    but keeps it short and nicely arranged, and I want practice
    writing recursive functions.)
    """
    div, mod = divmod(i, len(chars)**(place+1))
    if div == 0:
        return chars[mod]
    else:
        return inbase2(div, chars=chars, place=place+1)+chars[mod]



#
# These are objects which we can add to the meeting minutes.  Mainly
# they exist to aid in HTML-formatting.
#
class _BaseItem(object):
    itemtype = None
    def get_replacements(self):
        replacements = { }
        for name in dir(self):
            if name[0] == "_": continue
            replacements[name] = getattr(self, name)
        return replacements
    def makeRSTref(self, M):
        rstref = rstref_orig = "%s-%s"%(self.nick, self.time)
        count = 0
        while rstref in M.rst_refs:
            rstref = rstref_orig + inbase(count)
            count += 1
        M.rst_urls.append(".. _%s: %s"%(rstref, self.link+"#"+self.anchor))
        M.rst_refs[rstref] = True
        return rstref
    @property
    def anchor(self):
        return 'l-'+str(self.linenum)

class Topic(_BaseItem):
    itemtype = 'TOPIC'
    def __init__(self, nick, line, linenum, time_):
        self.nick = nick ; self.topic = line ; self.linenum = linenum
        self.time = time.strftime("%H:%M:%S", time_)
    def html(self, M):
        repl = self.get_replacements()
        repl['nick'] = writers.html(self.nick)
        repl['topic'] = writers.html(self.topic)
        repl['link'] = M.config.basename+'.log.html'
        return """<tr><td><a href='%(link)s#%(anchor)s'>%(time)s</a></td>
        <th colspan=3>Topic: %(topic)s</th>
        </tr>"""%repl
    def rst(self, M):
        self.link = M.config.basename+'.log.html'
        self.rstref = self.makeRSTref(M)
        return """**%(topic)s**  (%(rstref)s_)"""%self.get_replacements()

class GenericItem(_BaseItem):
    itemtype = ''
    starthtml = ''
    endhtml = ''
    startrst = ''
    endrst = ''
    def __init__(self, nick, line, linenum, time_):
        self.nick = nick ; self.line = line ; self.linenum = linenum
        self.time = time.strftime("%H:%M:%S", time_)
    def html(self, M):
        repl = self.get_replacements()
        repl['nick'] = writers.html(self.nick)
        repl['line'] = writers.html(self.line)
        repl['link'] = M.config.basename+'.log.html'
        return """<tr><td><a href='%(link)s#%(anchor)s'>%(time)s</a></td>
        <td>%(itemtype)s</td><td>%(nick)s</td><td>%(starthtml)s%(line)s%(endhtml)s</td>
        </tr>"""%repl
    def rst(self, M):
        self.link = M.config.basename+'.log.html'
        self.rstref = self.makeRSTref(M)
        return """*%(itemtype)s*: %(line)s  (%(rstref)s_)"""%self.get_replacements()


class Info(GenericItem):
    itemtype = 'INFO'
class Idea(GenericItem):
    itemtype = 'IDEA'
class Agreed(GenericItem):
    itemtype = 'AGREED'
class Action(GenericItem):
    itemtype = 'ACTION'
class Halp(GenericItem):
    itemtype = 'HALP'
class Accepted(GenericItem):
    itemtype = 'ACCEPTED'
    starthtml = '<font color="green">'
    endhtml = '</font>'
class Rejected(GenericItem):
    itemtype = 'REJECTED'
    starthtml = '<font color="red">'
    endhtml = '</font>'
class Link(_BaseItem):
    itemtype = 'LINK'
    def __init__(self, nick, line, linenum, time_):
        self.nick = nick ; self.linenum = linenum
        self.time = time.strftime("%H:%M:%S", time_)
        self.url, self.line = (line+' ').split(' ', 1)
        # URL-sanitization
        self.url_readable = self.url # readable line version
        self.url = self.url.replace('"', "%22")
        # readable line satitization:
        self.line = writers.html(self.line.strip())
    def html(self, M):
        repl = self.get_replacements()
        repl['nick'] = writers.html(self.nick)
        repl['url'] = writers.html(self.url)
        repl['url_readable'] = writers.html(self.url)
        repl['line'] = writers.html(self.line)
        repl['link'] = M.config.basename+'.log.html'
        self.link = M.config.basename+'.log.html'
        return """<tr><td><a href='%(link)s#%(anchor)s'>%(time)s</a></td>
        <td>%(itemtype)s</td><td>%(nick)s</td><td><a href="%(url)s">%(url_readable)s</a> %(line)s</td>
        </tr>"""%repl
    def rst(self, M):
        self.link = M.config.basename+'.log.html'
        self.rstref = self.makeRSTref(M)
        return """*%(itemtype)s*: %(url)s %(line)s  (%(rstref)s_)"""%self.get_replacements()