magic.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  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. class Plugin(mpp.api.Plugin,
  9. mpp.api.IConfigurable,
  10. # declare that it can subscribe on notifications
  11. mpp.api.Child):
  12. def declare_configuration(self, parser):
  13. parser.add_option("--myext.magic.numbers", "--mmn",
  14. action="store_true", default=False,
  15. help="Enables collection of magic numbers metric [default: %default]")
  16. def configure(self, options):
  17. self.is_active_numbers = options.__dict__['myext.magic.numbers']
  18. def initialize(self):
  19. if self.is_active_numbers == True:
  20. # subscribe to notifications from all code parsers
  21. self.subscribe_by_parents_interface(mpp.api.ICode, 'callback')
  22. # parents (code parsers) will call the callback declared
  23. def callback(self, parent, data, is_updated):
  24. print("{0} {1} {2}".format(parent.get_name(), data.get_path(), is_updated))