lines.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import mpp.api
  20. import re
  21. class Plugin(mpp.api.Plugin, mpp.api.MetricPluginMixin, mpp.api.Child, mpp.api.IConfigurable):
  22. def declare_configuration(self, parser):
  23. parser.add_option("--std.code.lines.code", "--sclc", action="store_true", default=False,
  24. help="Enables collection of lines of code metric (per region detalization) - "
  25. "number of non-empty lines of code, excluding comments "
  26. "[default: %default]")
  27. parser.add_option("--std.code.lines.preprocessor", "--sclp", action="store_true", default=False,
  28. help="Enables collection of lines of preprocessor code metric (per region detalization) - "
  29. "number of non-empty lines of preprocessor code "
  30. "[default: %default]")
  31. parser.add_option("--std.code.lines.comments", "--sclcom", action="store_true", default=False,
  32. help="Enables collection of lines of comments metric (per region detalization) - "
  33. "number of non-empty lines of comments "
  34. "[default: %default]")
  35. parser.add_option("--std.code.lines.total", "--sclt", action="store_true", default=False,
  36. help="Enables collection of total lines metric (per region detalization) - "
  37. "number of any type of lines (blank, code, comments, etc.)"
  38. "[default: %default]")
  39. def configure(self, options):
  40. self.is_active_code = options.__dict__['std.code.lines.code']
  41. self.is_active_preprocessor = options.__dict__['std.code.lines.preprocessor']
  42. self.is_active_comments = options.__dict__['std.code.lines.comments']
  43. self.is_active_total = options.__dict__['std.code.lines.total']
  44. pattern_line = re.compile(r'''[^\s].*''')
  45. def initialize(self):
  46. self.declare_metric(self.is_active_code,
  47. self.Field('code', int),
  48. self.pattern_line,
  49. mpp.api.Marker.T.CODE | mpp.api.Marker.T.STRING,
  50. merge_markers=True)
  51. self.declare_metric(self.is_active_preprocessor,
  52. self.Field('preprocessor', int),
  53. self.pattern_line,
  54. mpp.api.Marker.T.PREPROCESSOR)
  55. self.declare_metric(self.is_active_comments,
  56. self.Field('comments', int),
  57. self.pattern_line,
  58. mpp.api.Marker.T.COMMENT)
  59. self.declare_metric(self.is_active_total,
  60. self.Field('total', int),
  61. self.pattern_line,
  62. mpp.api.Marker.T.ANY,
  63. merge_markers=True)
  64. super(Plugin, self).initialize(fields=self.get_fields())
  65. if self.is_active() == True:
  66. self.subscribe_by_parents_interface(mpp.api.ICode)