magic.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. class Plugin(mpp.api.Plugin,
  21. mpp.api.IConfigurable,
  22. # declare that it can subscribe on notifications
  23. mpp.api.Child):
  24. def declare_configuration(self, parser):
  25. parser.add_option("--myext.magic.numbers", "--mmn",
  26. action="store_true", default=False,
  27. help="Enables collection of magic numbers metric [default: %default]")
  28. def configure(self, options):
  29. self.is_active_numbers = options.__dict__['myext.magic.numbers']
  30. def initialize(self):
  31. if self.is_active_numbers == True:
  32. # subscribe to notifications from all code parsers
  33. self.subscribe_by_parents_interface(mpp.api.ICode, 'callback')
  34. # parents (code parsers) will call the callback declared
  35. def callback(self, parent, data, is_updated):
  36. print parent.get_name(), data.get_path(), is_updated