Source

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

# HG changeset patch
# User Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
# Date 1280876358 -7200
# Node ID 15126c8358813d60d0a73d3e5965774bf14a2de0
# Parent dc2797856c153b649049583ebef79122fcfe43fd
imported patch kill-validator-types-subtypes-enums

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,7 +38,7 @@ from pida.core.languages import (Languag
     Documentator, External)
 
 from pida.utils.languages import (
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_OUTLINER_TYPES, 
+    LANG_OUTLINER_TYPES, 
     LANG_PRIO, Definition, Suggestion, Documentation, ValidationError)
 
 # services
@@ -222,22 +222,22 @@ 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.subtype = 'syntax'
     else:
-        msg.subtype = LANG_VALIDATOR_SUBTYPES.INDENTATION
+        msg.subtype = '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:
+        if self.type_ == 'error':
             typec = self.lookup_color('pida-val-error')
-        elif self.type_ == LANG_VALIDATOR_TYPES.INFO:
+        elif self.type_ == 'info':
             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')
@@ -257,10 +257,9 @@ class PythonError(ValidationError):
     """<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,
+                      'type': self.type_.capitalize(),
+                      'subtype': self.subtype.capitalize(),
+                      'message': message_string,
                       'linecolor': linecolor,
                       'typec': typec,
                       })
@@ -285,26 +284,27 @@ 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
+                type_ = 'info'
+                subtype = 'unused'
             elif isinstance(m, pyflakes.messages.RedefinedWhileUnused):
-                type_ = LANG_VALIDATOR_TYPES.WARNING
-                subtype = LANG_VALIDATOR_SUBTYPES.REDEFINED
+                type_ = 'warning'
+                subtype = 'redefined'
             elif isinstance(m, pyflakes.messages.ImportStarUsed):
-                type_ = LANG_VALIDATOR_TYPES.WARNING
-                subtype = LANG_VALIDATOR_SUBTYPES.BADSTYLE
+                type_ = 'warning'
+                subtype = 'badstyle'
             elif isinstance(m, pyflakes.messages.UndefinedName):
-                type_ = LANG_VALIDATOR_TYPES.ERROR
-                subtype = LANG_VALIDATOR_SUBTYPES.UNDEFINED
+                type_ = 'error'
+                subtype = 'undefined'
             elif isinstance(m, pyflakes.messages.DuplicateArgument):
-                type_ = LANG_VALIDATOR_TYPES.ERROR
-                subtype = LANG_VALIDATOR_SUBTYPES.DUPLICATE
+                type_ = 'error'
+                subtype = 'duplicate'
+            else:
+                type_ = 'unknown'
+                subtype = 'unknown'
 
             ve = PythonError(
                 message=m.message,
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
@@ -21,8 +21,7 @@ from pida.core.options import OptionsCon
 from pida.core.log import Log
 
 from pida.core.languages import (LanguageService, Validator, External)
-from pida.utils.languages import (LANG_COMPLETER_TYPES,
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
+from pida.utils.languages import (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.type_.capitalize(),
+                      'subtype': self.subtype.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
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,10 @@ 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,
+    OutlineItem, ValidationError,
+)
 from pida.services.language import DOCTYPES
 
 # docutils imports
@@ -312,7 +313,7 @@ class RSTValidator(Validator):
     name = "rst validator"
     description = _("A validator for ReStructuredText")
 
-    subtype = LANG_VALIDATOR_SUBTYPES.SYNTAX
+    subtype = 'syntax'
 
     def get_validations(self):
         self.rstplugin = RSTPlugin(self.svc)
@@ -335,9 +336,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_ = ('info', 'warning', 'error', 'fatal')[msg['level'] - 1]
         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
@@ -15,8 +15,8 @@ from pida.core.document import Document
 from pida.core.projects import Project
 from pida.core.service import Service
 from pida.core.features import FeaturesConfig
-from pida.utils.languages import (LANG_COMPLETER_TYPES,
-    LANG_VALIDATOR_TYPES, LANG_VALIDATOR_SUBTYPES, LANG_PRIO,
+from pida.utils.languages import (
+    LANG_COMPLETER_TYPES, 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
@@ -117,8 +117,8 @@ class ValidationError(InitObject):
     """Message a Validator should return"""
     message = ''
     message_args = None
-    type_ = LANG_VALIDATOR_TYPES.UNKNOWN
-    subtype = LANG_VALIDATOR_SUBTYPES.UNKNOWN
+    type_ = 'unknown'
+    subtype = 'unknown'
     filename = None
     lineno = None
 
@@ -135,11 +135,11 @@ class ValidationError(InitObject):
         pass
 
     def get_markup(self):
-        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_ == 'info':
             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')
@@ -148,7 +148,7 @@ class ValidationError(InitObject):
     """<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()),
+                      'type':_(self.type_.capitalize()),
                       'subtype':_(LANG_VALIDATOR_SUBTYPES.whatis(
                                     self.subtype).capitalize()),
                       'message':self.message,