filelines.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Metrix++, Copyright 2009-2019, Metrix++ Project
  3. # Link: https://github.com/metrixplusplus/metrixplusplus
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. import mpp.api
  8. import re
  9. class Plugin(mpp.api.Plugin, mpp.api.MetricPluginMixin, mpp.api.Child, mpp.api.IConfigurable):
  10. def declare_configuration(self, parser):
  11. parser.add_option("--std.code.filelines.code", "--scflc", action="store_true", default=False,
  12. help="Enables collection of lines of code metric (per file detalization) - "
  13. "number of non-empty lines of code, excluding comments "
  14. "[default: %default]")
  15. parser.add_option("--std.code.filelines.preprocessor", "--scflp", action="store_true", default=False,
  16. help="Enables collection of lines of preprocessor code metric (per file detalization) - "
  17. "number of non-empty lines of preprocessor code "
  18. "[default: %default]")
  19. parser.add_option("--std.code.filelines.comments", "--scflcom", action="store_true", default=False,
  20. help="Enables collection of lines of comments metric (per file detalization) - "
  21. "number of non-empty lines of comments "
  22. "[default: %default]")
  23. parser.add_option("--std.code.filelines.total", "--scflt", action="store_true", default=False,
  24. help="Enables collection of total lines metric (per file detalization) - "
  25. "number of any type of lines (blank, code, comments, etc.)"
  26. "[default: %default]")
  27. def configure(self, options):
  28. self.is_active_code = options.__dict__['std.code.filelines.code']
  29. self.is_active_preprocessor = options.__dict__['std.code.filelines.preprocessor']
  30. self.is_active_comments = options.__dict__['std.code.filelines.comments']
  31. self.is_active_total = options.__dict__['std.code.filelines.total']
  32. pattern_line = re.compile(r'''[^\s].*''')
  33. def initialize(self):
  34. self.declare_metric(self.is_active_code,
  35. self.Field('code', int),
  36. self.pattern_line,
  37. mpp.api.Marker.T.CODE | mpp.api.Marker.T.STRING,
  38. merge_markers=True)
  39. self.declare_metric(self.is_active_preprocessor,
  40. self.Field('preprocessor', int),
  41. self.pattern_line,
  42. mpp.api.Marker.T.PREPROCESSOR)
  43. self.declare_metric(self.is_active_comments,
  44. self.Field('comments', int),
  45. self.pattern_line,
  46. mpp.api.Marker.T.COMMENT)
  47. self.declare_metric(self.is_active_total,
  48. self.Field('total', int),
  49. self.pattern_line,
  50. mpp.api.Marker.T.ANY,
  51. merge_markers=True)
  52. super(Plugin, self).initialize(fields=self.get_fields(), support_regions=False)
  53. if self.is_active() == True:
  54. self.subscribe_by_parents_interface(mpp.api.ICode)