1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #
- # Metrix++, Copyright 2009-2019, Metrix++ Project
- # Link: https://github.com/metrixplusplus/metrixplusplus
- #
- # This file is a part of Metrix++ Tool.
- #
- import mpp.api
- import re
- class Plugin(mpp.api.Plugin, mpp.api.MetricPluginMixin, mpp.api.Child, mpp.api.IConfigurable):
-
- def declare_configuration(self, parser):
- parser.add_option("--std.code.filelines.code", "--scflc", action="store_true", default=False,
- help="Enables collection of lines of code metric (per file detalization) - "
- "number of non-empty lines of code, excluding comments "
- "[default: %default]")
- parser.add_option("--std.code.filelines.preprocessor", "--scflp", action="store_true", default=False,
- help="Enables collection of lines of preprocessor code metric (per file detalization) - "
- "number of non-empty lines of preprocessor code "
- "[default: %default]")
- parser.add_option("--std.code.filelines.comments", "--scflcom", action="store_true", default=False,
- help="Enables collection of lines of comments metric (per file detalization) - "
- "number of non-empty lines of comments "
- "[default: %default]")
- parser.add_option("--std.code.filelines.total", "--scflt", action="store_true", default=False,
- help="Enables collection of total lines metric (per file detalization) - "
- "number of any type of lines (blank, code, comments, etc.)"
- "[default: %default]")
-
- def configure(self, options):
- self.is_active_code = options.__dict__['std.code.filelines.code']
- self.is_active_preprocessor = options.__dict__['std.code.filelines.preprocessor']
- self.is_active_comments = options.__dict__['std.code.filelines.comments']
- self.is_active_total = options.__dict__['std.code.filelines.total']
-
- pattern_line = re.compile(r'''[^\s].*''')
- def initialize(self):
- self.declare_metric(self.is_active_code,
- self.Field('code', int),
- self.pattern_line,
- mpp.api.Marker.T.CODE | mpp.api.Marker.T.STRING,
- merge_markers=True)
- self.declare_metric(self.is_active_preprocessor,
- self.Field('preprocessor', int),
- self.pattern_line,
- mpp.api.Marker.T.PREPROCESSOR)
- self.declare_metric(self.is_active_comments,
- self.Field('comments', int),
- self.pattern_line,
- mpp.api.Marker.T.COMMENT)
- self.declare_metric(self.is_active_total,
- self.Field('total', int),
- self.pattern_line,
- mpp.api.Marker.T.ANY,
- merge_markers=True)
- super(Plugin, self).initialize(fields=self.get_fields(), support_regions=False)
- if self.is_active() == True:
- self.subscribe_by_parents_interface(mpp.api.ICode)
|