Add template and colour info
authorNeil <neil@dip.sun.ac.za>
Sun, 11 Nov 2012 10:32:48 +0000 (12:32 +0200)
committerNeil <neil@dip.sun.ac.za>
Sun, 11 Nov 2012 10:32:48 +0000 (12:32 +0200)
irkerhook.py

index 208c0d87911df2831d7f5bb78c4fee527566c430..99a9d3996205bfb9bf7bcdeed76a79870649e34f 100644 (file)
@@ -37,14 +37,21 @@ class IrkerSender(object):
 
     def _format(self):
         fields = {
+            'project': self.project(),
             'committer': self.revision.committer,
-            'message': self.revision.get_summary(),
-            'revision': '%d' % self.revno,
-            'url': self.url()
+            'repo': '',
+            'rev': '%d' % self.revno,
+            'files': '',
+            'logmsg': self.revision.get_summary(),
+            'url': self.url(),
         }
-        text = ''
-        #for name, value in fields.items():
-        #    text = text.replace('$%s' % name, value)
+        for name, value in self.colours():
+            fields[name] = value
+        text = ('%(bold)s%(project)s:%(reset)s '
+                '%(green)s%(committer)s%(reset)s '
+                '%(repo)s * %(bold)s%(rev)s%(reset)s / '
+                ' %(bold)s%(files)s%(reset)s: %(logmsg)s '
+                '%(brown)s%(url)s%(reset)s' % fields)
         return text
 
     def body(self):
@@ -94,6 +101,52 @@ class IrkerSender(object):
             url = self.branch.base
         return url
 
+    def colours(self):
+        colour_style = self.config.get('irker_colors')
+        colours = {
+                'bold': '',
+                'green': '',
+                'blue': '',
+                'red': '',
+                'yellow': '',
+                'brown': '',
+                'magenta': '',
+                'cyan': '',
+                'reset': '',
+                }
+        # Vaues taken from irker's irkerhook.py
+        if colour_style == 'ANSI':
+            colours = {
+                    'bold': '\x1b[1m'
+                    'green': '\x1b[1;32m'
+                    'blue': '\x1b[1;34m'
+                    'red':  '\x1b[1;31m'
+                    'yellow': '\x1b[1;33m'
+                    'brown': '\x1b[33m'
+                    'magenta': '\x1b[35m'
+                    'cyan': '\x1b[36m'
+                    'reset': '\x1b[0m'
+                    }
+        elif colour_style == 'mIRC':
+            colours = {
+                    'bold': '\x02'
+                    'green': '\x0303'
+                    'blue': '\x0302'
+                    'red': '\x0305'
+                    'yellow': '\x0307'
+                    'brown': '\x0305'
+                    'magenta': '\x0306'
+                    'cyan': '\x0310'
+                    'reset': '\x0F'
+                    }
+        return colours
+
+    def project(self):
+        projet = self.config.get('irker_project')
+        if project is None:
+            project = 'No Project name set'
+        return project
+
     def send(self):
         """Send the info to irkerd.
         """