pida-patches / kill-validator-types-subtypes-enums

# HG changeset patch
# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
# Date 1280876358 -7200
# Node ID 15126c8358813d60d0a73d3e5965774bf14a2de0
# Parent ee8ff69d6892f053e2ca214ed0811a055be8fbc7
switch the validator enums for VALIDATOR_LEVEL and VALIDATOR_KIND symbol bags

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
@@ -38,8 +38,8 @@ from pida.core.languages import (Languag
     Documentator, External)
 
 from pida.utils.languages import (
-    COMPLETER,
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_OUTLINER_TYPES, 
+    COMPLETER, VALIDATOR_LEVEL, VALIDATOR_KIND,
+    LANG_OUTLINER_TYPES, 
     LANG_PRIO, Definition, Suggestion, Documentation, ValidationError)
 
 # services
@@ -223,51 +223,13 @@ def _create_exception_validation(e):
     msg.lineno = lineno
     msg.message_args = (line,)
     msg.message = '<tt>%%s</tt>\n<tt>%s^</tt>' % (' ' * (offset - 2))
-    msg.type_ = LANG_VALIDATOR_TYPES.ERROR
+    msg.type_ = 'error'
     if isinstance(e, SyntaxError):
-        msg.subtype = LANG_VALIDATOR_SUBTYPES.SYNTAX
+        msg.kind = 'syntax'
     else:
-        msg.subtype = LANG_VALIDATOR_SUBTYPES.INDENTATION
+        msg.kind = 'indentation'
     return [msg]
 
-class PythonError(ValidationError):
-    def get_markup(self):
-        args = [('<b>%s</b>' % arg) for arg in self.message_args]
-        message_string = self.message % tuple(args)
-        if self.type_ == LANG_VALIDATOR_TYPES.ERROR:
-            typec = self.lookup_color('pida-val-error')
-        elif self.type_ == LANG_VALIDATOR_TYPES.INFO:
-            typec = self.lookup_color('pida-val-info')
-        elif self.type_ == LANG_VALIDATOR_TYPES.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':_(LANG_VALIDATOR_TYPES.whatis(self.type_).capitalize()),
-                      'subtype':_(LANG_VALIDATOR_SUBTYPES.whatis(
-                                    self.subtype).capitalize()),
-                      'message':message_string,
-                      'linecolor': linecolor,
-                      'typec': typec,
-                      })
-        return markup
-    markup = property(get_markup)
-
 class PythonValidator(Validator):
 
     priority = LANG_PRIO.GOOD
@@ -286,33 +248,34 @@ class PythonValidator(Validator):
             w = Checker(tree, filename)
             messages = w.messages
         for m in messages:
-            type_ = getattr(m, 'type_', LANG_VALIDATOR_TYPES.UNKNOWN)
-            subtype = getattr(m, 'subtype', LANG_VALIDATOR_SUBTYPES.UNKNOWN)
 
             #FIXME add pyflakes 0.3 types
             #FIXME make mapping
             if isinstance(m, pyflakes.messages.UnusedImport):
-                type_ = LANG_VALIDATOR_TYPES.INFO
-                subtype = LANG_VALIDATOR_SUBTYPES.UNUSED
+                level = VALIDATOR_LEVEL.INFO
+                kind = VALIDATOR_KIND.UNUSED
             elif isinstance(m, pyflakes.messages.RedefinedWhileUnused):
-                type_ = LANG_VALIDATOR_TYPES.WARNING
-                subtype = LANG_VALIDATOR_SUBTYPES.REDEFINED
+                level = VALIDATOR_LEVEL.WARNING
+                kind = VALIDATOR_KIND.REDEFINED
             elif isinstance(m, pyflakes.messages.ImportStarUsed):
-                type_ = LANG_VALIDATOR_TYPES.WARNING
-                subtype = LANG_VALIDATOR_SUBTYPES.BADSTYLE
+                level = VALIDATOR_LEVEL.WARNING
+                kind = VALIDATOR_KIND.BADSTYLe
             elif isinstance(m, pyflakes.messages.UndefinedName):
