info.py 3.7 KB

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