todo.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(
  46. r'\b({0})\b'.
  47. format('|'.join(self.tags_list)))
  48. def initialize(self):
  49. self.declare_metric(self.is_active_comments,
  50. self.Field('comments', int, non_zero=True),
  51. self.pattern_to_search,
  52. marker_type_mask=mpp.api.Marker.T.COMMENT,
  53. region_type_mask=mpp.api.Region.T.ANY)
  54. self.declare_metric(self.is_active_strings,
  55. self.Field('strings', int, non_zero=True),
  56. self.pattern_to_search,
  57. marker_type_mask=mpp.api.Marker.T.STRING,
  58. region_type_mask=mpp.api.Region.T.ANY)
  59. super(Plugin, self).initialize(fields=self.get_fields(),
  60. properties=[self.Property('tags', ','.join(self.tags_list))])
  61. if self.is_active() == True:
  62. self.subscribe_by_parents_interface(mpp.api.ICode)