# # Metrix++, Copyright 2009-2013, Metrix++ Project # Link: http://swi.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 . # 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): file_name = data.get_path() text = data.get_content() import cgi f = open(file_name + Plugin.POST_NAME, 'w') f.write('
')
        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('')
            elif marker.get_type() == data.get_marker_types().COMMENT:
                f.write('')
            elif marker.get_type() == data.get_marker_types().PREPROCESSOR:
                f.write('')
            f.write(cgi.escape(text[marker.begin:marker.end]))
            f.write('')
            last_pos = marker.end
        f.write(cgi.escape(text[last_pos:]))
        last_pos = 0
        f.write('
')
        styles = ['', '']
        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('')
            f.write(cgi.escape(text[reg.get_offset_begin():reg.get_offset_end()]))
            f.write('')
            last_pos = reg.get_offset_end()
        f.write(cgi.escape(text[last_pos:]))
        f.write('
') f.close()