info.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 mpp.cout
  21. import mpp.utils
  22. class Plugin(mpp.api.Plugin, mpp.api.IRunable):
  23. def run(self, args):
  24. exit_code = 0
  25. loader_prev = self.get_plugin_loader().get_plugin('mpp.dbf').get_loader_prev(none_if_empty=True)
  26. loader = self.get_plugin_loader().get_plugin('mpp.dbf').get_loader()
  27. details = []
  28. for each in loader.iterate_properties():
  29. prev_value_str = ""
  30. if loader_prev != None:
  31. prev = loader_prev.get_property(each.name)
  32. if prev == None:
  33. prev_value_str = " [new]"
  34. elif prev != each.value:
  35. prev_value_str = " [modified (was: " + loader_prev.get_property(each.name) + ")]"
  36. details.append((each.name, each.value + prev_value_str))
  37. path = self.get_plugin_loader().get_plugin('mpp.dbf').get_dbfile_path()
  38. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Created using plugins and settings:', details)
  39. details = []
  40. for each in sorted(loader.iterate_namespace_names()):
  41. for field in sorted(loader.get_namespace(each).iterate_field_names()):
  42. prev_value_str = ""
  43. if loader_prev != None:
  44. prev = None
  45. prev_namespace = loader_prev.get_namespace(each)
  46. if prev_namespace != None:
  47. prev = prev_namespace.get_field_packager(field)
  48. if prev == None:
  49. prev_value_str = " [new]"
  50. details.append((each + ':' + field, prev_value_str))
  51. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Collected metrics:', details)
  52. paths = None
  53. if len(args) == 0:
  54. paths = [""]
  55. else:
  56. paths = args
  57. for path in paths:
  58. details = []
  59. path = mpp.utils.preprocess_path(path)
  60. file_iterator = loader.iterate_file_data(path=path)
  61. if file_iterator == None:
  62. mpp.utils.report_bad_path(path)
  63. exit_code += 1
  64. continue
  65. for each in file_iterator:
  66. prev_value_str = ""
  67. if loader_prev != None:
  68. prev = loader_prev.load_file_data(each.get_path())
  69. if prev == None:
  70. prev_value_str = " [new]"
  71. elif prev.get_checksum() != each.get_checksum():
  72. prev_value_str = " [modified]"
  73. details.append((each.get_path(), '{0:#x}'.format(each.get_checksum()) + prev_value_str))
  74. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Processed files and checksums:', details)
  75. return exit_code