Browse Source

improved warnings for collect and limit tools.

avkonst 11 years ago
parent
commit
9879d7d310

+ 1 - 1
mainline/core/export/cout.py

@@ -21,7 +21,7 @@ SEVERITY_INFO    = 0x01
 SEVERITY_WARNING = 0x02
 SEVERITY_ERROR   = 0x03
 
-def cout(path, cursor, level, message, details):
+def notify(path, cursor, level, message, details = []):
     notification = path + ":" + str(cursor) + ": "
     if level == SEVERITY_INFO:
         notification += "info: "

+ 13 - 5
mainline/ext/std/code/cpp.py

@@ -20,9 +20,9 @@
 
 import re
 import binascii
-import logging
 
 import core.api
+import core.cout
 
 class Plugin(core.api.Plugin, core.api.Parent, core.api.IParser, core.api.IConfigurable, core.api.ICode):
     
@@ -230,8 +230,10 @@ class CppCodeParser(object):
                 if blocks[curblk]['indent_start'] == indent_current:
                     next_block = reset_next_block(m.end())
                     if curblk == 0:
-                        logging.warning("Non-matching closing bracket '}' detected: " + data.get_path() + ":" +
-                                        str(cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start()))))
+                        core.cout.notify(data.get_path(),
+                                         cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                         core.cout.SEVERITY_WARNING,
+                                         "Non-matching closing bracket '}' detected.")
                         count_mismatched_brackets += 1
                         continue
                     
@@ -245,7 +247,10 @@ class CppCodeParser(object):
                 # shift indent left
                 indent_current -= 1
                 if indent_current < 0:
-                    logging.warning("Non-matching closing bracket '}' detected")
+                    core.cout.notify(data.get_path(),
+                                     cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                     core.cout.SEVERITY_WARNING,
+                                     "Non-matching closing bracket '}' detected.")
                     count_mismatched_brackets += 1
                     indent_current = 0
 
@@ -286,7 +291,10 @@ class CppCodeParser(object):
 
         while indent_current > 0:
             # log all
-            logging.warning("Non-matching opening bracket '{' detected")
+            core.cout.notify(data.get_path(),
+                             cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, len(text))),
+                             core.cout.SEVERITY_WARNING,
+                             "Non-matching opening bracket '{' detected.")
             count_mismatched_brackets += 1
             indent_current -= 1
 

+ 13 - 5
mainline/ext/std/code/cs.py

@@ -20,9 +20,9 @@
 
 import re
 import binascii
-import logging
 
 import core.api
+import core.cout
 
 class Plugin(core.api.Plugin, core.api.Parent, core.api.IParser, core.api.IConfigurable, core.api.ICode):
     
@@ -246,8 +246,10 @@ class CsCodeParser(object):
                 if blocks[curblk]['indent_start'] == indent_current:
                     next_block = reset_next_block(m.end())
                     if curblk == 0:
-                        logging.warning("Non-matching closing bracket '}' detected: " + data.get_path() + ":" +
-                                        str(cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start()))))
+                        core.cout.notify(data.get_path(),
+                                         cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                         core.cout.SEVERITY_WARNING,
+                                         "Non-matching closing bracket '}' detected.")
                         count_mismatched_brackets += 1
                         continue
                     
@@ -261,7 +263,10 @@ class CsCodeParser(object):
                 # shift indent left
                 indent_current -= 1
                 if indent_current < 0:
-                    logging.warning("Non-matching closing bracket '}' detected")
+                    core.cout.notify(data.get_path(),
+                                     cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                     core.cout.SEVERITY_WARNING,
+                                     "Non-matching closing bracket '}' detected.")
                     count_mismatched_brackets += 1
                     indent_current = 0
 
@@ -301,7 +306,10 @@ class CsCodeParser(object):
 
         while indent_current > 0:
             # log all
-            logging.warning("Non-matching opening bracket '{' detected")
+            core.cout.notify(data.get_path(),
+                             cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, len(text))),
+                             core.cout.SEVERITY_WARNING,
+                             "Non-matching opening bracket '{' detected.")
             count_mismatched_brackets += 1
             indent_current -= 1
 

