فهرست منبع

New troubleshooting tool added, replaced dumper plugin.

avkonst 12 سال پیش
والد
کامیت
4845def219

+ 108 - 0
mainline/debug.py

@@ -0,0 +1,108 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, version 3 of the License.
+#    
+#    Metrix++ is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#    GNU General Public License for more details.
+#    
+#    You should have received a copy of the GNU General Public License
+#    along with Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import logging
+import time
+import cgi
+
+import core.log
+import core.cmdparser
+import core.db.post
+import core.db.loader
+
+def main():
+    log_plugin = core.log.Plugin()
+    db_plugin = core.db.post.Plugin()
+
+    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [path 1] ... [path N]")
+    log_plugin.declare_configuration(parser)
+    db_plugin.declare_configuration(parser)
+    parser.add_option("-m", "--general.mode", default='dumphtml', choices=['dumphtml'],
+                         help="'dumphtml' - prints html code with code highlights for each given path [default: %default]")
+
+    (options, args) = parser.parse_args()
+    log_plugin.configure(options)
+    db_plugin.configure(options)
+
+    loader = core.db.loader.Loader()
+    loader.open_database(db_plugin.dbfile)
+
+    if options.__dict__['general.mode'] == 'dumphtml':
+        return dumphtml(args, loader)
+    
+    assert(False)    
+    
+def dumphtml(args, loader):
+    exit_code = 0
+    result = ""
+    result += '<html><body>'
+    for path in args:
+        data = loader.load_file_data(path)
+        if data == None:
+            logging.error("Specified path '" + path + "' is invalid (not found in the database records)")
+            exit_code += 1
+            continue
+        
+        file_name = data.get_path()
+        fh = open(file_name, 'r')
+        if fh == None:
+            logging.error("can not open file '" + path + "' for reading")
+            exit_code += 1
+            continue
+        text = fh.read()
+        fh.close()
+        
+        result += '<table><tr><td><pre>'
+        last_pos = 0
+        for marker in data.iterate_markers():
+            result += (cgi.escape(text[last_pos:marker.begin]))
+            if marker.get_type() == data.get_marker_types().STRING:
+                result += ('<span style="color:#0000FF">')
+            elif marker.get_type() == data.get_marker_types().COMMENT:
+                result += ('<span style="color:#009900">')
+            elif marker.get_type() == data.get_marker_types().PREPROCESSOR:
+                result += ('<span style="color:#990000">')
+            result += (cgi.escape(text[marker.begin:marker.end]))
+            result += ('</span>')
+            last_pos = marker.end
+        result += (cgi.escape(text[last_pos:]))
+        last_pos = 0
+        result += ('</pre></td><td><pre>')
+        styles = ['<span style="background-color:#ffff80">', '<span style="background-color:#ff80ff">']
+        for item in enumerate(data.iterate_regions(filter_group=data.get_region_types().FUNCTION)):
+            reg = item[1]
+            result += (cgi.escape(text[last_pos:reg.get_offset_begin()]))
+            result += (styles[item[0] % 2])
+            result += ('<a href="#line' + str(reg.get_cursor()) + '" id=line"' + str(reg.get_cursor()) + '"></a>')
+            result += (cgi.escape(text[reg.get_offset_begin():reg.get_offset_end()]))
+            result += ('</span>')
+            last_pos = reg.get_offset_end()
+        result += (cgi.escape(text[last_pos:]))
+        result += ('</pre></td></tr></table>')
+    result += ('</body></html>')
+    print result
+    return exit_code
+            
+if __name__ == '__main__':
+    ts = time.time()
+    core.log.set_default_format()
+    exit_code = main()
+    logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
+    exit(exit_code) # number of reported messages, errors are reported as non-handled exceptions

+ 9 - 12
mainline/doc/project.html

@@ -483,23 +483,20 @@ along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
 
                 <p>Parser for C/C++ language can serve as <a
                 href="http://metrixplusplus.svn.sourceforge.net/viewvc/metrixplusplus/mainline/ext/std/code/cpp.py">an
-                example</a>. There useful options are avaialble for
+                example</a>. There useful options and tools are avaialble for
                 trobuleshooting purposes during development:</p>
                 <ul>
+                  <li><span class="normalImportance">debug.py tool</span> is
+                    helpful troubleshooting tool. In mode 'dumphtml' it
+                    generates html code showing code highlightings</li>
                   <li><span
-                    class="normalImportance">--std.code.dumper.on</span> If the
-                    option is set (True), HTML files are generated for every
-                    parsed file with code showing identified markers and
-                    regions (functions only) [default: False]</li>
-                  <li><span class="normalImportance">--std.code.test.on</span>
-                    Enables test plugin. Currently dumps to stdout structure of
-                    the code (tree of namespaces, classes and functions
-                    identified) after processing by a parser (for development
-                    purposes) [default: False]</li>
+                    class="normalImportance">--general.nest-regions</span> for
+                    export tool forces exporting of code structure in tree
+                    format. It can be helpful for analysis of parser's
+                  internals</li>
                   <li><span
                     class="normalImportance">--general.log-level</span>=GENERAL.LOG_LEVEL
-                    Defines log level. Possible values are
-                    'DEBUG','INFO','WARNING' or 'ERROR' [default: INFO]</li>
+                    for any tool is helpful to trace execution </li>
                 </ul>
 
                 <p>Finally, if there are any questions or enquires, please,

+ 0 - 26
mainline/ext/std/code/dumper.ini

