aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-11-07 17:14:16 +0000
committerBryn M. Reeves <bmr@redhat.com>2013-11-07 17:14:16 +0000
commit7e96ec748f0b0ab906fa246e4fcac0becb2ed1b4 (patch)
tree9e7f8dcd1b19ef3cab157a19c4911808ca7d9947
parent2b2fa228391a0188a375a9e3c1e8f03f69c7eafd (diff)
downloadsos-7e96ec748f0b0ab906fa246e4fcac0becb2ed1b4.tar.gz
Restore --build command line option
Releases of sos prior to 3.0 included the '--build' option to disable creation of a compressed archive and to leave the temporary build tree in place. This was removed with the reorganisation of the archive classes to support in-line archiving. Since all supported policies are now using an archive that derives from FileCacheArchive (commit 0178d5f) the option can be re-introduced. Archive classes that do not accumulate files in a temporary directory will return the path to the in-progress archive file. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/archive.py22
-rw-r--r--sos/policies/__init__.py8
-rw-r--r--sos/sosreport.py47
3 files changed, 51 insertions, 26 deletions
diff --git a/sos/archive.py b/sos/archive.py
index 080f2593..095777ba 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -59,6 +59,15 @@ class Archive(object):
to be included in the generated archive."""
raise NotImplementedError
+ def get_archive_path(self):
+ """Return a string representing the path to the temporary
+ archive. For archive classes that implement in-line handling
+ this will be the archive file itself. Archives that use a
+ directory based cache prior to packaging should return the
+ path to the temporary directory where the report content is
+ located"""
+ pass
+
def cleanup(self):
"""Clean up any temporary resources used by an Archive class."""
pass
@@ -76,7 +85,7 @@ class FileCacheArchive(Archive):
_tmp_dir = ""
_archive_root = ""
- _archive_path = ""
+ _archive_name = ""
def __init__(self, name, tmpdir):
self._name = name
@@ -141,6 +150,9 @@ class FileCacheArchive(Archive):
def get_tmp_dir(self):
return self._archive_root
+ def get_archive_path(self):
+ return self._archive_root
+
def makedirs(self, path, mode=0700):
self._makedirs(self.dest_path(path))
self.log.debug("created directory at %s in FileCacheArchive %s"
@@ -157,8 +169,8 @@ class FileCacheArchive(Archive):
self.log.debug("finalizing archive %s" % self._archive_root)
self._build_archive()
self.cleanup()
- self.log.debug("built archive at %s (size=%d)" % (self._archive_path,
- os.stat(self._archive_path).st_size))
+ self.log.debug("built archive at %s (size=%d)" % (self._archive_name,
+ os.stat(self._archive_name).st_size))
return self._compress()
@@ -170,7 +182,7 @@ class TarFileArchive(FileCacheArchive):
def __init__(self, name, tmpdir):
super(TarFileArchive, self).__init__(name, tmpdir)
self._suffix = "tar"
- self._archive_path = os.path.join(tmpdir, self.name())
+ self._archive_name = os.path.join(tmpdir, self.name())
def set_tarinfo_from_stat(self, tar_info, fstat, mode=None):
tar_info.mtime = fstat.st_mtime
@@ -214,7 +226,7 @@ class TarFileArchive(FileCacheArchive):
old_pwd = os.getcwd()
old_umask = os.umask(0077)
os.chdir(self._tmp_dir)
- tar = tarfile.open(self._archive_path, mode="w")
+ tar = tarfile.open(self._archive_name, mode="w")
tar.add(os.path.split(self._name)[1],
filter=self.copy_permissions_filter)
tar.close()
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 5c2531df..ba2f14b4 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -206,12 +206,6 @@ No changes will be made to system configuration.
"""
pass
- def package_results(self, package_name):
- """
- This function is called prior to packaging.
- """
- pass
-
def post_work(self):
"""
This function is called after the sosreport has been generated.
@@ -477,5 +471,3 @@ class LinuxPolicy(Policy):
return
- def package_results(self, archive_filename):
- self._print(_("Creating compressed archive..."))
diff --git a/sos/sosreport.py b/sos/sosreport.py
index b1f2e1d0..cab7d0c0 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -327,6 +327,19 @@ class SoSOptions(object):
self._batch = value
@property
+ def build(self):
+ if self._options != None:
+ return self._options.build
+ return self._build
+
+ @build.setter
+ def build(self):
+ self._check_options_initialized()
+ if not isinstance(value, bool):
+ raise TypeError("SoSOptions.build expects a boolean")
+ self._build = value
+
+ @property
def verbosity(self):
if self._options != None:
return self._options.verbosity
@@ -476,6 +489,9 @@ class SoSOptions(object):
parser.add_option("--batch", action="store_true",
dest="batch", default=False,
help="batch mode - do not prompt interactively")
+ parser.add_option("--build", action="store_true", \
+ dest="build", default=False, \
+ help="keep sos tree available and dont package results")
parser.add_option("-v", "--verbose", action="count",
dest="verbosity",
help="increase verbosity")
@@ -1097,24 +1113,29 @@ class SoSReport(object):
def final_work(self):
# package up the results for the support organization
- self.policy.package_results(self.archive.name())
+ if not self.opts.build:
+ self.ui_log.info(_("Creating compressed archive..."))
- self._finish_logging()
+ # compression could fail for a number of reasons
+ try:
+ final_filename = self.archive.finalize(self.opts.compression_type)
+ except:
+ if self.opts.debug:
+ raise
+ else:
+ return False
- # compression could fail for a number of reasons
- try:
- final_filename = self.archive.finalize(self.opts.compression_type)
- except:
- if self.opts.debug:
- raise
+ # automated submission will go here
+ if not self.opts.upload:
+ self.policy.display_results(final_filename)
else:
- return False
+ self.policy.upload_results(final_filename)
- # automated submission will go here
- if not self.opts.upload:
- self.policy.display_results(final_filename)
else:
- self.policy.upload_results(final_filename)
+ self.ui_log.info(_("\n sosreport build tree is located at : %s\n"
+ % self.archive.get_archive_path()))
+
+ self._finish_logging()
self.tempfile_util.clean()