Source

pida-patches / cleanup-validator-markup

Full commit
# HG changeset patch
# Parent 24ccd4947bee2bb0bf9cbf74b2460b55a9bf6b1d

diff --git a/pida-plugins/python_lint/python_lint.py b/pida-plugins/python_lint/python_lint.py
--- a/pida-plugins/python_lint/python_lint.py
+++ b/pida-plugins/python_lint/python_lint.py
@@ -63,7 +63,7 @@ class PythonError(ValidationError, Log):
     """
     Validator class for PyLint errrors
     """
-    def get_markup(self):
+    def markup_args(self):
         if self.message_args:
             try:
                 if isinstance(self.message_args, (list, tuple)):
@@ -78,38 +78,9 @@ class PythonError(ValidationError, Log):
                 message_string = self.message
         else:
             message_string = self.message
-        if self.type_ == 'error':
-            typec = self.lookup_color('pida-val-error')
-        elif self.type_ == 'error':
-            typec = self.lookup_color('pida-val-info')
-        elif self.type_ == 'warning':
-            typec = self.lookup_color('pida-val-warning')
-        else:
-            typec = self.lookup_color('pida-val-def')
-        if typec:
-            typec = typec.to_string()
-        else:
-            linecolor = "black"
-        linecolor = self.lookup_color('pida-lineno')
-        if linecolor:
-            linecolor = linecolor.to_string()
-        else:
-            linecolor = "black"
-        markup = ("""<tt><span color="%(linecolor)s">%(lineno)s</span> </tt>"""
-    """<span foreground="%(typec)s" style="italic" weight="bold">%(type)s</span"""
-    """>:<span style="italic">%(subtype)s</span>  -  """
-    """<span size="small" style="italic">%(msg_id)s</span>\n%(message)s""" % 
-                      {'lineno':self.lineno,
-                      'type': self.level.capitalize(),
-                      'subtype': self.kind.capitalize(),
-                      'message': message_string,
-                      'linecolor': linecolor,
-                      'typec': typec,
-                      'msg_id': self.msg_id
-                      })
-        return markup
-    markup = property(get_markup)
-
+        mapping = ValidationError.markup_args(self)
+        mapping['message'] = message_string
+        return mapping
 
 from logilab.common.ureports import TextWriter
 from logilab.common.textutils import get_csv
diff --git a/pida/utils/languages.py b/pida/utils/languages.py
--- a/pida/utils/languages.py
+++ b/pida/utils/languages.py
@@ -120,6 +120,15 @@ class ValidationError(InitObject):
     filename = None
     lineno = None
 
+    markup_string = (
+        '<tt><span color="{linecolor}">{lineno}</span> </tt>'
+        '<span foreground="{level_color}" style="italic" weight="bold">'
+        '{level}</span>:'
+        '<span style="italic">{kind}</span>\n'
+        '{message}'
+    )
+
+
     def __str__(self):
         return '%s:%s: %s' % (self.filename, self.lineno, self.message)
 
@@ -132,7 +141,12 @@ class ValidationError(InitObject):
         # FIXME
         pass
 
-    def get_markup(self):
+
+    @property
+    def markup(self):
+        return self.markup_string.format(**self.markup_args())
+
+    def markup_args(self):
         mapping = {
             'error': 'pida-val-error',
             'info': 'pida-val-info',
@@ -140,18 +154,14 @@ class ValidationError(InitObject):
         }
         typec = mapping.get(self.kind, 'pida-val-def')
 
-        markup = ("""<tt><span color="%(linecolor)s">%(lineno)s</span> </tt>"""
-    """<span foreground="%(typec)s" style="italic" weight="bold">%(type)s</span"""
-    """>:<span style="italic">%(subtype)s</span>\n%(message)s""" % 
-                      {'lineno':self.lineno, 
-                      'type': self.level.capitalize(),
-                      'subtype': self.kind.capitalize(),
-                      'message':self.message,
-                      'linecolor': color_to_string(self.lookup_color('pida-lineno')),
-                      'typec': color_to_string(typec),
-                      })
-        return markup
-    markup = property(get_markup)
+        return {
+            'lineno': self.lineno,
+            'level': self.level.capitalize(),
+            'level_color': color_to_string(typec),
+            'kind': self.kind.capitalize(),
+            'message': self.message,
+            'linecolor': color_to_string(self.lookup_color('pida-lineno')),
+        }