@@ -1,26 +0,0 @@
-;
-;    Metrix++, Copyright 2009-2013, Metrix++ Project
-;    Link: http://metrixplusplus.sourceforge.net
-;    
-;    This file is a part of Metrix++ Tool.
-;    
-;    Metrix++ is free software: you can redistribute it and/or modify
-;    it under the terms of the GNU General Public License as published by
-;    the Free Software Foundation, version 3 of the License.
-;    
-;    Metrix++ is distributed in the hope that it will be useful,
-;    but WITHOUT ANY WARRANTY; without even the implied warranty of
-;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;    GNU General Public License for more details.
-;    
-;    You should have received a copy of the GNU General Public License
-;    along with Metrix++.  If not, see <http://www.gnu.org/licenses/>.
-;
-
-[Plugin]
-version: 1.0
-package: std.code
-module:  dumper
-class:   Plugin
-depends: None
-enabled: True

+ 0 - 76
mainline/ext/std/code/dumper.py

@@ -1,76 +0,0 @@
-#
-#    Metrix++, Copyright 2009-2013, Metrix++ Project
-#    Link: http://metrixplusplus.sourceforge.net
-#    
-#    This file is a part of Metrix++ Tool.
-#    
-#    Metrix++ is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, version 3 of the License.
-#    
-#    Metrix++ is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#    GNU General Public License for more details.
-#    
-#    You should have received a copy of the GNU General Public License
-#    along with Metrix++.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-import core.api
-
-import re
-
-class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
-    
-    POST_NAME = '.ss.std.code.dumper.html'
-    
-    def declare_configuration(self, parser):
-        parser.add_option("--std.code.dumper.on", action="store_true", default=False,
-                         help="If the option is set (True), HTML files are generated for every parsed file containing code (for troubleshooting purposes only) [default: %default]")
-    
-    def configure(self, options):
-        self.dump_html = options.__dict__['std.code.dumper.on']
-        
-    def initialize(self):
-        if self.dump_html == True:
-            core.api.subscribe_by_parents_interface(core.api.ICode, self)
-        
-        # do not process files dumped by previous run of this module    
-        self.get_plugin_loader().get_plugin('core.dir').add_exclude_rule(re.compile(r'.*' + Plugin.POST_NAME + r'$'))
-        
-    def callback(self, parent, data, is_updated):
-        file_name = data.get_path()
-        text = data.get_content()
-        
-        import cgi
-        f = open(file_name + Plugin.POST_NAME, 'w')
-        f.write('<html><body><table><tr><td><pre>')
-        last_pos = 0
-        for marker in data.iterate_markers():
-            f.write(cgi.escape(text[last_pos:marker.begin]))
-            if marker.get_type() == data.get_marker_types().STRING:
-                f.write('<span style="color:#0000FF">')
-            elif marker.get_type() == data.get_marker_types().COMMENT:
-                f.write('<span style="color:#009900">')
-            elif marker.get_type() == data.get_marker_types().PREPROCESSOR:
-                f.write('<span style="color:#990000">')
-            f.write(cgi.escape(text[marker.begin:marker.end]))
-            f.write('</span>')
-            last_pos = marker.end
-        f.write(cgi.escape(text[last_pos:]))
-        last_pos = 0
-        f.write('</pre></td><td><pre>')
-        styles = ['<span style="background-color:#ffff80">', '<span style="background-color:#ff80ff">']
-        for item in enumerate(data.iterate_regions(filter_group=data.get_region_types().FUNCTION)):
-            reg = item[1]
-            f.write(cgi.escape(text[last_pos:reg.get_offset_begin()]))
-            f.write(styles[item[0] % 2])
-            f.write('<a href="#line' + str(reg.get_cursor()) + '" id=line"' + str(reg.get_cursor()) + '"></a>')
-            f.write(cgi.escape(text[reg.get_offset_begin():reg.get_offset_end()]))
-            f.write('</span>')
-            last_pos = reg.get_offset_end()
-        f.write(cgi.escape(text[last_pos:]))
-        f.write('</pre></td></tr></table></body></html>')
-        f.close()
-

+ 0 - 3
mainline/tests/general/test_basic/test_help_collect_default_stdout.gold.txt

@@ -36,6 +36,3 @@ Options:
   --std.code.cs.files=STD.CODE.CS.FILES
                         Enumerates filename extensions to match C/C++ files
                         [default: *.cs]
-  --std.code.dumper.on  If the option is set (True), HTML files are generated
-                        for every parsed file containing code (for
-                        troubleshooting purposes only) [default: False]

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_export_second_per_file_stderr.gold.txt

@@ -1,3 +1,3 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: ./simple.cpp
-[LOG]: WARNING:	Exit code: 0. Time spent: 0.02 seconds. Done
+[LOG]: WARNING:	Exit code: 0. Time spent: 0.01 seconds. Done

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_info_default_stderr.gold.txt

@@ -1,2 +1,2 @@
 [LOG]: WARNING:	Logging enabled with INFO level
-[LOG]: WARNING:	Exit code: 0. Time spent: 0.01 seconds. Done
+[LOG]: WARNING:	Exit code: 0. Time spent: 0.0 seconds. Done

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_default_stderr.gold.txt

@@ -1,4 +1,4 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: 
 [LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
-[LOG]: WARNING:	Exit code: 4. Time spent: 0.0 seconds. Done
+[LOG]: WARNING:	Exit code: 4. Time spent: 0.01 seconds. Done