Source

pida-patches / validator-markup-format-cleanup

# HG changeset patch
# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
# Date 1280876358 -7200
# Node ID 5d747f356bfc547439b23bd62b5b2f225851cf50
# Parent 985a4f0089877903d25796735027805edb55b6bb
imported patch validator-markip-format-cleanup

diff --git a/pida-plugins/python/python.py b/pida-plugins/python/python.py
--- a/pida-plugins/python/python.py
+++ b/pida-plugins/python/python.py
@@ -225,41 +225,12 @@ def _create_exception_validation(e):
     return [msg]
 
 class PythonError(ValidationError):
-    def get_markup(self):
+    def get_format_args(self):
         args = [('<b>%s</b>' % arg) for arg in self.message_args]
-        message_string = self.message % tuple(args)
-        if self.type_ == 'error':
-            typec = self.lookup_color('pida-val-error')
-        elif self.type_ == 'info':
-            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:
-            typec = "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>\n%(message)s""" % 
-                      {'lineno':self.lineno, 
-                      'type': self.type_.capitalize(),
-                      'subtype': self.subtype.capitalize(),
-                      'message': message_string,
-                      'linecolor': linecolor,
-                      'typec': typec,
-                      })
-        return markup
-    markup = property(get_markup)
+        data = ValidationError.get_format_args(self)
+        data['message'] = self.message % tuple(args)
+        return data
+
 
 class PythonValidator(Validator):
 
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
@@ -44,50 +44,6 @@ except ImportError:
     pylint = None
     BaseReporter = object
 
-# class SkeletonEventsConfig(EventsConfig):
-#
-#     def subscribe_all_foreign(self):
-#         self.subscribe_foreign('buffer', 'document-changed',
-#                     self.on_document_changed)
-#
-#     def on_document_changed(self, document):
-#         pass
-#
-#
-# class SkeletonFeaturesConfig(FeaturesConfig):
-#
-#     def subscribe_all_foreign(self):
-#         pass
-#
-#
-# class SkeletonOptionsConfig(OptionsConfig):
-#
-#     def create_options(self):
-#         self.create_option(
-#             'Skeleton_for_executing',
-#             _('Skeleton Executable for executing'),
-#             str,
-#             'Skeleton',
-#             _('The Skeleton executable when executing a module'),
-#         )
-#
-#
-# class SkeletonActionsConfig(ActionsConfig):
-#
-#     def create_actions(self):
-#         self.create_action(
-#             'execute_Skeleton',
-#             TYPE_NORMAL,
-#             _('Execute Skeleton Module'),
-#             _('Execute the current Skeleton module in a shell'),
-#             gtk.STOCK_EXECUTE,
-#             self.on_Skeleton_execute,
-#         )
-#
-#     def on_Skeleton_execute(self, action):
-#         #self.svc.execute_current_document()
-#         pass
-
 SUBTYPE_MAPPING = {
     'W0511': 'fixme',
     'W0622': 'redefined',
@@ -105,53 +61,35 @@ class PythonError(ValidationError, Log):
     """
     Validator class for PyLint errrors
     """
-    def get_markup(self):
+    
+    markup_format = (
+        '<tt><span color="{line_color}">{lineno}</span> </tt>'
+        '<span foreground="{type_color}" style="italic" weight="bold">{type}'
+        '</span>::<span style="italic">%(subtype)s</span> '
+        '<span size="small" style="italic">{msg_id}</span>\n'
+        '{message}'
+    )
+    def get_format_args(self):
         if self.message_args:
             try:
                 if isinstance(self.message_args, (list, tuple)):
                     args = [('<b>%s</b>' % arg) for arg in self.message_args]
-                    message_string = self.message % tuple(args)
+                    message = self.message % tuple(args)
                 else:
                     args = '<b>%s</b>' % self.message_args
-                    message_string = self.message % args
+                    message = self.message % args
             except TypeError, e:
                 self.log.warning("Can't convert arguments %s : %s" %(
                                     self.message, self.message_args))
-                message_string = self.message
+                message = 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.type_.capitalize(),
-                      'subtype': self.subtype.capitalize(),
-                      'message': message_string,
-                      'linecolor': linecolor,
-                      'typec': typec,
-                      'msg_id': self.msg_id
-                      })
-        return markup
-    markup = property(get_markup)
+            message = self.message
 
+        base = ValidationError.get_format_args(self)
+        base.update({
+            'msg_id': self.msg_id,
+            'message': message_string,
+        })
 
 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
@@ -122,52 +122,41 @@ class ValidationError(InitObject):
     filename = None
     lineno = None
 
+
+    markup_format =(
+        '<tt><span color="{line_color}">{lineno}</span> </tt>'
+        '<span foreground="{type_color}" style="italic" weight="bold">{type}'
+        '</span>::<span style="italic">%(subtype)s</span>\n'
+        '{message}'
+    )
     def __str__(self):
         return '%s:%s: %s' % (self.filename, self.lineno, self.message)
 
     def lookup_color(self, color):
         return "#000000"
 
-    @staticmethod
-    def from_exception(exc):
-        """Returns a new Message from a python exception"""
-        # FIXME
-        pass
+    def _type_color(self):
+        mapping = {
+            'error': 'pida-val-error',
+            'info': 'pida-val-info',
+            'warning': 'pida-val-warning',
+        }
+        lookup = mapping.get(self._type, 'pida-val-def')
+        return self.lookup_color(lookup)
 
-    def get_markup(self):
-        if self.type_ == 'error':
-            typec = self.lookup_color('pida-val-error')
-        elif self.type_ == 'info':
-            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')
-        
-        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.type_.capitalize(),
-                      'subtype': self.subtype.capitalize(),
-                      'message': self.message,
-                      'linecolor': color_to_string(self.lookup_color('pida-lineno')),
-                      'typec': color_to_string(typec),
-                      })
-        return markup
-    markup = property(get_markup)
-#     def get_markup(self):
-#         #args = [('<b>%s</b>' % arg) for arg in msg.message_args]
-#         #message_string = self.message % tuple(args)
-#         #msg.name = msg.__class__.__name__
-#         markup = ('<tt>%s </tt><i>%s:%s</i>\n%s' % 
-#                       (self.lineno, 
-#                       LANG_VALIDATOR_TYPES.whatis(self.type_).capitalize(),
-#                       LANG_VALIDATOR_SUBTYPES.whatis(self.subtype).capitalize(),
-#                       self.message))
-#         return markup
-#     
-#     markup = property(get_markup)
+    @property
+    def markup(self):
+        return self.markup_format.format(**self.get_format_args())
+
+    def get_format_args(self):
+        return dict(
+            lineno=self.lineno,
+            type=self.type_.capitalize(),
+            subtype=self.subtype.capitalize(),
+            message=self.message,
+            line_color=color_to_string(self.lookup_color('pida-lineno')),
+            type_color=color_to_string(self._type_color()),
+            )