| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 """ | 2 """ |
| 3 Program that calculates several hashes for a given CD image. | 3 Program that calculates several hashes for a given CD image. |
| 4 | 4 |
| 5 @copyright: Red Hat 2008-2009 | 5 @copyright: Red Hat 2008-2009 |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 import os, sys, optparse, logging | 8 import os, sys, optparse, logging |
| 9 import common | 9 import common |
| 10 import kvm_utils | |
| 11 from autotest_lib.client.common_lib import logging_manager | 10 from autotest_lib.client.common_lib import logging_manager |
| 12 from autotest_lib.client.bin import utils | 11 from autotest_lib.client.bin import utils |
| 12 from autotest_lib.client.virt import virt_utils |
| 13 | 13 |
| 14 | 14 |
| 15 if __name__ == "__main__": | 15 if __name__ == "__main__": |
| 16 parser = optparse.OptionParser("usage: %prog [options] [filenames]") | 16 parser = optparse.OptionParser("usage: %prog [options] [filenames]") |
| 17 options, args = parser.parse_args() | 17 options, args = parser.parse_args() |
| 18 | 18 |
| 19 logging_manager.configure_logging(kvm_utils.KvmLoggingConfig()) | 19 logging_manager.configure_logging(virt_utils.KvmLoggingConfig()) |
| 20 | 20 |
| 21 if args: | 21 if args: |
| 22 filenames = args | 22 filenames = args |
| 23 else: | 23 else: |
| 24 parser.print_help() | 24 parser.print_help() |
| 25 sys.exit(1) | 25 sys.exit(1) |
| 26 | 26 |
| 27 for filename in filenames: | 27 for filename in filenames: |
| 28 filename = os.path.abspath(filename) | 28 filename = os.path.abspath(filename) |
| 29 | 29 |
| 30 file_exists = os.path.isfile(filename) | 30 file_exists = os.path.isfile(filename) |
| 31 can_read_file = os.access(filename, os.R_OK) | 31 can_read_file = os.access(filename, os.R_OK) |
| 32 if not file_exists: | 32 if not file_exists: |
| 33 logging.critical("File %s does not exist!", filename) | 33 logging.critical("File %s does not exist!", filename) |
| 34 continue | 34 continue |
| 35 if not can_read_file: | 35 if not can_read_file: |
| 36 logging.critical("File %s does not have read permissions!", | 36 logging.critical("File %s does not have read permissions!", |
| 37 filename) | 37 filename) |
| 38 continue | 38 continue |
| 39 | 39 |
| 40 logging.info("Hash values for file %s", os.path.basename(filename)) | 40 logging.info("Hash values for file %s", os.path.basename(filename)) |
| 41 logging.info("md5 (1m): %s", utils.hash_file(filename, 1024*1024, | 41 logging.info("md5 (1m): %s", utils.hash_file(filename, 1024*1024, |
| 42 method="md5")) | 42 method="md5")) |
| 43 logging.info("sha1 (1m): %s", utils.hash_file(filename, 1024*1024, | 43 logging.info("sha1 (1m): %s", utils.hash_file(filename, 1024*1024, |
| 44 method="sha1")) | 44 method="sha1")) |
| 45 logging.info("md5 (full): %s", utils.hash_file(filename, method="md5")) | 45 logging.info("md5 (full): %s", utils.hash_file(filename, method="md5")) |
| 46 logging.info("sha1 (full): %s", utils.hash_file(filename, | 46 logging.info("sha1 (full): %s", utils.hash_file(filename, |
| 47 method="sha1")) | 47 method="sha1")) |
| 48 logging.info("") | 48 logging.info("") |
| OLD | NEW |