Mercurial > mamba
comparison mamba/forest.py @ 574:e6344f57886e
Try add colours to the irker messages.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 22 Nov 2012 00:57:15 +0200 |
parents | 1b720cf4d730 |
children | 1306f7d8ed35 |
comparison
equal
deleted
inserted
replaced
573:c01e1e329b47 | 574:e6344f57886e |
---|---|
66 abort(405, "Post levels here. Hsss.") | 66 abort(405, "Post levels here. Hsss.") |
67 | 67 |
68 | 68 |
69 MAMBA_VERSION = "0.1" | 69 MAMBA_VERSION = "0.1" |
70 MAMBA_URL = "https://ctpug.org.za/hg/mamba" | 70 MAMBA_URL = "https://ctpug.org.za/hg/mamba" |
71 IRKER_PORT = 6659 | |
72 CIA_URL = "http://cia.navi.cx" | 71 CIA_URL = "http://cia.navi.cx" |
73 CIA_MSG_TEMPLATE = """ | 72 CIA_MSG_TEMPLATE = """ |
74 <message | 73 <message |
75 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 74 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
76 xsi:noNamespaceSchemaLocation="schema.xsd"> | 75 xsi:noNamespaceSchemaLocation="schema.xsd"> |
121 } | 120 } |
122 srv = xmlrpclib.Server(cia.url) | 121 srv = xmlrpclib.Server(cia.url) |
123 srv.hub.deliver(msg) | 122 srv.hub.deliver(msg) |
124 | 123 |
125 | 124 |
126 def format_irker_message(project, filename, log, branch='uncurated'): | 125 def format_irker_message(msg_template, project, filename, log, |
127 return "%(project)s: %(branch)s * %(filename)s: %(log)s" % { | 126 branch='uncurated', colours=None): |
127 msg_params = { | |
128 "project": project, | 128 "project": project, |
129 "filename": filename, | 129 "filename": filename, |
130 "log": log, | 130 "log": log, |
131 "branch": branch, | 131 "branch": branch, |
132 } | 132 } |
133 if colours: | |
134 msg_params.update(colours) | |
135 return msg_template % msg_params | |
136 | |
137 | |
138 def irker_colours(colour_style): | |
139 if colour_style == "mIRC": | |
140 return { | |
141 'bold': '\x02', | |
142 'green': '\x0303', | |
143 'blue': '\x0302', | |
144 'red': '\x0305', | |
145 'yellow': '\x0307', | |
146 'brown': '\x0305', | |
147 'magenta': '\x0306', | |
148 'cyan': '\x0310', | |
149 'reset': '\x0F', | |
150 } | |
151 else: | |
152 return { | |
153 'bold': '', | |
154 'green': '', | |
155 'blue': '', | |
156 'red': '', | |
157 'yellow': '', | |
158 'brown': '', | |
159 'magenta': '', | |
160 'cyan': '', | |
161 'reset': '', | |
162 } | |
133 | 163 |
134 | 164 |
135 def inform_irker(filename, log, branch='uncurated'): | 165 def inform_irker(filename, log, branch='uncurated'): |
136 if app.config.forest.irker is None: | 166 if app.config.forest.irker is None: |
137 return | 167 return |
138 irker = app.config.forest.irker | 168 irker = app.config.forest.irker |
139 privmsg = format_irker_message(irker.project, filename, log, branch) | 169 colours = irker_colours(irker.colour_style) |
170 privmsg = format_irker_message(irker.msg_template, irker.project, | |
171 filename, log, branch, colours=colours) | |
140 message = json.dumps({"to": irker.channels, "privmsg": privmsg}) | 172 message = json.dumps({"to": irker.channels, "privmsg": privmsg}) |
141 try: | 173 try: |
142 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 174 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
143 sock.connect((irker.host, irker.port)) | 175 sock.connect((irker.host, irker.port)) |
144 sock.sendall(message + "\n") | 176 sock.sendall(message + "\n") |
146 sock.close() | 178 sock.close() |
147 | 179 |
148 | 180 |
149 class ForestConfig(object): | 181 class ForestConfig(object): |
150 | 182 |
183 IRKER_PORT = 6659 | |
184 IRKER_MSG_TEMPLATE = ( | |
185 "%(bold)s%(project)s:%(reset)s " | |
186 "%(magenta)s%(branch)s%(reset)s * " | |
187 "%(bold)s%(filename)s%(reset)s: " | |
188 "%(log)s" | |
189 ) | |
190 | |
151 class SubConfig(object): | 191 class SubConfig(object): |
152 """Holder for sub-config.""" | 192 """Holder for sub-config.""" |
153 | 193 |
154 def __init__(self, filenames): | 194 def __init__(self, filenames): |
155 self._config = SafeConfigParser() | 195 self._config = SafeConfigParser() |
176 if 'project' not in conf: | 216 if 'project' not in conf: |
177 return None | 217 return None |
178 irker = self.SubConfig() | 218 irker = self.SubConfig() |
179 irker.project = conf['project'] | 219 irker.project = conf['project'] |
180 irker.host = conf.get('host', 'localhost') | 220 irker.host = conf.get('host', 'localhost') |
181 irker.port = int(conf.get('port', IRKER_PORT)) | 221 irker.port = int(conf.get('port', self.IRKER_PORT)) |
182 irker.channels = conf['channels'] | 222 irker.channels = conf['channels'] |
223 irker.msg_template = conf.get('msg_template', self.IRKER_MSG_TEMPLATE) | |
224 irker.colour_style = conf.get('colour_style', 'mIRC') | |
183 return irker | 225 return irker |
184 | 226 |
185 def _parse_cia(self, conf): | 227 def _parse_cia(self, conf): |
186 if 'project' not in conf: | 228 if 'project' not in conf: |
187 return None | 229 return None |