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 logging
  20. import core.db.loader
  21. import core.db.post
  22. import core.log
  23. import core.cmdparser
  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 "Namespaces:"
  57. for each in loader.iterate_namespace_names():
  58. prev_value_str = ""
  59. if loader_prev != None:
  60. prev = loader_prev.get_namespace(each)
  61. if prev == None:
  62. prev_value_str = " [new]"
  63. print "(!)",
  64. print "\t" + each + prev_value_str
  65. for field in loader.get_namespace(each).iterate_field_names():
  66. prev_value_str = ""
  67. if loader_prev != None:
  68. prev = loader_prev.get_namespace(each).get_field_packager(field)
  69. if prev == None:
  70. prev_value_str = " [new]"
  71. print "(!)",
  72. print "\t\t- " + field + prev_value_str
  73. print "Files:"
  74. paths = None
  75. if len(args) == 0:
  76. paths = [""]
  77. else:
  78. paths = args
  79. for path in paths:
  80. file_iterator = loader.iterate_file_data(path=path)
  81. if file_iterator == None:
  82. logging.error("Specified path '" + path + "' is invalid (not found in the database records)")
  83. exit_code += 1
  84. continue
  85. for each in file_iterator:
  86. prev_value_str = ""
  87. if loader_prev != None:
  88. prev = loader_prev.load_file_data(each.get_path())
  89. if prev == None:
  90. prev_value_str = " [new]"
  91. print "(!)",
  92. elif prev.get_checksum() != each.get_checksum():
  93. prev_value_str = " [modified]"
  94. print "(!)",
  95. print "\t" + each.get_path() + prev_value_str
  96. return exit_code