info.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 time
  21. import core.db.loader
  22. import core.db.post
  23. import core.log
  24. import core.cmdparser
  25. def main():
  26. exit_code = 0
  27. log_plugin = core.log.Plugin()
  28. db_plugin = core.db.post.Plugin()
  29. parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [path 1] ... [path N]")
  30. log_plugin.declare_configuration(parser)
  31. db_plugin.declare_configuration(parser)
  32. (options, args) = parser.parse_args()
  33. log_plugin.configure(options)
  34. db_plugin.configure(options)
  35. loader = core.db.loader.Loader()
  36. loader.open_database(db_plugin.dbfile)
  37. loader_prev = None
  38. if db_plugin.dbfile_prev != None:
  39. loader_prev = core.db.loader.Loader()
  40. loader_prev.open_database(db_plugin.dbfile_prev)
  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 "Namespaces:"
  54. for each in loader.iterate_namespace_names():
  55. prev_value_str = ""
  56. if loader_prev != None:
  57. prev = loader_prev.get_namespace(each)
  58. if prev == None:
  59. prev_value_str = " [new]"
  60. print "(!)",
  61. print "\t" + each + prev_value_str
  62. for field in loader.get_namespace(each).iterate_field_names():
  63. prev_value_str = ""
  64. if loader_prev != None:
  65. prev = loader_prev.get_namespace(each).get_field_packager(field)
  66. if prev == None:
  67. prev_value_str = " [new]"
  68. print "(!)",
  69. print "\t\t- " + field + prev_value_str
  70. print "Files:"
  71. paths = None
  72. if len(args) == 0:
  73. paths = [""]
  74. else:
  75. paths = args
  76. for path in paths:
  77. file_iterator = loader.iterate_file_data(path=path)
  78. if file_iterator == None:
  79. logging.error("Specified path '" + path + "' is invalid (not found in the database records)")
  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
  94. if __name__ == '__main__':
  95. ts = time.time()
  96. core.log.set_default_format()
  97. exit_code = main()
  98. logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
  99. exit(exit_code) # number of reported messages, errors are reported as non-handled exceptions