1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Stdout notifier - mostly for debugging purposes
18 """
19 __author__ = "André Malo"
20 __docformat__ = "epytext en"
21 __all__ = ['getNotifier']
22
23
24 import sys
25 from svnmailer.notifier import _text
26
27
29 """ Returns an initialized notifier or nothing
30
31 @param config: The svnmailer config
32 @type config: C{svnmailer.settings.Settings}
33
34 @param groupset: The groupset to process
35 @type groupset: C{list}
36
37 @return: The list of notifiers (containing 0 or 1 member)
38 @rtype: C{list}
39 """
40 return [StdoutNotifier(config, groupset)]
41
42
44 """ Writes all stuff to sys.stdout
45
46 @cvar _fp: C{None}
47 @ivar _fp: alternate file like object (for testing purposes)
48 @type _fp: file like object
49 """
50 __implements__ = [_text.TextNotifier]
51 _fp = None
52
53
65
66
83
84
86 """ Writes the stdout preamble for the selected groups
87
88 @param groups: The groups that are notified
89 @type groups: C{list}
90 """
91 self.fp.write(
92 ">>> Notification for the following group%s:\n %s\n\n" %
93 (["", "s"][len(groups) > 1],
94 ",\n ".join(["[%s]" % group._name for group in groups]))
95 )
96
97
99 """ Returns the "proper" output encoding
100
101 If the output goes to a terminal, the method tries to get
102 the current locale encoding. UTF-8 is default and fallback
103 if anything fails.
104
105 @param fp: The file object written to
106 @type fp: file like object
107
108 @return: The chosen encoding
109 @rtype: C{str}
110 """
111 import os
112
113 enc = "utf-8"
114 try:
115 isatty = os.isatty(fp.fileno())
116 except AttributeError:
117 isatty = False
118
119 if isatty:
120 import locale
121 enc = locale.getpreferredencoding() or enc
122
123 return enc
124