diff options
-rw-r--r-- | sos/policies/__init__.py | 22 | ||||
-rw-r--r-- | sos/sosreport.py | 26 |
2 files changed, 26 insertions, 22 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 5b0b7063..20e0e3b6 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -13,7 +13,6 @@ from sos.utilities import (ImporterHelper, shell_out) from sos.plugins import IndependentPlugin, ExperimentalPlugin from sos import _sos as _ -import hashlib from textwrap import fill from six import print_ from six.moves import input @@ -285,22 +284,12 @@ No changes will be made to system configuration. considered to be a superuser""" return (os.getuid() == 0) - def _create_checksum(self, hash_name, archive=None): - if not archive: - return False - - archive_fp = open(archive, 'rb') - digest = hashlib.new(hash_name) - digest.update(archive_fp.read()) - archive_fp.close() - return digest.hexdigest() - def get_preferred_hash_name(self): """Returns the string name of the hashlib-supported checksum algorithm to use""" return "md5" - def display_results(self, archive, directory): + def display_results(self, archive, directory, checksum): # Display results is called from the tail of SoSReport.final_work() # # Logging is already shutdown and all terminal output must use the @@ -312,19 +301,10 @@ No changes will be made to system configuration. self._print() - hash_name = self.get_preferred_hash_name() if archive: - # store checksum into file - fp = open(archive + "." + hash_name, "w") - checksum = self._create_checksum(hash_name, archive) - if checksum: - fp.write(checksum + "\n") - fp.close() - self._print(_("Your sosreport has been generated and saved " "in:\n %s") % archive) else: - checksum = None self._print(_("sosreport build tree is located at : %s" % directory)) diff --git a/sos/sosreport.py b/sos/sosreport.py index f3e0f346..f7a5f11a 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -33,6 +33,7 @@ from stat import ST_UID, ST_GID, ST_MODE, ST_CTIME, ST_ATIME, ST_MTIME, S_IMODE from time import strftime, localtime from collections import deque import tempfile +import hashlib from sos import _sos as _ from sos import __version__ @@ -1432,6 +1433,18 @@ class SoSReport(object): raise self._log_plugin_exception(plugname, "postproc") + def _create_checksum(self, archive=None): + if not archive: + return False + + hash_name = self.policy.get_preferred_hash_name() + + archive_fp = open(archive, 'rb') + digest = hashlib.new(hash_name) + digest.update(archive_fp.read()) + archive_fp.close() + return digest.hexdigest() + def final_work(self): # this must come before archive creation to ensure that log # files are closed and cleaned up at exit. @@ -1466,7 +1479,18 @@ class SoSReport(object): else: directory = self.archive.get_archive_path() - self.policy.display_results(archive, directory) + hash_name = self.policy.get_preferred_hash_name() + checksum = None + + if hash_name and not self.opts.build: + # store checksum into file + fp = open(archive + "." + hash_name, "w") + checksum = self._create_checksum(archive) + if checksum: + fp.write(checksum + "\n") + fp.close() + + self.policy.display_results(archive, directory, checksum) self.tempfile_util.clean() return True |