info.py 3.9 KB

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