info.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.api
  20. import core.db.post
  21. import core.log
  22. import core.cmdparser
  23. import core.utils
  24. class Tool(core.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 = core.log.Plugin()
  30. db_plugin = core.db.post.Plugin()
  31. parser = core.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. loader = core.api.Loader()
  38. if loader.open_database(db_plugin.dbfile) == False:
  39. parser.error("Can not open file: " + db_plugin.dbfile)
  40. loader_prev = None
  41. if db_plugin.dbfile_prev != None:
  42. loader_prev = core.api.Loader()
  43. if loader_prev.open_database(db_plugin.dbfile_prev) == False:
  44. parser.error("Can not open file: " + db_plugin.dbfile_prev)
  45. print "Properties:"
  46. for each in loader.iterate_properties():
  47. prev_value_str = ""
  48. if loader_prev != None:
  49. prev = loader_prev.get_property(each.name)
  50. if prev == None:
  51. prev_value_str = " [new]"
  52. print "(!)",
  53. elif prev != each.value:
  54. prev_value_str = " [modified (was: " + loader_prev.get_property(each.name) + ")]"
  55. print "(!)",
  56. print "\t" + each.name + "\t=>\t" + each.value + prev_value_str
  57. print "\nMetrics:"
  58. for each in sorted(loader.iterate_namespace_names()):
  59. for field in sorted(loader.get_namespace(each).iterate_field_names()):
  60. prev_value_str = ""
  61. if loader_prev != None:
  62. prev = None
  63. prev_namespace = loader_prev.get_namespace(each)
  64. if prev_namespace != None:
  65. prev = prev_namespace.get_field_packager(field)
  66. if prev == None:
  67. prev_value_str = " [new]"
  68. print "(!)",
  69. print "\t" + each + ":" + field + prev_value_str
  70. print "\nFiles:"
  71. paths = None
  72. if len(args) == 0:
  73. paths = [""]
  74. else:
  75. paths = args
  76. for path in paths:
  77. path = core.utils.preprocess_path(path)
  78. file_iterator = loader.iterate_file_data(path=path)
  79. if file_iterator == None:
  80. core.utils.report_bad_path(path)
  81. exit_code += 1
  82. continue
  83. for each in file_iterator:
  84. prev_value_str = ""
  85. if loader_prev != None:
  86. prev = loader_prev.load_file_data(each.get_path())
  87. if prev == None:
  88. prev_value_str = " [new]"
  89. print "(!)",
  90. elif prev.get_checksum() != each.get_checksum():
  91. prev_value_str = " [modified]"
  92. print "(!)",
  93. print "\t" + each.get_path() + prev_value_str
  94. return exit_code