info.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. import mpp.cout
  9. import mpp.utils
  10. import os
  11. class Plugin(mpp.api.Plugin, mpp.api.IRunable):
  12. def run(self, args):
  13. exit_code = 0
  14. loader_prev = self.get_plugin('mpp.dbf').get_loader_prev(none_if_empty=True)
  15. loader = self.get_plugin('mpp.dbf').get_loader()
  16. details = []
  17. for each in loader.iterate_properties():
  18. prev_value_str = ""
  19. if loader_prev != None:
  20. prev = loader_prev.get_property(each.name)
  21. if prev == None:
  22. prev_value_str = " [new]"
  23. elif prev != each.value:
  24. prev_value_str = " [modified (was: " + loader_prev.get_property(each.name) + ")]"
  25. details.append((each.name, each.value + prev_value_str))
  26. path = self.get_plugin('mpp.dbf').get_dbfile_path()
  27. if ('METRIXPLUSPLUS_TEST_MODE' in list(os.environ.keys()) and
  28. os.environ['METRIXPLUSPLUS_TEST_MODE'] == "True"):
  29. # in tests, paths come as full paths, strip it for consistent gold files
  30. # TODO: if there are other path-like arguments, it is better to think about other solution
  31. path = os.path.basename(path)
  32. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Created using plugins and settings:', details)
  33. details = []
  34. for each in sorted(loader.iterate_namespace_names()):
  35. for field in sorted(loader.get_namespace(each).iterate_field_names()):
  36. prev_value_str = ""
  37. if loader_prev != None:
  38. prev = False
  39. prev_namespace = loader_prev.get_namespace(each)
  40. if prev_namespace != None:
  41. prev = prev_namespace.check_field(field)
  42. if prev == False:
  43. prev_value_str = " [new]"
  44. details.append((each + ':' + field, prev_value_str))
  45. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Collected metrics:', details)
  46. paths = None
  47. if len(args) == 0:
  48. paths = [""]
  49. else:
  50. paths = args
  51. for path in paths:
  52. details = []
  53. path = mpp.utils.preprocess_path(path)
  54. file_iterator = loader.iterate_file_data(path=path)
  55. if file_iterator == None:
  56. mpp.utils.report_bad_path(path)
  57. exit_code += 1
  58. continue
  59. for each in file_iterator:
  60. prev_value_str = ""
  61. if loader_prev != None:
  62. prev = loader_prev.load_file_data(each.get_path())
  63. if prev == None:
  64. prev_value_str = " [new]"
  65. elif prev.get_checksum() != each.get_checksum():
  66. prev_value_str = " [modified]"
  67. details.append((each.get_path(), '{0:#x}'.format(each.get_checksum()) + prev_value_str))
  68. mpp.cout.notify(path, '', mpp.cout.SEVERITY_INFO, 'Processed files and checksums:', details)
  69. return exit_code