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