info.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.db.post
  21. import mpp.log
  22. import mpp.cmdparser
  23. import mpp.utils
  24. class Tool(mpp.api.ITool):
  25. def run(self, tool_args):
  26. return main(tool_args)
  27. def main(tool_args):
  28. exit_code = 0
  29. log_plugin = mpp.log.Plugin()
  30. db_plugin = mpp.db.post.Plugin()
  31. parser = mpp.cmdparser.MultiOptionParser(usage="Usage: %prog info [options] -- [path 1] ... [path N]")
  32. log_plugin.declare_configuration(parser)
  33. db_plugin.declare_configuration(parser)
  34. (options, args) = parser.parse_args(tool_args)
  35. log_plugin.configure(options)
  36. db_plugin.configure(options)
  37. log_plugin.initialize()
  38. db_plugin.initialize()
  39. loader_prev = db_plugin.get_loader_prev(none_if_empty=True)
  40. loader = db_plugin.get_loader()
  41. print "Properties:"
  42. for each in loader.iterate_properties():
  43. prev_value_str = ""
  44. if loader_prev != None:
  45. prev = loader_prev.get_property(each.name)
  46. if prev == None:
  47. prev_value_str = " [new]"
  48. print "(!)",
  49. elif prev != each.value:
  50. prev_value_str = " [modified (was: " + loader_prev.get_property(each.name) + ")]"
  51. print "(!)",
  52. print "\t" + each.name + "\t=>\t" + each.value + prev_value_str
  53. print "\nMetrics:"
  54. for each in sorted(loader.iterate_namespace_names()):
  55. for field in sorted(loader.get_namespace(each).iterate_field_names()):
  56. prev_value_str = ""
  57. if loader_prev != None:
  58. prev = None
  59. prev_namespace = loader_prev.get_namespace(each)
  60. if prev_namespace != None:
  61. prev = prev_namespace.get_field_packager(field)
  62. if prev == None:
  63. prev_value_str = " [new]"
  64. print "(!)",
  65. print "\t" + each + ":" + field + prev_value_str
  66. print "\nFiles:"
  67. paths = None
  68. if len(args) == 0:
  69. paths = [""]
  70. else:
  71. paths = args
  72. for path in paths:
  73. path = mpp.utils.preprocess_path(path)
  74. file_iterator = loader.iterate_file_data(path=path)
  75. if file_iterator == None:
  76. mpp.utils.report_bad_path(path)
  77. exit_code += 1
  78. continue
  79. for each in file_iterator:
  80. prev_value_str = ""
  81. if loader_prev != None:
  82. prev = loader_prev.load_file_data(each.get_path())
  83. if prev == None:
  84. prev_value_str = " [new]"
  85. print "(!)",
  86. elif prev.get_checksum() != each.get_checksum():
  87. prev_value_str = " [modified]"
  88. print "(!)",
  89. print "\t" + each.get_path() + prev_value_str
  90. return exit_code