aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Quigley <bryan.quigley@canonical.com>2016-10-25 11:29:27 -0400
committerBryan Quigley <bryan.quigley@canonical.com>2019-12-07 16:15:03 -0800
commita0e0a522a84ea6fe3e693e5ba8da7f086b9e1cc5 (patch)
tree2f370acb330ebefc4a761f74b51994274c48b9b1
parent19b75c52ea7c4345bec8891f0cd88f09833c7ba6 (diff)
downloadsos-a0e0a522a84ea6fe3e693e5ba8da7f086b9e1cc5.tar.gz
[sosreport] Change text format, add username, filesize and chksum
This changes the format of the end text making the output information more consistent. We now mention the username that owns the archive the filesize in a human readable format, and the checksum. New format: Your sosreport has been generated and saved in: /tmp/sosreport-desktop-20180313115538.tar.xz Size 63.55KB Owner root sha256 d0ae51b7e57a6f6f8b336cc0d5a9b5bcc3fd1f6796cfc0df2e74bb98590b82dc We remove the tmpdir from the pretext. We also enable saying if configuration changes should be expected or not, given options selected. Closes: #631 Resolves: #887 Signed-off-by: Bryan Quigley <bryan.quigley@canonical.com>
-rw-r--r--sos/policies/__init__.py39
-rw-r--r--sos/sosreport.py8
2 files changed, 35 insertions, 12 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index f4aa3180..c4969bbd 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -9,6 +9,7 @@ import fnmatch
import tempfile
import random
import string
+from pwd import getpwuid
from sos.utilities import (ImporterHelper,
import_module,
@@ -24,6 +25,16 @@ from six.moves import input
PRESETS_PATH = "/var/lib/sos/presets"
+def GetHumanReadable(size, precision=2):
+ # Credit to Pavan Gupta https://stackoverflow.com/questions/5194057/
+ suffixes = ['B', 'KB', 'MB', 'GB', 'TB']
+ suffixIndex = 0
+ while size > 1024 and suffixIndex < 4:
+ suffixIndex += 1
+ size = size/1024.0
+ return "%.*f%s" % (precision, size, suffixes[suffixIndex])
+
+
def import_policy(name):
policy_fqname = "sos.policies.%s" % name
try:
@@ -412,8 +423,7 @@ class Policy(object):
msg = _("""\
This command will collect system configuration and diagnostic information \
-from this %(distro)s system. An archive containing the collected information \
-will be generated in %(tmpdir)s.
+from this %(distro)s system.
For more information on %(vendor)s visit:
@@ -423,7 +433,8 @@ The generated archive may contain data considered sensitive and its content \
should be reviewed by the originating organization before being passed to \
any third party.
-No changes will be made to system configuration.
+%(changes_text)s
+
%(vendor_text)s
""")
@@ -645,7 +656,7 @@ No changes will be made to system configuration.
to use"""
return "md5"
- def display_results(self, archive, directory, checksum):
+ def display_results(self, archive, directory, checksum, archivestat=None):
# Display results is called from the tail of SoSReport.final_work()
#
# Logging is already shutdown and all terminal output must use the
@@ -659,14 +670,16 @@ No changes will be made to system configuration.
if archive:
self._print(_("Your sosreport has been generated and saved "
- "in:\n %s") % archive, always=True)
+ "in:\n %s\n") % archive, always=True)
+ self._print(_(" Size\t%s") %
+ GetHumanReadable(archivestat.st_size))
+ self._print(_(" Owner\t%s") %
+ getpwuid(archivestat.st_uid).pw_name)
else:
- self._print(_("sosreport build tree is located at : %s" %
- directory), always=True)
-
- self._print()
+ self._print(_("Your sosreport build tree has been generated "
+ "in:\n %s\n") % directory, always=True)
if checksum:
- self._print(_("The checksum is: ") + checksum)
+ self._print(" " + self.get_preferred_hash_name() + "\t" + checksum)
self._print()
self._print(_("Please send this file to your support "
"representative."))
@@ -686,11 +699,15 @@ No changes will be made to system configuration.
the user in non-batch mode. If your policy sets self.distro that
text will be substituted accordingly. You can also override this
method to do something more complicated."""
+ if self.commons['cmdlineopts'].allow_system_changes:
+ changes_text = "Changes CAN be made to system configuration."
+ else:
+ changes_text = "No changes will be made to system configuration."
width = 72
_msg = self.msg % {'distro': self.distro, 'vendor': self.vendor,
'vendor_url': self.vendor_url,
'vendor_text': self.vendor_text,
- 'tmpdir': self.commons['tmpdir']}
+ 'changes_text': changes_text}
_fmt = ""
for line in _msg.splitlines():
_fmt = _fmt + fill(line, width, replace_whitespace=False) + '\n'
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 2f365fad..dd02771b 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -1265,6 +1265,8 @@ class SoSReport(object):
# containing directory.
final_name = os.path.join(self.sys_tmp,
os.path.basename(archive))
+ # Get stat on the archive
+ archivestat = os.stat(archive)
archive_hash = archive + "." + hash_name
final_hash = final_name + "." + hash_name
@@ -1294,7 +1296,11 @@ class SoSReport(object):
except (OSError, IOError):
print(_("Error moving checksum file: %s" % archive_hash))
- self.policy.display_results(archive, directory, checksum)
+ if not self.opts.build:
+ self.policy.display_results(archive, directory, checksum,
+ archivestat)
+ else:
+ self.policy.display_results(archive, directory, checksum)
# clean up
logging.shutdown()