+ 13 - 5
mainline/ext/std/code/java.py

@@ -20,9 +20,9 @@
 
 import re
 import binascii
-import logging
 
 import core.api
+import core.cout
 
 class Plugin(core.api.Plugin, core.api.Parent, core.api.IParser, core.api.IConfigurable, core.api.ICode):
     
@@ -206,8 +206,10 @@ class JavaCodeParser(object):
                 if blocks[curblk]['indent_start'] == indent_current:
                     next_block = reset_next_block(m.end())
                     if curblk == 0:
-                        logging.warning("Non-matching closing bracket '}' detected: " + data.get_path() + ":" +
-                                        str(cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start()))))
+                        core.cout.notify(data.get_path(),
+                                         cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                         core.cout.SEVERITY_WARNING,
+                                         "Non-matching closing bracket '}' detected.")
                         count_mismatched_brackets += 1
                         continue
                     
@@ -221,7 +223,10 @@ class JavaCodeParser(object):
                 # shift indent left
                 indent_current -= 1
                 if indent_current < 0:
-                    logging.warning("Non-matching closing bracket '}' detected")
+                    core.cout.notify(data.get_path(),
+                                     cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, m.start())),
+                                     core.cout.SEVERITY_WARNING,
+                                     "Non-matching closing bracket '}' detected.")
                     count_mismatched_brackets += 1
                     indent_current = 0
 
@@ -260,7 +265,10 @@ class JavaCodeParser(object):
 
         while indent_current > 0:
             # log all
-            logging.warning("Non-matching opening bracket '{' detected")
+            core.cout.notify(data.get_path(),
+                             cursor_current + len(self.regex_ln.findall(text, cursor_last_pos, len(text))),
+                             core.cout.SEVERITY_WARNING,
+                             "Non-matching opening bracket '{' detected.")
             count_mismatched_brackets += 1
             indent_current -= 1
 

+ 3 - 3
mainline/ext/std/suppress.py

@@ -18,7 +18,7 @@
 #
 
 import core.api
-import core.export.cout
+import core.cout
 
 import re
 
@@ -72,8 +72,8 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
                         namespace_name, field = m.split(':')
                         namespace = self.get_plugin_loader().get_database_loader().get_namespace(namespace_name)
                         if namespace == None or namespace.get_field_packager(field) == None:
-                            core.export.cout.cout(data.get_path(), region.get_cursor(),
-                                                  core.export.cout.SEVERITY_WARNING,
+                            core.cout.notify(data.get_path(), region.get_cursor(),
+                                                  core.cout.SEVERITY_WARNING,
                                                   "Suppressed metric '" + namespace_name + ":" + field +
                                                     "' is not being collected",
                                                   [("Metric name", namespace_name + ":" + field),

+ 6 - 0
mainline/tests/general/test_std_code_cpp/test_parser_collect_default_stdout.gold.txt

@@ -0,0 +1,6 @@
+./test3.cpp:68: warning: Non-matching closing bracket '}' detected.
+
+./test3.cpp:88: warning: Non-matching closing bracket '}' detected.
+
+./test3.cpp:110: warning: Non-matching opening bracket '{' detected.
+

+ 2 - 2
mainline/tools/limit.py

@@ -24,7 +24,7 @@ import core.log
 import core.db.loader
 import core.db.post
 import core.db.utils
-import core.export.cout
+import core.cout
 import core.warn
 import core.cmdparser
 
@@ -211,7 +211,7 @@ def report_limit_exceeded(path, cursor, namespace, field, region_name,
                ("Change trend", '{0:{1}}'.format(trend_value, '+' if trend_value else '')),
                ("Limit", stat_limit),
                ("Suppressed", is_suppressed)]
-    core.export.cout.cout(path, cursor, core.export.cout.SEVERITY_WARNING, message, details)
+    core.cout.notify(path, cursor, core.cout.SEVERITY_WARNING, message, details)