todo.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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,
  22. mpp.api.IConfigurable,
  23. mpp.api.Child,
  24. mpp.api.MetricPluginMixin):
  25. def declare_configuration(self, parser):
  26. self.parser = parser
  27. parser.add_option("--std.code.todo.comments", "--sctc",
  28. action="store_true", default=False,
  29. help="Enables collection of number of todo/fixme/etc markers in comments [default: %default]")
  30. parser.add_option("--std.code.todo.strings", "--scts",
  31. action="store_true", default=False,
  32. help="Enables collection of number of todo/fixme/etc markers in strings [default: %default]")
  33. parser.add_option("--std.code.todo.tags", "--sctt", type=str,
  34. default="TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX",
  35. help="A list of typical todo markers to search, separated by comma [default: %default]")
  36. def configure(self, options):
  37. self.is_active_comments = options.__dict__['std.code.todo.comments']
  38. self.is_active_strings = options.__dict__['std.code.todo.strings']
  39. self.tags_list = options.__dict__['std.code.todo.tags'].split(',')
  40. self.tags_list.sort()
  41. for tag in self.tags_list:
  42. if re.match(r'''^[A-Za-z0-9]+$''', tag) == None:
  43. self.parser.error('option --std.code.todo.tags: tag {0} includes not allowed symbols'.
  44. format(tag))
  45. self.pattern_to_search = re.compile('([^a-zA-Z]({0})(?=[^a-zA-Z]))|([^a-zA-Z]({0})$)'.format('|'.join(self.tags_list)))
  46. def initialize(self):
  47. self.declare_metric(self.is_active_comments,
  48. self.Field('comments', int, non_zero=True),
  49. self.pattern_to_search,
  50. marker_type_mask=mpp.api.Marker.T.COMMENT,
  51. region_type_mask=mpp.api.Region.T.ANY)
  52. self.declare_metric(self.is_active_strings,
  53. self.Field('strings', int, non_zero=True),
  54. self.pattern_to_search,
  55. marker_type_mask=mpp.api.Marker.T.STRING,
  56. region_type_mask=mpp.api.Region.T.ANY)
  57. super(Plugin, self).initialize(fields=self.get_fields(),
  58. properties=[self.Property('tags', ','.join(self.tags_list))])
  59. if self.is_active() == True:
  60. self.subscribe_by_parents_interface(mpp.api.ICode)