-                type_ = LANG_VALIDATOR_TYPES.ERROR
-                subtype = LANG_VALIDATOR_SUBTYPES.UNDEFINED
+                level = VALIDATOR_LEVEL.ERROR
+                kind = VALIDATOR_KIND.UNDEFINED
             elif isinstance(m, pyflakes.messages.DuplicateArgument):
-                type_ = LANG_VALIDATOR_TYPES.ERROR
-                subtype = LANG_VALIDATOR_SUBTYPES.DUPLICATE
+                type_ = VALIDATOR_LEVEL.ERROR
+                kind = VALIDATOR_KIND.DUPLICATE
+            else:
+                level = VALIDATOR_LEVEL.UNKNOWN
+                kind = VALIDATOR_KIND.UNKNOWN
 
-            ve = PythonError(
+            ve = ValidationError(
                 message=m.message,
                 message_args=m.message_args,
                 lineno=m.lineno,
-                type_=type_,
-                subtype=subtype,
+                level=level,
+                kind=kind,
                 filename=filename
                 )
             yield ve
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
@@ -22,7 +22,6 @@ from pida.core.log import Log
 
 from pida.core.languages import (LanguageService, Validator, External)
 from pida.utils.languages import (
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
    Definition, Suggestion, Documentation, ValidationError)
 
 # locale
@@ -90,16 +89,15 @@ except ImportError:
 #         pass
 
 SUBTYPE_MAPPING = {
-'W0511': LANG_VALIDATOR_SUBTYPES.FIXME,
-'W0622': LANG_VALIDATOR_SUBTYPES.REDEFINED,
-'W0611': LANG_VALIDATOR_SUBTYPES.UNUSED,
-'W0612': LANG_VALIDATOR_SUBTYPES.UNUSED,
-'E1101': LANG_VALIDATOR_SUBTYPES.UNDEFINED,
-'W0201': LANG_VALIDATOR_SUBTYPES.UNDEFINED,
-'W0212': LANG_VALIDATOR_SUBTYPES.PROTECTION,
-'W0703': LANG_VALIDATOR_SUBTYPES.DANGEROUS,
-'W0107': LANG_VALIDATOR_SUBTYPES.UNUSED,
-
+    'W0511': 'fixme',
+    'W0622': 'redefined',
+    'W0611': 'unused',
+    'W0612': 'unused',
+    'E1101': 'undefined',
+    'W0201': 'undefined',
+    'W0212': 'protection',
+    'W0703': 'dangerous',
+    'W0107': 'unused',
 }
 
 
@@ -122,11 +120,11 @@ class PythonError(ValidationError, Log):
                 message_string = self.message
         else:
             message_string = self.message
-        if self.type_ == LANG_VALIDATOR_TYPES.ERROR:
+        if self.type_ == 'error':
             typec = self.lookup_color('pida-val-error')
-        elif self.type_ == LANG_VALIDATOR_TYPES.INFO:
+        elif self.type_ == 'error':
             typec = self.lookup_color('pida-val-info')
-        elif self.type_ == LANG_VALIDATOR_TYPES.WARNING:
+        elif self.type_ == 'warning':
             typec = self.lookup_color('pida-val-warning')
         else:
             typec = self.lookup_color('pida-val-def')
@@ -144,10 +142,9 @@ class PythonError(ValidationError, Log):
     """>:<span style="italic">%(subtype)s</span>  -  """
     """<span size="small" style="italic">%(msg_id)s</span>\n%(message)s""" % 
                       {'lineno':self.lineno,
-                      'type':_(LANG_VALIDATOR_TYPES.whatis(self.type_).capitalize()),
-                      'subtype':_(LANG_VALIDATOR_SUBTYPES.whatis(
-                                    self.subtype).capitalize()),
-                      'message':message_string,
+                      'type': self.level.capitalize(),
+                      'subtype': self.kind.capitalize(),
+                      'message': message_string,
                       'linecolor': linecolor,
                       'typec': typec,
                       'msg_id': self.msg_id
@@ -225,26 +222,26 @@ class PidaLinter(PyLinter, Log):
             return        
         # update stats
         if msg_id[0] == 'I':
-            ty = LANG_VALIDATOR_TYPES.INFO
-            sty = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+            ty = 'info'
+            sty = 'unknown'
         elif msg_id[0] == 'C':
-            ty = LANG_VALIDATOR_TYPES.INFO
-            sty = LANG_VALIDATOR_SUBTYPES.BADSTYLE
+            ty = 'info'
+            sty = 'badstyle'
         elif msg_id[0] == 'R':
-            ty = LANG_VALIDATOR_TYPES.WARNING
-            sty = LANG_VALIDATOR_SUBTYPES.BADSTYLE
+            ty = 'info'
+            sty = 'badstyle'
         elif msg_id[0] == 'W':
-            ty = LANG_VALIDATOR_TYPES.WARNING
-            sty = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+            ty = 'warning'
+            sty = 'unknown'
         elif msg_id[0] == 'E':
-            ty = LANG_VALIDATOR_TYPES.ERROR
-            sty = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+            ty = 'error'
+            sty = 'unknown'
         elif msg_id[0] == 'F':
-            ty = LANG_VALIDATOR_TYPES.FATAL
-            sty = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+            ty = 'fatal'
+            sty = 'unknown'
         else:
-            ty = LANG_VALIDATOR_TYPES.UNKNOWN
-            sty = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+            ty = 'unknown'
+            sty = 'unknown'
 
         #msg_cat = MSG_TYPES[msg_id[0]]
         #self.stats[msg_cat] += 1
@@ -269,8 +266,8 @@ class PidaLinter(PyLinter, Log):
             path = node.root().file
         # add the message
         cmsg = PythonError( message = msg,
-                            type_ = ty,
-                            subtype = sty,
+                            level = ty,
+                            kind = sty,
                             filename = path,
                             message_args = args or (),
                             lineno = line or 1,
diff --git a/pida-plugins/rst/rst.py b/pida-plugins/rst/rst.py
--- a/pida-plugins/rst/rst.py
+++ b/pida-plugins/rst/rst.py
@@ -12,9 +12,11 @@ from collections import defaultdict
 
 # PIDA imports
 from pida.core.languages import LanguageService, Outliner, Validator
-from pida.utils.languages import (LANG_PRIO,
-    LANG_OUTLINER_TYPES, OutlineItem,
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, ValidationError)
+from pida.utils.languages import (
+    LANG_PRIO, LANG_OUTLINER_TYPES,
+    VALIDATOR_LEVEL, VALIDATOR_KIND,
+    OutlineItem, ValidationError,
+)
 from pida.services.language import DOCTYPES
 
 # docutils imports
@@ -312,20 +314,20 @@ class RSTValidator(Validator):
     name = "rst validator"
     description = _("A validator for ReStructuredText")
 
-    subtype = LANG_VALIDATOR_SUBTYPES.SYNTAX
+    kind = VALIDATOR_KIND.SYNTAX
 
     def get_validations(self):
         self.rstplugin = RSTPlugin(self.svc)
         self.doctree = self.rstplugin.parse_rst(self.document)
         if self.doctree:
             for msg in self.doctree.parse_messages :
-                message, type_, filename, lineno = self._parse_error(msg)
+                message, level, filename, lineno = self._parse_error(msg)
                 # TODO need to filter out duplicates with no lineno set
                 # not sure why this happens...
                 if lineno:
                     yield ValidationError (message=message,
-                                           type_=type_,
-                                           subtype=self.subtype,
+                                           level=level,
+                                           kind=self.kind,
                                            filename=filename,
                                            lineno=lineno)
 
@@ -335,9 +337,7 @@ class RSTValidator(Validator):
         message = textwrap.fill(msg.children[0].children[0].data, width)
         # docutils defines the following error levels:
         #     "info/1", '"warning"/"2" (default), "error"/"3", "severe"/"4"
-        type_ = (LANG_VALIDATOR_TYPES.INFO, LANG_VALIDATOR_TYPES.WARNING,
-                 LANG_VALIDATOR_TYPES.ERROR, LANG_VALIDATOR_TYPES.FATAL
-                )[msg['level'] - 1]
+        type_ = VALIDATOR_LEVEL[msg['level']]
         filename = msg.source
         lineno = msg.line
         return (message, type_, filename, lineno)
diff --git a/pida/core/languages.py b/pida/core/languages.py
--- a/pida/core/languages.py
+++ b/pida/core/languages.py
@@ -16,7 +16,7 @@ from pida.core.projects import Project
 from pida.core.service import Service
 from pida.core.features import FeaturesConfig
 from pida.utils.languages import (
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
+    COMPLETER, LANG_PRIO,
     Suggestion, Definition, ValidationError, Documentation)
 from pida.utils.path import get_relative_path
 # locale
diff --git a/pida/utils/languages.py b/pida/utils/languages.py
--- a/pida/utils/languages.py
+++ b/pida/utils/languages.py
@@ -41,14 +41,13 @@ COMPLETER = Symbols('completer', [
 
 
 
-# main types
-LANG_VALIDATOR_TYPES = Enumeration('LANG_TYPES',
-    ('UNKNOWN', 'INFO', 'WARNING', 'ERROR', 'FATAL'))
+VALIDATOR_KIND = Symbols('validation errors',
+    ('unknown', 'syntax', 'indentation', 'undefined', 'redefined', 'badstyle',
+     'duplicate', 'unused', 'fixme', 'protection', 'dangerous'))
 
-# validation sub types
-LANG_VALIDATOR_SUBTYPES = Enumeration('LANG_VALIDATION_ERRORS',
-    ('UNKNOWN', 'SYNTAX', 'INDENTATION', 'UNDEFINED', 'REDEFINED', 'BADSTYLE',
-     'DUPLICATE', 'UNUSED', 'FIXME', 'PROTECTION', 'DANGEROUS'))
+VALIDATOR_LEVEL = Symbols('validation level',
+    ('unknown', 'info', 'warning', 'error', 'fatal'))
+
 
 # validation sub types
 
@@ -116,8 +115,8 @@ class ValidationError(InitObject):
     """Message a Validator should return"""
     message = ''
     message_args = None
-    type_ = LANG_VALIDATOR_TYPES.UNKNOWN
-    subtype = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+    level = VALIDATOR_LEVEL.UNKNOWN
+    kind = VALIDATOR_KIND.UNKNOWN
     filename = None
     lineno = None
 
@@ -134,41 +133,25 @@ class ValidationError(InitObject):
         pass
 
     def get_markup(self):
-        if self.type_ == LANG_VALIDATOR_TYPES.ERROR:
-            typec = self.lookup_color('pida-val-error')
-        elif self.type_ == LANG_VALIDATOR_TYPES.INFO:
-            typec = self.lookup_color('pida-val-info')
-        elif self.type_ == LANG_VALIDATOR_TYPES.WARNING:
-            typec = self.lookup_color('pida-val-warning')
-        else:
-            typec = self.lookup_color('pida-val-def')
-        
+        mapping = {
+            VALIDATOR_LEVEL.ERROR: 'pida-val-error',
+            VALIDATOR_LEVEL.INFO: 'pida-val-info',
+            VALIDATOR_LEVEL.WARNING: 'pida-val-warning',
+        }
+        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':_(LANG_VALIDATOR_TYPES.whatis(self.type_).capitalize()),
-                      'subtype':_(LANG_VALIDATOR_SUBTYPES.whatis(
-                                    self.subtype).capitalize()),
+                      '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)
-#     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)
-
 
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.